Documentation
¶
Index ¶
- Constants
- Variables
- func Access(path string, mode uint32) bool
- func Atime(fi fs.FileInfo) time.Time
- func CleanupTempDir(dir string, errp *error)
- func CopyFile(src, dst string) error
- func CopyLinkMetadata(src, dst string) error
- func CopyMetadata(src, dst string) error
- func CopyRegularFiles(src, dst string) (int, error)
- func CopyTree(src, dst string, o CopyTreeOptions) error
- func CreateTempBeside(target, prefix, suffix string) (*os.File, error)
- func DiskUsage(path string) (total, used, free uint64, err error)
- func Identity(path string) (dev, ino uint64, err error)
- func IsRenameContended(err error) bool
- func IsRenameCrossDevice(err error) bool
- func LockFile(f *os.File) error
- func LookPathIn(cmd, path string) (string, error)
- func Move(src, dst string) (string, error)
- func PermBits(path string) (uint32, bool)
- func ReadText(path string, limit int) (string, error)
- func RemoveOlderThan(dir, pattern string, cutoff time.Time) int
- func RemoveTempDir(dir string) error
- func RemoveTree(path string, onError func(op RemoveOp, path string, err error) error) error
- func Replace(tmp, target string) (string, error)
- func RestoreOwner(path string, owner *Owner)
- func SetPermBits(path string, mode uint32) error
- func TryLockFile(f *os.File) (bool, error)
- func UnlockFile(f *os.File) error
- func WriteFile(ctx context.Context, path string, data []byte, o WriteOptions) error
- type CopyFailure
- type CopyTreeError
- type CopyTreeOptions
- type FileLock
- type IgnoreFunc
- type LockTimeoutError
- type Owner
- type PendingFile
- type RemoveOp
- type TextDecodeError
- type WriteOptions
Constants ¶
const ( // Execute permission, or search permission for a directory AccessExec = 1 // Write permission AccessWrite = 2 // Read permission AccessRead = 4 )
Bits of the mode Access tests, combined with |
Variables ¶
var ErrSameFile = errors.New("source and destination are the same file")
Error a copy gives when source and destination name the same file
var ErrSymlinkRoot = errors.New("refusing to remove a tree through a symbolic link")
Error RemoveTree reports for a root that is a symbolic link or a Windows junction, which it never follows
var SyncDir = syncDir
Flushes a directory entry to disk, skipped on Windows and on any error; durable writes run it after the rename, and tests may replace it to observe them
var SyncFile = func(f *os.File) error { return f.Sync() }
Flushes a file to disk; every atomic write runs it before the rename, and tests may replace it to simulate a failing disk
Functions ¶
func Access ¶
Whether the real user may use path with every one of the AccessRead, AccessWrite and AccessExec bits of mode
func Atime ¶
Access time of a file from its stat result to the nanosecond, the modification time when the result carries none
func CleanupTempDir ¶
Removes a temporary directory when the function that made it returns, joining a removal failure into *errp; meant for defer
func CopyFile ¶
Copies the content of src to dst, or into dst when that is a directory, then its permission bits with setuid, setgid and sticky, both times and on Linux its extended attributes, symlinks followed; a copy onto itself fails with ErrSameFile, a directory, fifo, socket or device src fails before dst is touched
func CopyLinkMetadata ¶
Copies the times, on Linux the extended attributes and on the BSDs and macOS the mode and file flags of the symlink src onto the symlink dst, following neither
func CopyMetadata ¶
Copies the permission bits with setuid, setgid and sticky, both times and on Linux the extended attributes of src onto dst, symlinks followed
func CopyRegularFiles ¶
Copies the regular files below src into the same places below dst, content only, skipping symlinks and every other kind of entry; gives back how many it copied, zero without error when src is no directory
func CopyTree ¶
func CopyTree(src, dst string, o CopyTreeOptions) error
Copies the directory tree at src to dst, making dst and its parents: each file with its content, permission bits, times and on Linux extended attributes, then each directory's own; a Windows junction is descended into; an entry that fails is skipped and gathered into a *CopyTreeError, while an unreadable src, a dst that exists without DirsExistOK and a Check error stop the copy at once
func CreateTempBeside ¶
Temp file named prefix, random characters and suffix in the directory Replace publishes target into, the directory of the link itself when that one refuses it
func DiskUsage ¶
Total, used and free bytes of the volume holding path, free counting what an unprivileged user may still use
func IsRenameContended ¶
Whether a rename failed because another process holds the target, which only happens on Windows
func IsRenameCrossDevice ¶
Whether a rename failed because the target is on another device or busy, a failure a copy works around
func LockFile ¶
Blocks until f holds an exclusive advisory lock on its whole file, a flock retried through interrupted waits
func LookPathIn ¶
Executable cmd names, searched in each directory of path, a list in the form of PATH, by exec.LookPath's rules except that POSIX judges execute permission for the real user: a cmd holding a separator is checked as given, Windows tries the PATHEXT extensions and skips empty entries where POSIX reads them as the working directory, an empty list finds nothing, and a first hit through a relative directory comes back with an error wrapping exec.ErrDot, which on Windows a later absolute directory holding that same file turns into a plain hit
func Move ¶
Moves the file or tree at src to dst, or into dst when that is a directory, with a rename or, where that fails, a copy keeping links and metadata and then the removal of src; gives back the path moved to, empty when src and dst already name the same directory; an existing destination fails with fs.ErrExist
func PermBits ¶
All twelve permission bits of the file path names, symlinks followed, false when it cannot be read
func ReadText ¶
First limit characters of the UTF-8 text file at path, all of it for math.MaxInt, a leading byte order mark dropped and \r\n and a lone \r read as \n; bytes that are not UTF-8 within what it reads give a *TextDecodeError
func RemoveOlderThan ¶
Removes the regular files directly in dir whose names match the glob pattern and that were last modified before cutoff, symlinks followed to decide; gives back how many went, skipping whatever cannot be read or removed
func RemoveTempDir ¶
Removes a temporary directory tree, giving back owner access to every entry or parent that refuses removal and trying it again; entries already gone are no failure
func RemoveTree ¶
Removes the tree at path depth first without following symbolic links or junctions, refusing a linked root with ErrSymlinkRoot; every failure goes to onError with the operation that failed, whose error stops the removal while nil goes on, and a nil onError stops at the first failure
func Replace ¶
Renames tmp over target, or over the file a symlinked target points at so the link stays, copying across devices and retrying a target another Windows process holds; gives back the path written
func RestoreOwner ¶
Hands path to owner, ignoring a refusal; a nil owner leaves it alone
func SetPermBits ¶
Sets all twelve permission bits of path, setuid, setgid and sticky given in their POSIX positions; on Windows only the owner write bit counts, as the read only attribute
func TryLockFile ¶
One attempt at the exclusive lock without waiting, false and no error when another handle holds it
Types ¶
type CopyFailure ¶
One entry a tree copy could not copy and why
func (*CopyFailure) Error ¶
func (f *CopyFailure) Error() string
The entry and the reason, as in copy /a/x to /b/x: open /a/x: permission denied
type CopyTreeError ¶
type CopyTreeError struct{ Failures []CopyFailure }
Every entry a tree copy went on past, in the order it met them
func (*CopyTreeError) Error ¶
func (e *CopyTreeError) Error() string
Each failure, joined by semicolons
func (*CopyTreeError) Unwrap ¶
func (e *CopyTreeError) Unwrap() []error
Each failure as an error of its own, so errors.Is and errors.As look into every one
type CopyTreeOptions ¶
type CopyTreeOptions struct {
Symlinks bool
DirsExistOK bool
Ignore IgnoreFunc
Check func(dir string, names []string) error
CopyFile func(src, dst string) error
}
Settings of CopyTree: Symlinks recreates symbolic links as links rather than copying what they point at; DirsExistOK merges into directories that already exist; Ignore picks the names to skip in each directory; Check vets each directory listing before anything in it is copied, its error stopping the whole copy and coming back unchanged; CopyFile copies each regular file, a copy keeping content and metadata when nil
type FileLock ¶
type FileLock struct {
// contains filtered or unexported fields
}
Advisory lock on one lock file, shared by every goroutine and process that takes it, which the goroutine holding it may take again; the holder's pid is stamped in the file after one pad byte while held, so other processes can read it past the byte a Windows lock covers
func SharedFileLock ¶
The FileLock of the lock file at path, the same value for every caller in this process naming the same file
type IgnoreFunc ¶
Names in one directory listing that a tree copy skips
func IgnorePatterns ¶
func IgnorePatterns(patterns ...string) IgnoreFunc
IgnoreFunc skipping the names that match any of the glob patterns, case folded on Windows
type LockTimeoutError ¶
Lock wait that gave up once its timeout passed, with the pid another live process stamped into the lock file, zero when unknown
func (*LockTimeoutError) Error ¶
func (e *LockTimeoutError) Error() string
The lock file, the timeout and the likely holder, as in timed out after 15s waiting for lock file /h/.env.lock; process 4242 probably holds it
func (*LockTimeoutError) Unwrap ¶
func (e *LockTimeoutError) Unwrap() error
Lets errors.Is match os.ErrDeadlineExceeded
type PendingFile ¶
Temp file of a streamed atomic write, written through the embedded *os.File and published over its target by Commit; it must not be closed directly
func NewPendingFile ¶
func NewPendingFile(ctx context.Context, path string, o WriteOptions) (*PendingFile, error)
Temp file for an atomic write of path under o, staged where Replace publishes and already carrying the final permission bits; the parent directory is made first, refusing a deleted profile home; publish it with Commit and defer Cleanup
func (*PendingFile) Cleanup ¶
func (p *PendingFile) Cleanup() error
Closes and removes the temp file unless Commit already published it; safe to call any number of times
func (*PendingFile) Commit ¶
func (p *PendingFile) Commit() error
Flushes and closes the temp file and renames it over the target, over the file a symlinked target points at so the link stays, then puts the captured owner and permission bits back and flushes the directory when asked; the temp file is gone whatever the outcome, a panic on the way included
type RemoveOp ¶
Operation a tree removal failed at, which an error handler may run again on the same path once it fixed the cause
type TextDecodeError ¶
Bytes of a text file that are not UTF-8, at the offset from the start of the file where decoding failed
func (*TextDecodeError) Error ¶
func (e *TextDecodeError) Error() string
The file and the offset, as in notes.txt: invalid UTF-8 at byte 17
type WriteOptions ¶
type WriteOptions struct {
Prefix string
Mode *fs.FileMode
CreateMode *fs.FileMode
KeepOwner bool
NativeLineEnds bool
SyncDir bool
}
Settings of an atomic write: Prefix starts the temp file name (".tmp_" when empty); Mode forces the permission bits, setuid, setgid and sticky included, else the replaced file keeps its bits and a new file gets CreateMode or the umask default; KeepOwner hands the file back to the replaced file's owner; NativeLineEnds makes WriteFile write \n as \r\n on Windows; SyncDir flushes the directory after the rename
Source Files
¶
- access.go
- atime_atim.go
- copy.go
- copytree.go
- disk_unix.go
- filelock.go
- filelock_unix.go
- identity_unix.go
- immutable_other.go
- junction_other.go
- linkmeta_unix.go
- linkmode_linux.go
- lock_unix.go
- lookpath.go
- lookpath_unix.go
- meta.go
- meta_unix.go
- move.go
- move_unix.go
- remove.go
- replace.go
- replace_unix.go
- statfs_linux.go
- tempdir.go
- tempdir_perms_other.go
- text.go
- umask_linux.go
- write.go
- xattr_linux.go