luci-go: github.com/luci/luci-go/common/system/filesystem Index | Files

package filesystem

import "github.com/luci/luci-go/common/system/filesystem"

Index

Package Files

filepath.go filesystem.go filesystem_unix.go tempdir.go

func AbsPath Uses

func AbsPath(base *string) error

AbsPath is a convenience wrapper around filepath.Abs that accepts a string pointer, base, and updates it on successful resolution.

func CreateDirectories Uses

func CreateDirectories(baseDirectory string, files []string) error

CreateDirectories creates the directory structure needed by the given list of files.

func GetFreeSpace Uses

func GetFreeSpace(path string) (uint64, error)

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 Uses

func HardlinkRecursively(src, dst string) error

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 Uses

func IsDir(path string) (bool, error)

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 Uses

func IsEmptyDir(dir string) (bool, error)

IsEmptyDir returns whether |dir| is empty or not. This returns error if |dir| is not directory, or find some error during checking.

func IsNotExist Uses

func IsNotExist(err error) bool

IsNotExist calls os.IsNotExist on the unwrapped err.

func MakeDirs Uses

func MakeDirs(path string) error

MakeDirs is a convenience wrapper around os.MkdirAll that applies a 0755 mask to all created directories.

func MakePathUserWritable Uses

func MakePathUserWritable(path string, fi os.FileInfo) error

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 Uses

func MakeReadOnly(path string, filter func(string) bool) error

MakeReadOnly recursively iterates through all of the files and directories starting at path and marks them read-only.

func MakeTreeFilesReadOnly Uses

func MakeTreeFilesReadOnly(ctx context.Context, root string) error

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 Uses

func MakeTreeReadOnly(ctx context.Context, root string) error

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 Uses

func MakeTreeWritable(ctx context.Context, root string) error

MakeTreeWritable makes all the files in the directories writeable. Also makes the directories writeable, only if it makes sense on the platform.

func ReadableCopy Uses

func ReadableCopy(outfile, infile string) error

ReadableCopy makes a copy of the file that is readable by everyone.

func RemoveAll Uses

func RemoveAll(path string) error

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 Uses

func RenamingRemoveAll(path, renameToDir string) (renamedToPath string, err error)

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(path string) (string, os.FileInfo, error)

ResolveSymlink recursively resolves simlink and returns absolute path that is not symlink with stat.

func SetReadOnly Uses

func SetReadOnly(path string, readOnly bool) error

SetReadOnly sets or resets the write bit on a file or directory. Zaps out access to 'group' and 'others'.

func Touch Uses

func Touch(path string, when time.Time, mode os.FileMode) error

Touch creates a new, empty file at the specified path.

If when is zero-value, time.Now will be used.

type TempDir Uses

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 Uses

func (td *TempDir) With(fn func(string) error) error

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 13 packages (graph) and is imported by 6 packages. Updated 2019-12-11. Refresh now. Tools for package owners.