fsx

package
v2.0.2 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2026 License: MIT Imports: 23 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

This section is empty.

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 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 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 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 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 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 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 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

Jump to

Keyboard shortcuts

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