Hard-coded 60s URL and 10s host floors with jitter and per-host backoff, shared between dibs processes through a locked state file. The scheduler shuffles due URLs each round and runs one worker per host; 'dibs --headless' watches and logs JSON.
34 lines
846 B
Go
34 lines
846 B
Go
// Package fsutil has file helpers shared by the packages that persist data.
|
|
package fsutil
|
|
|
|
import (
|
|
"io/fs"
|
|
"os"
|
|
"path/filepath"
|
|
)
|
|
|
|
// WriteFileAtomic replaces path with data, so a crash never leaves a
|
|
// half-written file behind. Missing parent directories are created for the
|
|
// user only.
|
|
func WriteFileAtomic(path string, data []byte, perm fs.FileMode) error {
|
|
if err := os.MkdirAll(filepath.Dir(path), 0o700); err != nil { return err }
|
|
|
|
tmp, err := os.CreateTemp(filepath.Dir(path), "."+filepath.Base(path)+".*")
|
|
if err != nil { return err }
|
|
defer func() { _ = os.Remove(tmp.Name()) }()
|
|
|
|
if err := tmp.Chmod(perm); err != nil {
|
|
_ = tmp.Close()
|
|
return err
|
|
}
|
|
|
|
if _, err := tmp.Write(data); err != nil {
|
|
_ = tmp.Close()
|
|
return err
|
|
}
|
|
|
|
if err := tmp.Close(); err != nil { return err }
|
|
|
|
return os.Rename(tmp.Name(), path)
|
|
}
|