Documentation
¶
Overview ¶
Package sys provides os level helper functions for interacting with the system
Index ¶
- func Abs(target string) (result string, err error)
- func AllDirs(root string, opts ...*opt.Opt) (result []string, err error)
- func AllFiles(root string, opts ...*opt.Opt) (result []string, err error)
- func AllPaths(root string, opts ...*opt.Opt) (result []string, err error)
- func Base(src string) (result string)
- func Chmod(path string, mode os.FileMode, opts ...*opt.Opt) (err error)
- func Chown(path string, uid, gid int, opts ...*opt.Opt) (err error)
- func Copy(src, dst string, opts ...*opt.Opt) (err error)
- func CopyFile(src, dst string, opts ...*opt.Opt) (result string, err error)
- func Darwin() (result bool)
- func Dir(src string) (result string)
- func Dirs(target string) (result []string)
- func ExecExists(target string) (ok bool)
- func ExecOut(str string, a ...interface{}) (out string, err error)
- func ExecPath(target string) (path string)
- func Exists(src string) bool
- func Expand(target string) (path string, err error)
- func Files(target string) (result []string)
- func FollowOpt(val bool) *opt.Opt
- func Glob(path string, opts ...*opt.Opt) (sources []string, err error)
- func Home() (result string, err error)
- func InfoOpt(val *FileInfo) *opt.Opt
- func IsDir(src string) bool
- func IsFile(src string) bool
- func IsSymlink(src string) bool
- func IsSymlinkDir(src string) bool
- func IsSymlinkFile(src string) bool
- func Linux() (result bool)
- func MD5(filename string) (result string, err error)
- func MkdirP(dirname string, perms ...uint32) (dir string, err error)
- func Mode(src string) (mode os.FileMode)
- func Move(src, dst string) (result string, err error)
- func OnlyDirsOpt(val bool) *opt.Opt
- func OnlyFilesOpt(val bool) *opt.Opt
- func Paths(target string) (result []string)
- func Pwd() (pwd string)
- func ReadBytes(filepath string) (result []byte, err error)
- func ReadDirnames(dirname string) (names []string, err error)
- func ReadLines(filepath string) (result []string, err error)
- func ReadString(filepath string) (result string, err error)
- func RecurseOpt(val bool) *opt.Opt
- func Remove(target string) (err error)
- func RemoveAll(target string) (err error)
- func SharedDir(first, second string) (result string)
- func Size(src string) (size int64)
- func SlicePath(target string, i, j int) (result string)
- func SplitCmd(cmd string) (slice []string)
- func Symlink(src, link string) error
- func SymlinkTarget(src string) (target string, err error)
- func SymlinkTargetExists(src string) bool
- func Touch(filepath string) (path string, err error)
- func TrimExt(target string) string
- func TrimProtocol(target string) string
- func Walk(root string, walkFn WalkFunc, opts ...*opt.Opt) (err error)
- func Windows() (result bool)
- func WriteBytes(filepath string, data []byte, perms ...uint32) (err error)
- func WriteLines(filepath string, lines []string, perms ...uint32) (err error)
- func WriteStream(reader io.Reader, filepath string, perms ...uint32) (err error)
- func WriteString(filepath string, data string, perms ...uint32) (err error)
- type FileInfo
- func (info *FileInfo) IsDir() bool
- func (info *FileInfo) IsFile() bool
- func (info *FileInfo) IsSymlink() bool
- func (info *FileInfo) IsSymlinkDir() bool
- func (info *FileInfo) IsSymlinkFile() bool
- func (info *FileInfo) ModTime() time.Time
- func (info *FileInfo) Mode() os.FileMode
- func (info *FileInfo) Name() string
- func (info *FileInfo) Size() int64
- func (info *FileInfo) SymlinkTarget() (target string, err error)
- func (info *FileInfo) SymlinkTargetExists() bool
- func (info *FileInfo) Sys() interface{}
- type WalkFunc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AllDirs ¶
AllDirs returns a list of all dirs recursively for the given root path in a deterministic order. Follows links by default, but can be stopped by passing FollowOpt(false). Paths are distinct.
func AllFiles ¶
AllFiles returns a list of all files recursively for the given root path in a deterministic order. Follows links by default, but can be stopped by passing FollowOpt(false). Paths are distinct.
func AllPaths ¶
AllPaths returns a list of all paths recursively for the given root path in a deterministic order including the root path as first entry. Follows links by default, but can be stopped by passing FollowOpt(false). Paths are distinct.
func Chmod ¶
Chmod wraps os.Chmod but provides path expansion, globbing, recursion and error tracing. For each resulting path if the file is a symbolic link, it changes the mode of the link's target. Recursively apply chmod to all files and directories by passing in RecurseOpt(true) Apply chmod to only directories or files with OnlyDirsOpt(true) and/or OnlyFilesOpt(true)
func Chown ¶
Chown wraps os.Chown but provides path expansion, globbing, recursion and error tracing. For each resulting path change the numeric uid and gid. If the file is a symbolic link, it changes the uid and gid of the link's target. A uid or gid of -1 means to not change that value. Recursively apply chown to all files and directories by passing in RecurseOpt(true)
func Copy ¶
Copy copies src to dst recursively, creating destination directories as needed. Handles globbing e.g. Copy("./*", "../") The dst will be copied to if it is an existing directory. The dst will be a clone of the src if it doesn't exist. Doesn't follow links by default but can be turned by passing in FollowOpt(true)
func CopyFile ¶
CopyFile copies a single file from src to dsty, creating destination directories as needed. The dst will be copied to if it is an existing directory. The dst will be a clone of the src if it doesn't exist. Supports passing in the FileInfo object directly with FollowOpt(true) Returns the destination path for copied file
func Dirs ¶
Dirs returns all directories from the given target path, sorted by filename Doesn't include the target itself only its children nor is this recursive.
func ExecExists ¶
ExecExists checks if the given executable exists on the PATH
func ExecOut ¶
ExecOut executes the given command and returns the output as a string. Supports string interpolation like fmt.Sprintf
func ExecPath ¶
ExecPath wraps exec.LookPath to find the path of an executable using the PATH environment variable. Returns an empty string if not found.
func Files ¶
Files returns all files from the given target path, sorted by filename. Doesn't include the target itself only its children nor is this recursive.
func FollowOpt ¶
FollowOpt creates a new follow option with the given value -------------------------------------------------------------------------------------------------
func Glob ¶
Glob wraps filepath.Glob but provides path expansion, recursion and error tracing. If no sources are found an empty string slice will be returned and a nil error. Enable recursion by passing in the option RecurseOpt(true).
func Home ¶
Home returns the absolute home directory for the current user Go 1.12 provides os.UserHomeDir so we can just call that
func InfoOpt ¶
InfoOpt creates a new option info option with the given *FileInfo -------------------------------------------------------------------------------------------------
func IsSymlinkDir ¶
IsSymlinkDir returns true if the given symlink's target is a directory
func IsSymlinkFile ¶
IsSymlinkFile returns true if the given symlink's target is a file
func MkdirP ¶
MkdirP creates the target directory and any parent directories needed and returns the ABS path of the created directory
func Move ¶
Move the src path to the dst path. If the dst already exists and is not a directory src will replace it. If there is an error it will be of type *LinkError. Wraps os.Rename but fixes the issue where dst name is required. Returns the new location
func OnlyDirsOpt ¶
OnlyDirsOpt creates a new only dirs option with the given value -------------------------------------------------------------------------------------------------
func OnlyFilesOpt ¶
OnlyFilesOpt creates a new only dirs option with the given value -------------------------------------------------------------------------------------------------
func Paths ¶
Paths returns all directories/files from the given target path, sorted by filename. Doesn't include the target itself only its children nor is this recursive.
func ReadDirnames ¶
ReadDirnames reads the directory named by dirname and returns a list of directory entries sorted by filename.
func ReadString ¶
ReadString returns the entire file as a string
func RecurseOpt ¶
RecurseOpt creates a new recurse option with the given value -------------------------------------------------------------------------------------------------
func Remove ¶
Remove the given target file or empty directory. If there is an error it will be of type *PathError
func RemoveAll ¶
RemoveAll removes the target path and any children it contains. It will retry the operation after attempting to correct file permissions on failure. If the target path does not exist nil is returned
func SplitCmd ¶
SplitCmd splits this cmd into substrings around spaces taking into account bash like double and single quotes. Unmatched quotes throw and error and empty quotes are removed.
func Symlink ¶
Symlink creates newname as a symbolic link to link. If there is an error, it will be of type *LinkError.
func SymlinkTarget ¶
SymlinkTarget follows the symlink to get the path for the target. Will get the path regardless if the target actually exists.
func SymlinkTargetExists ¶
SymlinkTargetExists returns true if the symlink's target exists
func TrimProtocol ¶
TrimProtocol removes well known protocol prefixes
func Walk ¶
Walk extends the filepath.Walk to allow for it to walk symlinks by default but can be turned off by passing in FollowOpt(false)
func WriteBytes ¶
WriteBytes is a pass through to ioutil.WriteBytes with default permissions
func WriteLines ¶
WriteLines is a pass through to ioutil.WriteFile with default permissions
func WriteStream ¶
WriteStream reads from the io.Reader and writes to the given file using io.Copy thus never filling memory i.e. streaming. dest will be overwritten if it exists.
Types ¶
type FileInfo ¶
type FileInfo struct {
Path string // absolute path to the file set when created
Val os.FileInfo // handle on the actual OS object to use where needed
}
FileInfo wraps the os.FileInfo interface and provide additional helper functions
func Lstat ¶
Lstat wraps os.Lstate to give back a FileInfo Resolves home dir and relative dir pathing into absolute paths
func ReadDir ¶
ReadDir reads the directory named by dirname and returns a list of directory entries sorted by filename. Similar to ioutil.ReadDir but using internal FileInfo types.
func (*FileInfo) IsSymlinkDir ¶
IsSymlinkDir returns true if the symlink's target is a directory
func (*FileInfo) IsSymlinkFile ¶
IsSymlinkFile returns true if the symlink's target is a file
func (*FileInfo) SymlinkTarget ¶
SymlinkTarget follows the symlink to get the path for the target
func (*FileInfo) SymlinkTargetExists ¶
SymlinkTargetExists returns true if the symlink's target exists