osutil

package
v0.3.25 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2024 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const ModeUserRW = 0600 // rw-------
View Source
const ModeUserRWX = 0700 // rwx------
View Source
const ModeUserRWXGroupRX = 0750 // rwxr-x---

Variables

View Source
var ErrInvalidInput = errors.New("invalid input")
View Source
var ErrMissingInput = errors.New("missing input")
View Source
var ErrUnsupportedFileType = errors.New("unsupported file type")

ErrUnsupportedFileType is returned when attempting to copy a file type that's not supported.

Functions

func CopyDir

func CopyDir(srcDir, dstDir string) error

CopyDir recursively copies a directory from 'srcDir' to 'dstDir', preserving soft links. All regular files will be hard copied. Note that file attributes are not preserved, so this should only be used when the folder contents are required in the original structure. This implementation is based on [1].

[1] https://github.com/moby/moby/blob/master/daemon/graphdriver/copy/copy.go

func CopyFile added in v0.1.2

func CopyFile(ctx context.Context, src, out string) error

CopyFile is a utility function for copying an 'io.Reader' to a new file created with the specified 'os.FileMode'.

func CopyReaderWithMode added in v0.1.2

func CopyReaderWithMode(ctx context.Context, src io.Reader, mode fs.FileMode, out string) error

CopyReaderWithMode is a utility function for copying an 'io.Reader' to a new file created with the specified 'os.FileMode'.

func EnsureDir

func EnsureDir(path string, perm fs.FileMode) error

EnsureDir verifies that the specified path exists, is a directory, and has the specified permission bits set.

func HashFile added in v0.2.1

func HashFile(h hash.Hash, path string) error

func HashFileWithName added in v0.3.10

func HashFileWithName(h hash.Hash, root, path string) error

func HashFiles added in v0.1.2

func HashFiles(h hash.Hash, root string) error

HashFiles updates the provided 'hash.Hash' with the file structure contents rooted at 'root'.

func ModeOf added in v0.1.2

func ModeOf(path string) (fs.FileMode, error)

ModeOf returns the file mode of the specified file.

Types

type Path added in v0.1.3

type Path string

Path is a string type that's expected to be a path.

func (Path) CheckIsDir added in v0.1.3

func (p Path) CheckIsDir() error

CheckIsDir verifies that the underlying path is a valid directory.

func (Path) CheckIsDirOrEmpty added in v0.1.3

func (p Path) CheckIsDirOrEmpty() error

CheckIsDirOrEmpty verifies that the underlying path is either empty or a valid directory.

func (Path) CheckIsFile added in v0.1.3

func (p Path) CheckIsFile() error

CheckIsFile verifies that the underlying path is a valid file.

func (Path) CheckIsFileOrEmpty added in v0.1.3

func (p Path) CheckIsFileOrEmpty() error

CheckIsFileOrEmpty verifies that the underlying path is either empty or a valid file.

func (Path) Dir added in v0.3.18

func (p Path) Dir() Path

Dir creates a new 'Path' pointing to the directory of this 'Path'.

func (Path) Join added in v0.3.18

func (p Path) Join(elem ...string) Path

Join creates a new 'Path' with the provided elements appended.

func (*Path) RelTo added in v0.1.3

func (p *Path) RelTo(base Path) error

RelTo converts the underlying path into a cleaned, absolute path. If the path is relative it's first resolved against the provided base path (or current working directory if 'base' is empty).

func (Path) String added in v0.1.3

func (p Path) String() string

Jump to

Keyboard shortcuts

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