Documentation ¶
Overview ¶
Package filesystem provides various filesystem utility methods either not provided by the Go standard library or requiring a more optimized implementation. It also provides filesystem watching facilities.
Index ¶
- Constants
- Variables
- func DecomposesUnicode(path string) (bool, error)
- func DeviceID(info os.FileInfo) (uint64, error)
- func DirectoryContents(path string) ([]os.FileInfo, error)
- func GetOwnership(info os.FileInfo) (int, int, error)
- func IsAtomicOperationFileName(name string) bool
- func IsExecutabilityProbeFileName(name string) bool
- func IsUnicodeProbeFileName(name string) bool
- func Mutagen(create bool, subpath ...string) (string, error)
- func Normalize(path string) (string, error)
- func PreservesExecutability(path string) (bool, error)
- func RenameFileAtomic(oldPath, newPath string) error
- func SetOwnership(path string, uid, gid int) error
- func Walk(root string, visitor filepath.WalkFunc) error
- func Watch(context context.Context, root string, events chan struct{}, mode WatchMode, ...)
- func WriteFileAtomic(path string, data []byte, permissions os.FileMode) error
- type Locker
- type WatchMode
Constants ¶
const (
// DefaultPollingInterval is the default watch polling interval, in seconds.
DefaultPollingInterval = 10
)
const ( // MutagenDirectoryName is the name of the Mutagen control directory inside // the user's home directory. MutagenDirectoryName = ".mutagen" )
Variables ¶
var HomeDirectory string
HomeDirectory is the cached path to the current user's home directory.
var MutagenConfigurationPath string
MutagenConfigurationPath is the path to the Mutagen configuration file.
var WatchMode_name = map[int32]string{
0: "WatchDefault",
1: "WatchPortable",
2: "WatchForcePoll",
}
var WatchMode_value = map[string]int32{
"WatchDefault": 0,
"WatchPortable": 1,
"WatchForcePoll": 2,
}
Functions ¶
func DecomposesUnicode ¶
DecomposesUnicode determines whether or not the filesystem on which the directory at the specified path resides decomposes Unicode filenames.
func DirectoryContents ¶
DirectoryContents returns the contents of the directory at the specified path. The ordering of the contents is non-deterministic.
func GetOwnership ¶
GetOwnership returns the owning user and group IDs from file metadata.
func IsAtomicOperationFileName ¶ added in v0.5.2
IsAtomicOperationFileName determines whether or not a file name (not a file path) is the name of an intermediate temporary file used in an atomic operation.
func IsExecutabilityProbeFileName ¶ added in v0.5.2
IsExecutabilityProbeFileName determines whether or not a file name (not a file path) is the name of an executability preservation probe file.
func IsUnicodeProbeFileName ¶ added in v0.5.2
IsUnicodeProbeFileName determines whether or not a file name (not a file path) is the name of an Unicode decomposition probe file.
func Mutagen ¶
Mutagen computes (and optionally creates) subdirectories inside the Mutagen directory (~/.mutagen).
func Normalize ¶
Normalize normalizes a path, expanding home directory tildes, converting it to an absolute path, and cleaning the result.
func PreservesExecutability ¶
PreservesExecutability determines whether or not the filesystem on which the directory at the specified path resides preserves POSIX executability bits.
func RenameFileAtomic ¶
RenameFileAtomic performs an atomic file rename. In the simplest case, it's a simple alias for os.Rename. However, if moving a file across filesystems, it will fall back to a copy/rename combination that should still approximate atomicity (at least in terms of swapping the destination file contents). It does NOT support renaming directories, only files. It takes inspiration from: https://github.com/golang/dep/blob/4ad9f4ec24012607dc247ca24528e3224d61519a/fs.go#L80
func SetOwnership ¶
SetOwnership sets the owning user and group IDs for the specified path.
func Walk ¶ added in v0.5.0
Walk provides a faster implementation of path/filepath.Walk with slightly different semantics. In particular, it only walks directory contents after metadata for the directory has been collected and does not sort entries by name. It gains speed by avoiding sorting and, more importantly, using os.File.Readdir for vastly more efficient traversal on Windows.
func Watch ¶
func Watch(context context.Context, root string, events chan struct{}, mode WatchMode, pollInterval uint32)
TODO: Document that this function closes the events channel when the watch is cancelled. TODO: Document that this function will always succeed in one way or another (it doesn't have any total failure modes) and won't exit until the associated context is cancelled. TODO: Document that the events channel must be buffered.
Types ¶
type Locker ¶
type Locker struct {
// contains filtered or unexported fields
}
Locker provides file locking facilities.
func NewLocker ¶
NewLocker attempts to create a lock with the file at the specified path, creating the file if necessary. The lock is returned in an unlocked state.
type WatchMode ¶
type WatchMode int32
WatchMode specifies the mode for filesystem watching.
const ( // WatchMode_WatchDefault represents an unspecified watch mode. It should be // converted to one of the following values based on the desired default // behavior. WatchMode_WatchDefault WatchMode = 0 // WatchMode_WatchPortable specifies that native recursive watching should // be used to monitor paths on systems that support it if those paths fall // under the home directory. In these cases, a watch on the entire home // directory is established and filtered for events pertaining to the // specified path. On all other systems and for all other paths, poll-based // watching is used. WatchMode_WatchPortable WatchMode = 1 // WatchMode_WatchForcePoll specifies that only poll-based watching should // be used. WatchMode_WatchForcePoll WatchMode = 2 )
func (WatchMode) Description ¶
Description returns a human-readable description of a watch mode.
func (WatchMode) EnumDescriptor ¶
func (WatchMode) Supported ¶
Supported indicates whether or not a particular watch mode is a valid, non-default value.
func (*WatchMode) UnmarshalText ¶
UnmarshalText implements the text unmarshalling interface used when loading from TOML files.
Source Files ¶
- atomic.go
- atomic_posix.go
- device_posix.go
- directory.go
- doc.go
- executability_posix.go
- locker.go
- locker_posix.go
- normalize.go
- ownership_posix.go
- paths.go
- unicode_posix.go
- visibility_posix.go
- walk.go
- watch.go
- watch.pb.go
- watch_native.go
- watch_native_non_recursive.go
- watch_native_non_recursive_inotify.go
- watch_native_posix.go
- watch_poll.go
Directories ¶
Path | Synopsis |
---|---|
Package winfsnotify allows the user to receive file system event notifications on Windows.
|
Package winfsnotify allows the user to receive file system event notifications on Windows. |