Documentation ¶
Index ¶
- Variables
- func CopyFile(from string, to string) error
- func CopyFileTree(from string, to string, whitelist []string) error
- func FindFileInParents(filename string, startingFromDir string) (string, error)
- func HasParentDir(child string) (bool, error)
- func IsDirPresent(p string) (bool, error)
- func NormalFileExists(path string) (bool, error)
- func RemoveEmptySubDirs(dir string) error
- func TryCloseAll(things ...interface{}) error
- func TryRemoveAllLocked(dirPath string) (bool, error)
- func WalkRelAtDepth(root string, depth int, walk filepath.WalkFunc) error
- type LockedDir
- type LockedFile
Constants ¶
This section is empty.
Variables ¶
var ErrNotExist = os.ErrNotExist
Functions ¶
func CopyFile ¶
CopyFile will copy the entire contents of the file at path `from`, to the file at path `to`. If `to` doesn't exist, it is created. If it does exist, it is overwritten.
func CopyFileTree ¶
CopyFileTree copies the directory tree under `from` to the directory `to`. This function only copies files, creating directories as necessary to recreate the structure. As a result, empty directories will not be created.
The `whitelist` is a list of glob patterns on filenames (not complete paths), which are used to filter which files are copied. Only files with names matching the list will be copied. filepath.Match is used to perform the matching.
func FindFileInParents ¶
FindFileInParents proceeds up the directory hierarchy, starting from `startingFromDir`, and attempts to find a file named `filename` in any of those directories. It will return the path of the one closest (i.e. fewer steps) to `startingFromDir`. If not such file is found, returns `ErrNotExist`
func HasParentDir ¶
HasParentDir returns true if the given path has a parent directory distinct from itself. Equivalently, it returns true if the provided path is *not* the root of the filesystem (e.g. '/' on unix or 'C:\' on Windows). Returns an error if a filesystem operation fails.
func IsDirPresent ¶
IsDirPresent will return true if it found a directory at the given path. It will return false if there is nothing at the given path. It returns an error if a normal file is found at the given path.
func NormalFileExists ¶
NormalFileExists will return true if a normal file (i.e. not a directory) exists at the given path. It will also return false if parent directories don't exist. Any other error encountered will be returned.
func RemoveEmptySubDirs ¶
RemoveEmptySubDirs will delete the immediate child directories of path, but only of they are empty. Directories that are not empty will be skipped silently.
func TryCloseAll ¶
func TryCloseAll(things ...interface{}) error
TryCloseAll takes io.Closers, or slices of things that implement io.Closer, and trys to close them all Even if one Close() fails, it will try to close all of them If there was an error, returns a multierror.Error containing all the errors that occurred.
func TryRemoveAllLocked ¶
TryRemoveAllLocked will attempt to lock the given directory and delete it, including its entire contents. If the directory could not be locked, returns false but no error If the deletion fails for another reason, returns false with an error If the deletion succeeds, returns true and no error.
func WalkRelAtDepth ¶
WalkRelAtDepth will walk the directory tree starting at root. For each entry whose depth is exactly `depth` into the tree, it calls the provided function. The `path` paremeter it passes to the callback is relative to `root`. Otherwise, this function behaves the same as filepath.Walk
Types ¶
type LockedDir ¶
type LockedDir struct {
// contains filtered or unexported fields
}
LockedDir is a discretionary lock for a directory. There is no concept of lock inheritance; locking a directory does not automatically lock its parent or child directories or files. The lock is implemented by creating a locked "*.lock" file adjacent to the specified directory. This file has no contents. The locked directory itself is not guaranteed to exist - this allows locking the directory before it is created, and allows calling functions that expect to create the directory themselves. Shared locking is not implemented; all directory locks are exclusive.
func LockDirOrCreate ¶
LockDirOrCreate locks the dir at `path`. If the directory does not exist, the provided `constructor` is called to initialise the contents of the directory.
type LockedFile ¶
LockedFile is an open file with an advisory lock. It is important that you close and unlock the file before the program exits - both can be achieved by calling Close()
func CreateLockedFile ¶
func CreateLockedFile(path string, truncate bool) (file *LockedFile, err error)
CreateLockedFile creates a new file, opened for reading and writing and locked exclusively. If `truncate` is true, it will overwrite an existing file at `path`. Otherwise, an error will be returned if the file already exists.
func OpenRLockedFile ¶
func OpenRLockedFile(path string) (file *LockedFile, err error)
OpenRLockedFile will open a file read-only with shared locking.
func OpenRLockedFileOrCreate ¶
func OpenRLockedFileOrCreate(path string, constructor func(file *LockedFile) error) (file *LockedFile, err error)
OpenRLockedFileOrCreate will try to open the file at `path` for reading, in the same manner as OpenRLockedFile. If it does not exist, the file will opened for writing in the same manner as CreateLockedFile, and the provided `constructor` is called to allow the file to be filled. In either case, the open LockedFile is returned.
func (*LockedFile) Close ¶
func (lf *LockedFile) Close() error
Close implements an io.Closer for LockedFile