pyfs

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2026 License: MIT Imports: 26 Imported by: 0 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

Index

Constants

This section is empty.

Variables

View Source
var ErrRmTreeSymlink = errors.New("Cannot call rmtree on a symbolic link")

Error rmtree raises for a symlinked root or a symlinked subdirectory that reports as a directory

View Source
var Fsync = func(f *os.File) error { return f.Sync() }

File flush every atomic writer runs before the replace, the os.fsync tests fail

View Source
var FsyncDirectory = fsyncDirectory

Directory flush every durable write calls, the name a case replaces the way pytest patches utils.fsync_directory

Functions

func Access

func Access(path string, mode uint32) bool

Whether the real user may open path with every R_OK, W_OK and X_OK bit of mode, as os.access answers

func ArchiveRootDirs

func ArchiveRootDirs(archive string) (map[string]bool, error)

Top level directory names of an archive, counting a root only through a nested member or a directory member

func AtomicReplace

func AtomicReplace(tmp, target string) (string, error)

Moves tmp onto target keeping a symlink target in place, returning the path actually written

func AtomicWrite

func AtomicWrite(ctx context.Context, path string, write func(*os.File) error, o WriteOptions) error

Temp file beside the target, fsync and atomic replace with owner and mode reapplied, the temp removed on failure

func AtomicWriteBytes

func AtomicWriteBytes(ctx context.Context, path string, content []byte, prefix string, mode *os.FileMode, fsyncDir bool) error

Writes bytes through a fsynced temp sibling and an atomic rename, mode nil keeping an existing file mode

func AtomicWriteText

func AtomicWriteText(ctx context.Context, path, content, prefix string) error

Writes text through a temp file beside the published target, fsync, and an atomic rename

func AtomicWriteTextMode

func AtomicWriteTextMode(ctx context.Context, path, content, prefix string, mode os.FileMode) error

Writes like AtomicWriteText with the permission bits forced

func AtomicWriteTextWith

func AtomicWriteTextWith(ctx context.Context, path, content string, o TextWrite) error

Writes utf-8 text through the shared atomic writer under the given keyword arguments

func CloseTempDir

func CloseTempDir(name string, errp *error)

Cleans up a temporary directory at the end of its with block, a cleanup error replacing the block result

func Copy2

func Copy2(src, dst string) error

shutil.copy2 into dst or into dst when it is a directory, content, mode, both times and xattrs

func CopyRegularFiles

func CopyRegularFiles(src, dst string) (int, error)

Copies the regular files under src into dst skipping symlinks, returning the count

func CopyTree

func CopyTree(src, dst string, symlinks, dirsExistOK bool, ignore IgnoreFunc) error

Copies a directory tree the way shutil.copytree does with copy2, failures gathered into one error

func CopyTreeAbortable

func CopyTreeAbortable(src, dst string, symlinks, dirsExistOK bool, ignore IgnoreErrFunc) error

Tree copy whose ignore callback raising stops the copy at once and returns that error unchanged

func DiskUsage

func DiskUsage(path string) (total, used, free uint64, err error)

Total, used and free bytes of the volume holding path the way shutil.disk_usage reports them on POSIX

func ExtractTarDataReader

func ExtractTarDataReader(f io.Reader, destination string) error

Extracts a tar stream into destination like TarFile.extractall with filter data

func Filemode

func Filemode(mode uint32) string

Ten character mode string of a raw st_mode like stat.filemode from the C _stat module

func HolderFileLock

func HolderFileLock(lockPath string, holder *LockHolder, timeout time.Duration, timeoutMessage string) (func(), error)

Takes the cross process advisory lock at lockPath, reentrant per goroutine, failing with the message at the deadline

func IsContendedReplaceError

func IsContendedReplaceError(err error) bool

Contended rename retries only exist on Windows

func IsCrossDeviceError

func IsCrossDeviceError(err error) bool

Cross device and busy target renames fall back to a copy

