Documentation
¶
Overview ¶
Package fsutil holds small filesystem helpers shared across commands.
Index ¶
- Variables
- func ExistingPerm(path string, def fs.FileMode) fs.FileMode
- func OpenJSONL(path string, replay func([]byte)) (*os.File, error)
- func RestrictToOwner(string) error
- func SyncDir(dir string) error
- func VerifyPrivate(path string) error
- func WriteAtomic(path string, data []byte, perm fs.FileMode) (err error)
- type DirLock
Constants ¶
This section is empty.
Variables ¶
var ErrLocked = errors.New("directory is in use by another process")
ErrLocked means another process holds the directory's lock.
Functions ¶
func ExistingPerm ¶
ExistingPerm returns path's permission bits, or def when it cannot be stat'd. Use with WriteAtomic to keep an existing file's mode.
func OpenJSONL ¶
OpenJSONL replays the append-only log at path line by line into replay, then returns it open for appending. A torn trailing line (crash mid-write) is handed to replay like any other (callers skip lines that don't decode) and then terminated with '\n', so the next record starts on its own line instead of being glued onto — and lost with — the torn one.
func RestrictToOwner ¶
RestrictToOwner is a no-op here: the 0600 mode the caller creates files with already is owner-only. (Windows replaces the DACL.)
func VerifyPrivate ¶
VerifyPrivate reports whether group and other have no access to path.
func WriteAtomic ¶
WriteAtomic writes data to path so a reader sees either the old or the new content, never a partial file: temp file in the same directory, fsync, chmod perm, rename, fsync the directory. The directory must exist.
Types ¶
type DirLock ¶ added in v0.5.0
type DirLock struct {
// contains filtered or unexported fields
}
DirLock is an exclusive advisory lock on a directory, held through a file in it for as long as the process lives or until Close. The operating system drops it when the process dies, so a crash never leaves a stale lock.