Documentation ¶
Index ¶
- func AtomicSymlink(oldname string, newname string) error
- func AtomicWrite(p string, r io.Reader, opts ...AtomicWriteOpt) error
- func AtomicWriter(p string, w func(io.Writer) error, opts ...AtomicWriteOpt) error
- func Executable(uname string, path string) (bool, error)
- func IsSymlink(path string) (bool, error)
- func MakeReadWriteExecutable(uname, path string) error
- func PathExists(path string) (bool, error)
- func ReadWritable(uname string, path string) (bool, error)
- func ReadWriteExecutable(uname string, path string) (bool, error)
- func Readable(uname string, path string) (bool, error)
- func Writable(uname string, path string) (bool, error)
- type AtomicWriteOpt
- type PathStat
- type PathStats
- type WriteCloserFailer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AtomicSymlink ¶
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 ¶
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 ¶
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 ¶
IsSymlink returns true if the given path is a symbolic link and false otherwise. An error is returned on
func MakeReadWriteExecutable ¶
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 ¶
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 ¶
ReadWritable returns whether or not a path is RW by a given user
func ReadWriteExecutable ¶
ReadWriteExecutable returns whether or not a path is RWE 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)