func LockFile

func LockFile(f *os.File) error

Blocks until f holds an exclusive whole file flock, retrying interrupted waits as fcntl.flock does

func LockHolderHint

func LockHolderHint(lockPath string) string

Live holder hint from the pid a holder stamps into the lock file, empty for none, a dead pid or this process

func LstatIdentity

func LstatIdentity(path string) (dev, ino uint64, err error)

Device and inode numbers os.lstat reports for a path, a final link not followed

func MakeTargz

func MakeTargz(base, rootDir, baseDir string) (string, error)

Writes base.tar.gz of rootDir/baseDir in GNU format through a sibling temp file renamed on completion

func Makedirs

func Makedirs(name string, mode os.FileMode, existOK bool) error

os.makedirs creating missing parents first, an existing directory accepted when existOK

func MkstempBeside

func MkstempBeside(target, prefix, suffix string) (*os.File, error)

Temp file in the directory a later AtomicReplace publishes into, beside the link when that one is unwritable

func ModeForWrite

func ModeForWrite(path string, createMode uint32, createSet, preserve bool) (uint32, bool)

Existing permission bits of path when preserving, else the create mode for a file that does not exist

func Move

func Move(src, dst string) (string, error)

Moves a file or tree like shutil.move with copy2, the result empty for the same file rename

func NormalizeArchiveParts

func NormalizeArchiveParts(member string) ([]string, error)

Safe relative parts of an archive member name, refusing absolute, drive, empty and parent references

func OSErrorText

func OSErrorText(err error) string

Python str of an OS error, errno number and description followed by the quoted path

func PlatformNewlines

func PlatformNewlines(s string) string

Text mode writes keep LF on POSIX hosts

func PosixModeBits

func PosixModeBits(m os.FileMode) uint32

Octal permission bits of a FileMode with the setuid, setgid and sticky flags folded into their positions

func PreserveFileMode

func PreserveFileMode(path string) (uint32, bool)

All twelve permission bits of the file path names, false when it is missing or cannot be read

func ReadTextChars

func ReadTextChars(path string, n int, sig bool) (string, error)

open(path, encoding utf-8 or utf-8-sig).read(n) with TextIOWrapper chunking, universal newlines and strict errors

func RemoveTempDir

func RemoveTempDir(name string) error

Removes a temporary directory like tempfile.TemporaryDirectory cleanup, resetting permissions of denied entries

func RestoreFileMode

func RestoreFileMode(path string, mode uint32, ok bool)

Applies permission bits to path when a mode was captured, ignoring a refusal

func RestoreFileOwner

func RestoreFileOwner(path string, owner *FileOwner)

Gives a replaced file back to its previous owner, ignoring a refusal, a nil owner leaving it alone

func RmTree

func RmTree(path string, onexc func(op RmTreeOp, path string, err error) error) error

Removes a tree like shutil.rmtree, routing every failure through onexc or returning the first one when onexc is nil

func SafeExtractTargz

func SafeExtractTargz(archive, destination string) error

Extracts only directories and regular files, failing on links, devices and escaping names

func TarMemberNames

func TarMemberNames(r io.Reader) ([]string, error)

Member names of a gzip or plain tar archive in stream order

func TryLockFile

func TryLockFile(f *os.File) (bool, error)

One non blocking exclusive flock attempt, false without error when another handle holds it

func UnlinkFilesOlderThan

func UnlinkFilesOlderThan(dir, pattern string, maxAgeSeconds float64, now *float64) int

Deletes regular files matching the pattern whose mtime is more than the age before now and returns the count

func UnlockFile

func UnlockFile(f *os.File) error

Releases the flock f holds

func Walk

func Walk(top string, followlinks bool, visit func(dirpath string, dirnames, filenames []string) []string)

os.walk top down in scandir order, visit returning the subdirectory names to descend and unreadable directories skipped

Types

type ArchiveError

type ArchiveError struct{ Msg string }

