fileutils

package
v0.0.0-...-0490640 Latest Latest
Warning

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

Go to latest
Published: May 16, 2019 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

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 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 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

Types

type AtomicWriteOpt

type AtomicWriteOpt func(*atomicWriteOpts)

AtomicWriteOpt allows setting options for writing a file

func WithAtomicWriteFileMode

func WithAtomicWriteFileMode(mode os.FileMode) AtomicWriteOpt

WithAtomicWriteFileMode specifies the file mode the file must have

func WithAtomicWriteNoSync

func WithAtomicWriteNoSync(noSync bool) AtomicWriteOpt

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

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 {
	io.WriteCloser
	Fail(error) error
}

func NewAtomicWriter

func NewAtomicWriter(p string, opts ...AtomicWriteOpt) (WriteCloserFailer, error)

Jump to

Keyboard shortcuts

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