fsx

package
v2.0.4 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2026 License: MIT Imports: 27 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

File system steps every part of icebath takes the same way: lock files, whole file writes, copies, and the questions asked of a path

Index

Constants

View Source
const NameWatchHearsWrites = true

NameWatchHearsWrites is true here, because a name watch hears writes in place through the folder.

Variables

View Source
var ErrNotElevated = errors.New("This needs icebath run as administrator, as the administrators hold what is to be given back.")

Why a process that is not elevated could not repair what the administrators of Windows hold

Functions

func AwaitLock

func AwaitLock(ctx context.Context, path string) (release func(), err error)

AwaitLock takes the lock at path, waiting in the system until its holder releases it. On a share a blocking lock waits on a word from the server that can be lost, so there it asks again every shareLook.

func Below

func Below(path, root string) bool

Whether path lies under root, root itself not counted, both cleaned first

func CloseAll

func CloseAll(files ...*os.File)

Closes every file, what a close says left unsaid, as the ends of pipes a started child no longer needs

func Copy

func Copy(src, dst string) error

Copies a file's bytes, permission bits and modification time over dst

func CopyTree

func CopyTree(files fs.FS, dest string, skip func(name string) bool) error

Copies the folders and regular files of a tree into dest, made when missing, an executable file staying executable; the names skip says yes to are left out with what they hold, and a link is refused since it could lead out of dest. skip sees slash paths from the root and may be nil

func Digest

func Digest(path string) (string, error)

Hex sha256 of a file's bytes

func Disk

func Disk(path string) (free, total int64, ok bool)

Bytes this user may still store on the volume of the path and the size of the volume; false when the volume tells nothing

func Elevated

func Elevated() bool

Whether this process runs elevated, which only Windows tells apart from running as its user: never here

func Executable

func Executable(path string) bool

Whether the path is a regular file this process may run, through links

func Exists

func Exists(path string) bool

Whether anything is at the path, through links

func Expand

func Expand(path, home string) string

Path with a leading ~ standing for the home folder given expanded, such as the HOME a profile or a child process is handed; left as it is when home is empty

func ExpandFrom

func ExpandFrom(path string, getenv func(name string) string) string

Path with a leading ~ standing for the home folder the HOME of an environment names expanded, such as a path a variable of a profile holds, the user's own when it names none

func ExpandHome

func ExpandHome(path string) string

Path with a leading ~ standing for the user's home folder expanded, left as it is when there is no home

func Give

func Give(string) error

Gives the entry back to the user of this process, which only an elevated run of Windows takes away: nothing here

func Held

func Held(err error) bool

Whether a failure is another program holding the file for a while

func Inside

func Inside(path, root string) bool

Whether the path is the root or lies under it once the links of both are followed as far as they are there, so neither .. nor a link leads out of it

func IsDir

func IsDir(path string) bool

Whether the path is a folder, through links

func IsFile

func IsFile(path string) bool

Whether the path is a regular file, through links

func Lexists

func Lexists(path string) bool

Whether anything is at the path, a dangling link included

func Linked

func Linked(f *os.File) bool

Whether the file whose lock f holds still has a name, asked of the file and not of its name. The lock is asked for again on the same handle: nothing changes where it is held, and on a network file system the request goes to the server and has the client forget what it kept of the file. Then the file is looked at through the handle: an error, as a server gives for a file removed there, or no link left means the name is gone, whatever the file system kept of the name. A file system that gives no lock twice tells nothing by that, and the look through the handle decides

func Lock

func Lock(ctx context.Context, path string, timeout time.Duration) (release func(), err error)

Takes the advisory lock of the lock file at path, made with its folder when missing, waiting while another process or handle holds it until ctx is done or the timeout passes: a zero timeout tries once, a negative one waits for as long as it takes

func LockPath

func LockPath(path string) string

Path of the lock file that guards the file at path

func Locked

func Locked(path string) (bool, error)

Whether another handle holds the lock of the lock file at path now. A missing file is held by nobody. The file is never made, and a lock taken to test it is let go at once. The file is opened for writing where this process may, as a network file system locks a file for one holder only through a handle that can write, and nothing is written

func MakeUserDir

func MakeUserDir(path string, mode os.FileMode) error

Makes the folder and those missing above it with the mode, which belong to the user of this process here

func Mentioned

func Mentioned(words string, endings ...string) []string

Paths of this computer the words name outside their blocks and spans of code, each once in the order named, cleaned and a leading ~ written out: whole from the root, the home folder or a drive, the name ending in one of the endings in any case, such as png or tar.gz. A path inside a word, an address or another path is none; none for no endings

func NewLocked

func NewLocked(path string) (*os.File, bool, error)

Makes the lock file at path with its folder and takes its advisory lock, held until the file is closed: false, the file removed again, when another handle took the lock in the moment the file was there. A file already at the path is never opened and is an error that is fs.ErrExist: a process that holds the lock of a file through one handle opens no second one, as closing a second handle lets the lock of the first go on some network file systems

func OpenLocked

func OpenLocked(path string, wait bool) (*os.File, bool, error)

Opens the file at path, made with its folder when missing, holding its advisory lock until the file is closed: waiting for the lock when wait is true, else false while another process or handle holds it. For a lock file that keeps data of its own, which TryLock and Lock would overwrite

func ReadJSON

func ReadJSON[T any](path string) (T, error)

Value of the JSON file at path, the zero value when it is missing or empty. Reads take no lock, since every write replaces the file whole

func Remedy

func Remedy(path string) string

What a person runs to have a folder this process may not use back: on Windows the inherited access list put back from an administrator's prompt, elsewhere the folder given to them

func Replace

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

Write that leaves an existing file its permission bits, perm going to a new one

func Resolved

func Resolved(path string) string

Path made whole against the working folder, cleaned, with the links of the part of it that is there followed and the rest of it as it is, so a file about to be made, or gone, is named where it is or was, and a .. after a link leads where the system leads it

func Retry

func Retry(operation func() error) error

Runs a rename or removal again for about three seconds while another program, usually an antivirus scan on Windows, holds the file

func Settled

func Settled(path string) (string, bool)

Version of the file or folder at path as Version gives it, and whether its last change is far enough from now (past the coarsest tick of the times file systems keep) that any change from now on moves it: a change now takes a time near now, which differs from one that far before or after it. A reader that keeps what it read by the version reads it again while it is not settled: what it read may already be older than the file though the version is the same. A time set ahead, as by an archive unpacked from a computer whose clock ran ahead, counts as settled rather than leaving the file unsettled until that time. A missing file is settled

func Sweep

func Sweep(dir string, age time.Duration)

Removes what the folder holds that was last changed longer ago than the age, files and folders alike; nothing for a folder that is not there

func Tilde

func Tilde(path string) string

Path as a person reads it, the user's home folder at its start written ~, the path cleaned and left as it is outside the home folder

func TreeDigest

func TreeDigest(files fs.FS, skip func(name string) bool) (string, error)

Digest of the files of a tree: each file's path from the root and the digest of its bytes, in path order, so no bytes moved from one file to the next read the same; the names skip says yes to left out with what they hold. skip sees slash paths from the root and may be nil

func TryLock

func TryLock(path string) (release func(), ok bool, err error)

Takes the advisory lock of the lock file at path, made with its folder when missing and never opened through a link, without waiting: its release, or false while another process or handle holds it. The file itself is never removed, so a process waiting on it never holds the lock of a file gone from its folder

func Update

func Update(path string, perm os.FileMode, change func(old []byte) ([]byte, error)) error

Changes the file at path under the lock beside it. Change gets the file's bytes, nil when it is missing, and returns the new bytes, which are written whole with perm. A file change returns unchanged is not written. The lock is waited for up to ten seconds, across goroutines and processes alike

func UpdateJSON

func UpdateJSON[T any](path string, perm os.FileMode, change func(value *T) error) error

Changes the JSON file at path under its lock: change edits the value read from it, the zero value when the file is missing or empty, and the value is written back indented. An error from change writes nothing

func UpdateYAML

func UpdateYAML[T any](path string, perm os.FileMode, change func(value *T) error) error

Changes the YAML file at path under its lock as UpdateJSON changes a JSON file

func Version

func Version(path string) string

Version of the file or folder at path as a reader compares it, from one look at it: its modification time and size, and what tells a file put in its place apart (its device and inode and its change time, on Windows its volume and file index); empty when it is missing. Within one tick of the times the file system keeps, two writes in place of the same size, entries of a folder made and removed, or two replacements by rename whose second file takes the number the first freed can read the same: a reader that keeps what it read by the version takes Settled. A file in a folder rewritten in place moves no time of the folder

func Within

func Within(path, root string) bool

Whether path is root or lies under it, both cleaned first

func Write

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

Writes data to path whole or not at all, through a temporary file beside it that is flushed and renamed over it, so a reader sees the old bytes or the new and a crash leaves one of them; the file gets perm, and its folder, made when missing, may be entered by whoever may read the file

func Written

func Written(path string) string

Path as a person writes it, a leading ~ standing for the user's home folder, made whole with its links followed as Resolved follows them

Types

type Grant

type Grant struct {
	Path    string
	Dir     bool
	Bounded bool
}

One grant of the repair: the user of this process given full control of the entry, inherited by what is in it for a folder. Bounded says a link lies somewhere below the folder, so the grant must not be carried down the tree by the system, as icacls carries it

