Documentation
¶
Overview ¶
Package fsops provides filesystem operations with OS-appropriate implementations. On POSIX the operations are thin wrappers over the standard library; on Windows they add cmd/PowerShell fallbacks for the cases where the Win32 layer rejects an operation the Go runtime issued (e.g. RemoveAll on a directory containing a junction).
Index ¶
- func MkdirAll(path string, perm os.FileMode) error
- func ReadDirAllowMissing(path string) (entries []os.DirEntry, found bool, err error)
- func ReadFileAllowMissing(path string) (data []byte, found bool, err error)
- func Remove(path string) error
- func RemoveAll(path string) error
- func Rename(oldpath, newpath string) error
- func StatAllowMissing(path string) (info os.FileInfo, found bool, err error)
- func WriteFile(path string, data []byte, perm os.FileMode) error
- func WriteFileAtomic(path string, data []byte) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ReadDirAllowMissing ¶ added in v0.5.0
ReadDirAllowMissing reads the directory at path, applying the same absent/real-error/present three-way split as ReadFileAllowMissing.
func ReadFileAllowMissing ¶ added in v0.5.0
ReadFileAllowMissing reads the file at path, distinguishing a legitimately absent file from a real read error. A missing file (os.IsNotExist) returns (nil, false, nil); any other error (permission denied, I/O failure, ...) is surfaced as (nil, false, err) instead of being silently conflated with absence; a successful read returns (data, true, nil).
This is the shared primitive for the "swallow-and-degrade" remediation: callers that used to do `if err != nil { return <empty> }` after os.ReadFile can switch to this helper and get a correct three-way split (absent / real error / present) without hand-rolling the os.IsNotExist check at every call site.
func Rename ¶ added in v0.5.0
Rename atomically renames (moves) oldpath to newpath on the same volume.
Deliberately SINGLE-SHOT: no retry loop and no PowerShell fallback, unlike the other Windows variants in this package. Callers (notably the internal/agentslock release/reclaim lifecycle) build atomicity arguments on "one rename syscall, one observable transition" — the lock name either moved or it did not. A wrapper that silently retried would widen those callers' race windows (e.g. a retried rename against a lock name that a rival has since re-acquired would steal the rival's live lock). Callers for whom a bounded retry is the correct semantic loop over this primitive themselves.
func StatAllowMissing ¶ added in v0.5.0
StatAllowMissing stats path, applying the same absent/real-error/present three-way split as ReadFileAllowMissing.
func WriteFileAtomic ¶
WriteFileAtomic writes data to path atomically: a temp file in the same directory is written and closed, then renamed into place, so a concurrent reader never observes a partial file. The parent directory must already exist. The resulting file carries os.CreateTemp's owner-only mode (0600), matching the prior sidecar writers; callers needing a different mode chmod the final path themselves.
This is the single atomic-write primitive shared by the YAML sidecar writers (scoring, review/labels) and the lockfile writer; callers marshal their own bytes and hand them here rather than re-implementing temp+rename.
Types ¶
This section is empty.