Back to / lib / io / fileutils

Package fileutils

v0.0.0 (6660285)
Latest Go to latest
Published: today | License: Apache-2.0 | Module:


Package Files

func AtomicSymlink(oldname string, newname string) error

func AtomicWrite

func AtomicWrite(p string, r io.Reader, opts ...AtomicWriteOpt) error

AtomicWrite reads the content of r into the file at path p atomically. This is done by first writing into a temporary file, and then renaming that into place.

func AtomicWriter

func AtomicWriter(p string, w func(io.Writer) error, opts ...AtomicWriteOpt) error

AtomicWriter writes a file atomically into p. It provides a writer to given callback. If the callback returns an error, the file is not written.

func CopyDir

func CopyDir(srcDir string, dstDir string, options ...Opt) error

CopyDir copies all files that are not symlinks in a source directory to another.

func CopyFile

func CopyFile(srcPath, dstPath string, options ...Opt) error

CopyFile copies the file at the src into the dst path

func Executable

func Executable(uname string, path string) (bool, error)

Executable returns whether or not a path is executable by a given user. In addition to verifying that the executable bit is set for the base of the path, it traverses the path in reverse and verifies that the user has the exec bit through the entire path.

func IsSymlink(path string) (bool, error)

IsSymlink returns true if the given path is a symbolic link and false otherwise. An error is returned on

func LogClose

func LogClose(c io.Closer, log logrus.FieldLogger, msg string)

LogCLose closes the given io.Closer, logging any error.

func MakeReadWriteExecutable

func MakeReadWriteExecutable(uname, path string) error

MakeReadWriteExecutable takes a user and path and attempts to modify file permissions to make it RWE in the least intrusive way. There are many ways to do this but what I've deemed the least intrusive generally is: If the base path isn't owned by the user or share group membership with the user we'll change the files ownership to the user instead of making it RWE for everybody. Next, we'll update the owner or group bits with RWE. Finally, we'll ensure that the user has exec bits through the entire path either via ownership, group membership, or everybody. NOTE: it's best to assume that the UID running this function is root.

func PathExists

func PathExists(path string) (bool, error)

PathExists returns true if the path exists and false if it doesn't exist. An error is returned if an unexpected error occurs. Callers who want behavior similar to Ruby's File.exist? or Rusts' path::exists functions can ignore the error.

func ReadWritable

func ReadWritable(uname string, path string) (bool, error)

ReadWritable returns whether or not a path is RW by a given user

func ReadWriteExecutable

func ReadWriteExecutable(uname string, path string) (bool, error)

ReadWriteExecutable returns whether or not a path is RWE by a given user

func Readable

func Readable(uname string, path string) (bool, error)

Readable returns whether or not a path is readable by a given user

func Writable

func Writable(uname string, path string) (bool, error)

Writable returns whether or not a path is writable by a given user

type AtomicWriteOpt

type AtomicWriteOpt func(*atomicWriteOpts)

AtomicWriteOpt allows setting options for writing a file

func WithAtomicWriteChmod

func WithAtomicWriteChmod(mode os.FileMode) AtomicWriteOpt

WithAtomicWriteChmod specifies the file mode the file must have. This is not affected by the umask

func WithAtomicWriteChown

func WithAtomicWriteChown(uid int, gid int) AtomicWriteOpt

func WithAtomicWriteFileMode

func WithAtomicWriteFileMode(mode os.FileMode) AtomicWriteOpt

WithAtomicWriteFileMode specifies the file mode the file must have This is affected by the umask

func WithAtomicWriteNoSync

func WithAtomicWriteNoSync(noSync bool) AtomicWriteOpt

WithAtomicWriterNoSync specifies if sync should be skipped. Skipping sync is not safe.

type Opt

type Opt func(*copyOpts)

Opt is a functional option

func Depth

func Depth(depth int) Opt

Depth determines how far to recursively traverse if the function supports it

func NoRecursive

func NoRecursive() Opt

NoRecursive will not recursively traverse directories if the function supports it

func Overwrite

func Overwrite() Opt

Overwrite will overwrite the file and/or directory and files

type PathStat

type PathStat struct {
	// contains filtered or unexported fields

PathStat contains a path and the corresponding syscall.Stat_t for the path.

type PathStats

type PathStats []PathStat

PathStats is a slice representing the stat results of path in reverse order starting with the base at index 0 all the way to / on the slice edge.

type WriteCloserFailer

type WriteCloserFailer interface {
	Fail(error) error

func NewAtomicWriter

func NewAtomicWriter(p string, opts ...AtomicWriteOpt) (WriteCloserFailer, error)
Documentation was rendered with GOOS=linux and GOARCH=amd64.

Jump to identifier

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to identifier