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
- Variables
- func AwaitLock(ctx context.Context, path string) (release func(), err error)
- func Below(path, root string) bool
- func CloseAll(files ...*os.File)
- func Copy(src, dst string) error
- func CopyTree(files fs.FS, dest string, skip func(name string) bool) error
- func Digest(path string) (string, error)
- func Disk(path string) (free, total int64, ok bool)
- func Elevated() bool
- func Executable(path string) bool
- func Exists(path string) bool
- func Expand(path, home string) string
- func ExpandFrom(path string, getenv func(name string) string) string
- func ExpandHome(path string) string
- func Give(string) error
- func Held(err error) bool
- func Inside(path, root string) bool
- func IsDir(path string) bool
- func IsFile(path string) bool
- func Lexists(path string) bool
- func Linked(f *os.File) bool
- func Lock(ctx context.Context, path string, timeout time.Duration) (release func(), err error)
- func LockPath(path string) string
- func Locked(path string) (bool, error)
- func MakeUserDir(path string, mode os.FileMode) error
- func Mentioned(words string, endings ...string) []string
- func NewLocked(path string) (*os.File, bool, error)
- func OpenLocked(path string, wait bool) (*os.File, bool, error)
- func ReadJSON[T any](path string) (T, error)
- func Remedy(path string) string
- func Replace(path string, data []byte, perm os.FileMode) error
- func Resolved(path string) string
- func Retry(operation func() error) error
- func Settled(path string) (string, bool)
- func Sweep(dir string, age time.Duration)
- func Tilde(path string) string
- func TreeDigest(files fs.FS, skip func(name string) bool) (string, error)
- func TryLock(path string) (release func(), ok bool, err error)
- func Update(path string, perm os.FileMode, change func(old []byte) ([]byte, error)) error
- func UpdateJSON[T any](path string, perm os.FileMode, change func(value *T) error) error
- func UpdateYAML[T any](path string, perm os.FileMode, change func(value *T) error) error
- func Version(path string) string
- func Within(path, root string) bool
- func Write(path string, data []byte, perm os.FileMode) error
- func Written(path string) string
- type Grant
- type Mention
- type Repair
- type Seen
- type Skip
- type TimeoutError
- type Watch
Constants ¶
const NameWatchHearsWrites = true
NameWatchHearsWrites is true here, because a name watch hears writes in place through the folder.
Variables ¶
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 ¶
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 CloseAll ¶
Closes every file, what a close says left unsaid, as the ends of pipes a started child no longer needs
func CopyTree ¶
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 Disk ¶
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 ¶
Whether the path is a regular file this process may run, through links
func Expand ¶
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 ¶
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 ¶
Path with a leading ~ standing for the user's home folder expanded, left as it is when there is no home
func Give ¶
Gives the entry back to the user of this process, which only an elevated run of Windows takes away: nothing here
func Inside ¶
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 Linked ¶
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 ¶
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 Locked ¶
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 ¶
Makes the folder and those missing above it with the mode, which belong to the user of this process here
func Mentioned ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 Resolved ¶
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 ¶
Runs a rename or removal again for about three seconds while another program, usually an antivirus scan on Windows, holds the file
func Settled ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
Changes the YAML file at path under its lock as UpdateJSON changes a JSON file
func Version ¶
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
Types ¶
type Grant ¶
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
type Repair ¶
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 ¶
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 ¶
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
type TimeoutError ¶
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 ¶
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 ¶
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) Set ¶
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 ¶
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 ¶
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.