fsops

package
v0.5.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 22, 2026 License: Apache-2.0 Imports: 3 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func MkdirAll

func MkdirAll(path string, perm os.FileMode) error

MkdirAll creates a directory path and all missing parents.

func ReadDirAllowMissing added in v0.5.0

func ReadDirAllowMissing(path string) (entries []os.DirEntry, found bool, err error)

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

func ReadFileAllowMissing(path string) (data []byte, found bool, err error)

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 Remove

func Remove(path string) error

Remove removes a single file or empty directory.

func RemoveAll

func RemoveAll(path string) error

RemoveAll removes path and any children it contains.

func Rename added in v0.5.0

func Rename(oldpath, newpath string) error

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

func StatAllowMissing(path string) (info os.FileInfo, found bool, err error)

StatAllowMissing stats path, applying the same absent/real-error/present three-way split as ReadFileAllowMissing.

func WriteFile

func WriteFile(path string, data []byte, perm os.FileMode) error

WriteFile writes data to path, creating it if necessary.

func WriteFileAtomic

func WriteFileAtomic(path string, data []byte) error

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL