import "go.chromium.org/luci/common/system/filesystem"
filepath.go filesystem.go filesystem_unix.go tempdir.go
AbsPath is a convenience wrapper around filepath.Abs that accepts a string pointer, base, and updates it on successful resolution.
Copy makes a copy of the file.
CreateDirectories creates the directory structure needed by the given list of files.
GetFilenameNoExt returns the base file name without the extension.
GetFreeSpace returns the number of free bytes.
On POSIX platforms, this returns the free space as visible by the current user. The returned value is what is usable, and it can be lower than the actual free disk space. For example on linux there's by default a 5% that is reserved to the root user.
HardlinkRecursively efficiently copies a file or directory from src to dst.
`src` may be a file, directory, or a symlink to a file or directory. All symlinks are replaced with their targets, so the resulting directory structure in `dst` will never have any symlinks.
To increase speed, HardlinkRecursively hardlinks individual files into the (newly created) directory structure if possible.
IsDir to see whether |path| is a directory. This is just a thin wrapper around os.Stat(...). If this returns True, |path| is a directory. If this returns False with nil err, |path| is not a directory. If this returns non-nil error, failed to determine |path| is a drectory.
IsEmptyDir returns whether |dir| is empty or not. This returns error if |dir| is not directory, or find some error during checking.
IsNotExist calls os.IsNotExist on the unwrapped err.
MakeDirs is a convenience wrapper around os.MkdirAll that applies a 0755 mask to all created directories.
MakePathUserWritable updates the filesystem metadata on a single file or directory to make it user-writable.
fi is optional. If nil, os.Stat will be called on path. Otherwise, fi will be regarded as the results of calling os.Stat on path. This is provided as an optimization, since some filesystem operations automatically yield a FileInfo.
MakeReadOnly recursively iterates through all of the files and directories starting at path and marks them read-only.
MakeTreeFilesReadOnly makes all the files in the directories read only but not the directories themselves. This means files can be created or deleted.
MakeTreeReadOnly makes all the files in the directories read only. Also makes the directories read only, only if it makes sense on the platform. This means no file can be created or deleted.
MakeTreeWritable makes all the files in the directories writeable. Also makes the directories writeable, only if it makes sense on the platform.
ReadableCopy makes a copy of the file that is readable by everyone.
RemoveAll is a fork of os.RemoveAll that attempts to deal with read only files and directories by modifying permissions as necessary.
If the specified path does not exist, RemoveAll will return nil.
Note that RemoveAll will not modify permissions on parent directory of the provided path, even if it is read only and preventing deletion of the path on POSIX system.
Copied from https://go.googlesource.com/go/+/b86e76681366447798c94abb959bb60875bcc856/src/os/path.go#63
RenamingRemoveAll opportunistically renames a path first, and then removes it.
The advantage over RemoveAll is, if renaming succeeds, lower chance of interference from other writers/readers of the filesystem. If renaming fails, removes the original path via RemoveAll.
If renameToDir is given, a new temp directory will be created in it. Else, a new temp directory is placed within the path's parent dir. After this, a file/dir represented by the path is moved into the temp dir.
In case of any failures during the temp dir creation or the move, default to RemoveAll of path in place.
Returned renamedToPath is the renamed path if renaming succeeded and "" otherwise. Returned error is the one from RemoveAll call.
ResolveSymlink recursively resolves simlink and returns absolute path that is not symlink with stat.
SetReadOnly sets or resets the write bit on a file or directory. Zaps out access to 'group' and 'others'.
Touch creates a new, empty file at the specified path.
If when is zero-value, time.Now will be used.
type TempDir struct { // Dir is the base diectory. If empty, the default will be used (see // ioutil.TempDir) Dir string // Prefix is the prefix to apply to the temporary directory. If empty, a // default will be used (see ioutil.TempDir). Prefix string // OnCleanupErr, if not nil, will be called if TempDir cleanup fails. // // If nil, cleanup errors will be silently discarded. CleanupErrFunc func(tdir string, err error) }
TempDir configures a temporary directory.
With creates a temporary directory and passes it to fn. After fn exits, the directory and all of its contents is deleted.
Any error that happens during setup or execution of the callback is returned. If an error occurs during cleanup, the optional CleanupErrFunc will be called.
Package filesystem imports 14 packages (graph) and is imported by 29 packages. Updated 2021-01-25. Refresh now. Tools for package owners.