Error for an unsafe or unsupported archive member, the ValueError of

func (*ArchiveError) Error

func (e *ArchiveError) Error() string

type CopyTreeError

type CopyTreeError struct{ Failures [][3]string }

Failures gathered by a tree copy as source, destination and reason triples

func (*CopyTreeError) Error

func (e *CopyTreeError) Error() string

type EncodeError

type EncodeError struct{ Msg string }

UnicodeEncodeError Python raises writing text with lone surrogates as utf-8

func (*EncodeError) Error

func (e *EncodeError) Error() string

type FileOwner

type FileOwner struct{ UID, GID int }

Owning uid and gid of a file on a POSIX host

func PreserveFileOwner

func PreserveFileOwner(path string) *FileOwner

Owner of the file path names, nil when it cannot be read

type IgnoreErrFunc

type IgnoreErrFunc func(dir string, names []string) (map[string]bool, error)

Names of a directory listing a tree copy skips, or an error that stops the whole copy

type IgnoreFunc

type IgnoreFunc func(dir string, names []string) map[string]bool

Names of a directory listing a tree copy skips

type LockHolder

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

Per goroutine reentrancy depth of one advisory lock, the holder its users share

func (*LockHolder) Depth

func (h *LockHolder) Depth() int

Depth the calling goroutine holds the lock at, zero when it does not hold it

type LockTimeoutError

type LockTimeoutError struct{ Message string }

Python TimeoutError a holder lock waiter raises once its deadline passes

func (*LockTimeoutError) Error

func (e *LockTimeoutError) Error() string

type MoveError

type MoveError struct{ Msg string }

shutil.Error raised for a move whose destination exists or lies inside the source

func (*MoveError) Error

func (e *MoveError) Error() string

type MovePermissionError

type MovePermissionError struct{ Msg string }

PermissionError raised for a tree that is immutable or that macOS will not let the caller empty

func (*MovePermissionError) Error

func (e *MovePermissionError) Error() string

func (*MovePermissionError) PyTypeName

func (e *MovePermissionError) PyTypeName() string

Python class name of the error

func (*MovePermissionError) Unwrap

func (e *MovePermissionError) Unwrap() error

Lets errors.Is match the permission class

type RmTreeOp

type RmTreeOp func(path string) error

Operation an rmtree error came from, re-runnable by the error handler like the func argument of onexc

type TarAdder

type TarAdder struct {
	W *tar.Writer
	// contains filtered or unexported fields
}

TarAdder writes paths into a tar stream like tarfile.TarFile.add, tracking hard links across calls

func (*TarAdder) Add

func (a *TarAdder) Add(path, arcname string, recursive bool, filter func(h *tar.Header) *tar.Header) error

Adds path as arcname, recursing into directories in sorted order, a nil filter result skips the member and its children

type TarFilterError

type TarFilterError struct {
	Class string
	Msg   string
}

Refusal of a member by the tarfile data filter, Class naming the tarfile.FilterError subclass

func (*TarFilterError) Error

func (e *TarFilterError) Error() string

type TextWrite

type TextWrite struct {
	Prefix       string
	PreserveMode bool
	CreateMode   *os.FileMode
	Mode         *os.FileMode
	FsyncDir     bool
}

Keyword arguments of an atomic text write, Mode forcing the bits and CreateMode applying to a new file only

type UnicodeDecodeError

type UnicodeDecodeError struct {
	Path   string
	Byte   byte
	Start  int
	End    int
	Reason string
}

UnicodeDecodeError a strict utf-8 text read raises for bytes that do not decode

func (*UnicodeDecodeError) Error

func (e *UnicodeDecodeError) Error() string

type WriteOptions

type WriteOptions struct {
	Prefix        string
	Mode          uint32
	ModeSet       bool
	PreserveOwner bool
	FsyncDir      bool
}

Keyword arguments of the shared atomic writer, Mode applying only when ModeSet

Jump to

Keyboard shortcuts

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