Documentation ¶
Index ¶
- Variables
- func AbsPath(base *string) error
- func Copy(outfile, infile string, mode os.FileMode) (err error)
- func CreateDirectories(baseDirectory string, files []string) error
- func GetCommonAncestor(paths []string, rootSentinels []string) (string, error)
- func GetFilenameNoExt(path string) string
- func GetFreeSpace(path string) (uint64, error)
- func HardlinkRecursively(src, dst string) error
- func IsDir(path string) (bool, error)
- func IsEmptyDir(dir string) (bool, error)
- func IsNotExist(err error) bool
- func MakeDirs(path string) error
- func MakePathUserWritable(path string, fi os.FileInfo) error
- func MakeReadOnly(path string, filter func(string) bool) error
- func MakeTreeFilesReadOnly(ctx context.Context, root string) error
- func MakeTreeReadOnly(ctx context.Context, root string) error
- func MakeTreeWritable(ctx context.Context, root string) error
- func ReadableCopy(outfile, infile string) error
- func RemoveAll(path string) error
- func RenamingRemoveAll(path, renameToDir string) (renamedToPath string, err error)
- func ResolveSymlink(path string) (string, os.FileInfo, error)
- func SetReadOnly(path string, readOnly bool) error
- func Touch(path string, when time.Time, mode os.FileMode) error
- type TempDir
Constants ¶
This section is empty.
Variables ¶
var ErrRootSentinel = errors.New("hit root sentinel")
ErrRootSentinel is wrapped and then returned from GetCommonAncestor when it encounters one of the provided rootSentinels.
Functions ¶
func AbsPath ¶
AbsPath is a convenience wrapper around filepath.Abs that accepts a string pointer, base, and updates it on successful resolution.
func CreateDirectories ¶
CreateDirectories creates the directory structure needed by the given list of files.
func GetCommonAncestor ¶
GetCommonAncestor returns the smallest path which is the ancestor of all provided paths (which must actually exist on the filesystem).
All paths here are converted to absolute paths before calculating the ancestor, and the returned path will also be an absolute path. Note that this doesn't do anything special with symlinks; the caller can resolve them if necessary.
This function works correctly on case-insensitive filesystems, or on filesystems with a mix of case-sensitive and case-insensitive paths, but you can get some wild filesystems out there, so this will probably break on exotic setups. Note that the case of the path you get back will be derived from the shortest input path (after making them absolute); this function makes no attempt to "canonicalize" the case of any paths (but may do so accidentally, depending on the operating system). This function does not attempt to resolve symlinks.
If a given path points to a file, the file's containing directory will be considered instead (i.e. GetCommonAncestor("a/b.ext") will return the absolute path of "a").
`rootSentinels` is a list of sub paths to look for to stop walking up the directory hierarchy. A typical value would be something like []string{".git"}. If one of these is found, this function returns "" with a wrapped ErrRootSentinel. Use errors.Is to identify this.
Returns an error if any of the provided paths does not exist. If successful, will return a path ending with PathSeparator.
If no paths are prodvided, returns ("", nil)
func GetFilenameNoExt ¶
GetFilenameNoExt returns the base file name without the extension.
func GetFreeSpace ¶
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.
func HardlinkRecursively ¶
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.
func IsDir ¶
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.
func IsEmptyDir ¶
IsEmptyDir returns whether |dir| is empty or not. This returns error if |dir| is not directory, or find some error during checking.
func IsNotExist ¶
IsNotExist calls os.IsNotExist on the unwrapped err.
func MakeDirs ¶
MakeDirs is a convenience wrapper around os.MkdirAll that applies a 0755 mask to all created directories.
func MakePathUserWritable ¶
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.
func MakeReadOnly ¶
MakeReadOnly recursively iterates through all of the files and directories starting at path and marks them read-only.
func MakeTreeFilesReadOnly ¶
MakeTreeFilesReadOnly makes all the files in the directories read only but not the directories themselves. This means files can be created or deleted.
func MakeTreeReadOnly ¶
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.
func MakeTreeWritable ¶
MakeTreeWritable makes all the files in the directories writeable. Also makes the directories writeable, only if it makes sense on the platform.
func ReadableCopy ¶
ReadableCopy makes a copy of the file that is readable by everyone.
func RemoveAll ¶
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
func RenamingRemoveAll ¶
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.
func ResolveSymlink ¶
ResolveSymlink recursively resolves simlink and returns absolute path that is not symlink with stat.
func SetReadOnly ¶
SetReadOnly sets or resets the write bit on a file or directory. Zaps out access to 'group' and 'others'.
Types ¶
type TempDir ¶
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.
func (*TempDir) With ¶
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.