type Mention

type Mention struct {
	// The path cleaned with a leading ~ written out, and as the words have it, which is what the words hold from Start up to End
	Path, Named string
	Start, End  int
}

One place words name a path of this computer, as Mentions finds it

func Mentions

func Mentions(words string, endings ...string) []Mention

Every place the words name a path of this computer the way Mentioned finds them, in order, a path named twice found twice

type Repair

type Repair struct {
	Grants  []Grant
	Skips   []Skip
	Kept    int
	Granted int
	Failed  []Skip
}

What a repair of a tree would change, or changed: the grants, the entries left and why, how many already were the user's, and once made, how many grants took and those that failed

func Plan

func Plan(root, real string, seen []Seen) Repair

Plans the repair of the tree at the root, whose own place the system names real, from what was seen of its entries: each entry the user lacks full control of is granted it, a folder's grant inherited by what comes to be in it; nothing is granted to or through a link, a junction or another reparse point, to anything below one, to a file with other names, or to an entry the system places elsewhere than the tree. A folder holding any of those below it is granted on its own alone. Folders come before what is in them

func RepairTree

func RepairTree(string) (Repair, error)

Repairs the access to a tree an elevated run of Windows took, which no run here takes: nothing to do

type Seen

type Seen struct {
	Path string
	// It is a folder; it is a link, a junction or another reparse point, which the repair never grants through
	Dir, Reparse bool
	// Names a file has, more than one for a file linked under other names that may be outside the tree
	Names int
	// Where the system says the entry is once every link on its way is followed, empty when not told; one placed elsewhere than its own
	// place below the root is no part of the tree
	Final string
	// The user of this process may already do anything with it, and for a folder so may with what comes to be in it
	Granted bool
	// Why it could not be looked at, empty when it could; such an entry is granted, its look made again as the grant opens it
	Problem string
}

What the repair of a folder an elevated process left to the administrators sees of one entry of the folder's tree

func Survey

func Survey(string, int) (string, []Seen, error)

Looks at a tree as the repair of Windows access needs, which only Windows has

type Skip

type Skip struct {
	Path, Why string
}

An entry the repair leaves as it is, and why

type TimeoutError

type TimeoutError struct {
	Path    string
	Timeout time.Duration
	Holder  int
}

Lock wait that gave up once its timeout passed, with the pid another live process stamped in the lock file, zero when unknown

func (*TimeoutError) Error

func (e *TimeoutError) Error() string

func (*TimeoutError) Unwrap

func (e *TimeoutError) Unwrap() error

Lets errors.Is match os.ErrDeadlineExceeded

type Watch

type Watch struct {
	// contains filtered or unexported fields
}

Watch reports changes at a set of paths from the system's own notices. A file changes when it is written, made, renamed or removed, and a folder when an entry in it is. Changed gets one value for any number of changes since it was last read, so a caller that looks at the paths after each value misses nothing.

func NewNameWatch

func NewNameWatch(paths ...string) *Watch

NewNameWatch starts watching the paths for files that are made, replaced, renamed or removed, and never opens a file. A lock file needs this, because closing a second handle on it releases its lock on some network file systems. On systems with kqueue this watch does not report writes in place.

func NewWatch

func NewWatch(paths ...string) *Watch

NewWatch starts watching the paths. It also reports writes in place to a file among them, and on systems with kqueue it opens that file to do so.

func (*Watch) Changed

func (w *Watch) Changed() <-chan struct{}

Changed returns the channel that gets a value after the paths changed.

func (*Watch) Close

func (w *Watch) Close()

Close stops the watch.

func (*Watch) Set

func (w *Watch) Set(paths ...string) bool

Set replaces the watched paths and reports whether they differ from the earlier ones. Changed gets a value when they differ, because a change before Set is only visible to a look after Set.

func (*Watch) Trusted

func (w *Watch) Trusted() bool

Trusted reports whether Works returns true and this system's watch has passed its proof in this process (proveWatch). The first call starts the proof on another goroutine, so Trusted returns false until the proof has passed. A caller must keep its own timer unless the watch is trusted when a missed change would break a promise to another process.

func (*Watch) Works

func (w *Watch) Works() bool

Works reports whether the system reports every change at the paths now. It returns false when the system has no notices, when a watched folder or file sits on a file system that may change without a notice here, when a folder could not be watched, and once the notices can't be read any more. The caller must then look on its own timer, and it must ask again on every turn because the answer changes while it runs. Changed gets a value whenever the answer turns false, so a sleeping caller wakes up and asks. Works tries an unwatched folder again, and it still returns false on that call so that the caller looks once more first.

Jump to

Keyboard shortcuts

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