fs

package
v1.3.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 24, 2024 License: BSD-3-Clause Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Abs

func Abs(path string) (string, error)

Abs resolves a path to an absolute path. The supplied path can not be an empty string.

func CopyFile

func CopyFile(from, to string, mode os.FileMode) (err error)

CopyFile copies file to the provided location making sure the resulting file has permission bits set to the mode prior to umask. To honor umask correctly the resulting file must not exist.

func CopyFileAtomic

func CopyFileAtomic(from, to string, mode os.FileMode) (err error)

CopyFileAtomic copies file to a temporary file in the same destination directory and the renames to the final name. This is useful to avoid races where concurrent copies could happen to the same destination. It makes sure the resulting file has permission bits set to the mode prior to umask. To honor umask correctly the resulting file must not exist.

func EnsureFileWithPermission

func EnsureFileWithPermission(fn string, mode os.FileMode) error

EnsureFileWithPermission takes a file path, and 1. Creates it with the specified permission, or 2. ensures a file is the specified permission.

func EvalRelative

func EvalRelative(path string, root string) string

EvalRelative evaluates symlinks in path relative to root path, it returns a path as if it was evaluated from chroot. This function always returns an absolute path and is intended to be used to resolve mount points destinations, it helps the runtime to not bind mount directories/files outside of the container image provided by the root argument.

func FindSize

func FindSize(size int64) string

FindSize takes a size in bytes and converts it to a human-readable string representation expressing kB, MB, GB or TB (whatever is smaller, but still larger than one).

func FirstExistingParent

func FirstExistingParent(path string) (string, error)

FirstExistingParent walks up the supplied path and returns the first parent that exists. If the supplied path exists, it will just return that path. Assumes cwd and the root directory always exists

func ForceRemoveAll

func ForceRemoveAll(path string) error

ForceRemoveAll removes a directory like os.RemoveAll, except that it will chmod any directory who's permissions are preventing the removal of contents

func IsDir

func IsDir(name string) bool

IsDir check if name component is a directory.

func IsExec

func IsExec(name string) bool

IsExec check if name component has executable bit permission set.

func IsFile

func IsFile(name string) bool

IsFile check if name component is regular file.

func IsLink(name string) bool

IsLink check if name component is a symlink.

func IsOwner

func IsOwner(name string, uid uint32) bool

IsOwner check if name component is owned by user identified with uid.

func IsReadable added in v1.1.0

func IsReadable(path string) bool

IsReadable returns true if the file that is passed in is readable by the user (note: uid is checked, not euid).

func IsSuid

func IsSuid(name string) bool

IsSuid check if name component has setuid bit permission set.

func IsWritable

func IsWritable(path string) bool

IsWritable returns true if the file that is passed in is writable by the user (note: uid is checked, not euid).

func MakeTmpDir

func MakeTmpDir(basedir, pattern string, mode os.FileMode) (string, error)

MakeTmpDir creates a temporary directory with provided mode in os.TempDir if basedir is "". This function assumes that basedir exists, so it's the caller's responsibility to create it before calling it.

func MakeTmpFile

func MakeTmpFile(basedir, pattern string, mode os.FileMode) (*os.File, error)

MakeTmpFile creates a temporary file with provided mode in os.TempDir if basedir is "". This function assumes that basedir exists, so it's the caller's responsibility to create it before calling it.

func Mkdir

func Mkdir(path string, mode os.FileMode) error

Mkdir creates a directory if it doesn't exist with mode after umask reset.

func MkdirAll

func MkdirAll(path string, mode os.FileMode) error

MkdirAll creates a directory and parents if it doesn't exist with mode after umask reset.

func PathExists

func PathExists(path string) (bool, error)

PathExists simply checks if a path exists.

func PermWalk

func PermWalk(root string, walkFn filepath.WalkFunc) error

PermWalk is similar to filepath.Walk - but:

  1. The skipDir checks are removed (we never want to skip anything here)
  2. Our walk will call walkFn on a directory *before* attempting to look inside that directory.

func PermWalkRaiseError

func PermWalkRaiseError(root string, walkFn filepath.WalkFunc) error

PermWalkRaiseError is similar to filepath.Walk - but:

  1. The skipDir checks are removed (we never want to skip anything here)
  2. Our walk will call walkFn on a directory *before* attempting to look inside that directory.
  3. We back out of the recursion at the *first* error... we don't attempt to go through as much as we can.

func RootDir

func RootDir(path string) string

RootDir returns the root directory of path (rootdir of /my/path is /my). Returns "." if path is empty.

func Touch

func Touch(path string) error

Touch behaves like touch command.

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL