Documentation ¶
Overview ¶
Package fs provides various filesystem helpers.
Index ¶
- Constants
- func CopyFile(from string, to string, mode os.FileMode) error
- func CopyOrLinkFile(from, to string, mode os.FileMode, link, fallback bool) error
- func EnsureDir(filename string) error
- func ExpandHomePath(path string) string
- func FileExists(filename string) bool
- func Glob(buildFileNames []string, rootPath string, ...) []string
- func IsGlob(pattern string) bool
- func IsPackage(buildFileNames []string, name string) bool
- func IsSameFile(a, b string) bool
- func IsSymlink(filename string) bool
- func PathExists(filename string) bool
- func RecursiveCopy(from string, to string, mode os.FileMode) error
- func RecursiveLink(from string, to string, mode os.FileMode) error
- func SortPaths(files []string) []string
- func Walk(rootPath string, callback func(name string, isDir bool) error) error
- func WalkMode(rootPath string, ...) error
- func WriteFile(fromFile io.Reader, to string, mode os.FileMode) error
- type PathHasher
Constants ¶
DirPermissions are the default permission bits we apply to directories.
Variables ¶
This section is empty.
Functions ¶
func CopyFile ¶
CopyFile copies a file from 'from' to 'to', with an attempt to perform a copy & rename to avoid chaos if anything goes wrong partway.
func CopyOrLinkFile ¶
CopyOrLinkFile either copies or hardlinks a file based on the link argument. Falls back to a copy if link fails and fallback is true.
func EnsureDir ¶
EnsureDir ensures that the directory of the given file has been created.
func ExpandHomePath ¶
ExpandHomePath expands all prefixes of ~ without a user specifier to $HOME.
func FileExists ¶
FileExists returns true if the given path exists and is a file.
func Glob ¶
func Glob(buildFileNames []string, rootPath string, includes, prefixedExcludes, excludes []string, includeHidden bool) []string
Glob implements matching using Go's built-in filepath.Glob, but extends it to support Ant-style patterns using **.
func IsGlob ¶
IsGlob returns true if the given pattern requires globbing (i.e. contains characters that would be expanded by it)
func IsPackage ¶
IsPackage returns true if the given directory name is a package (i.e. contains a build file)
func IsSameFile ¶
IsSameFile returns true if two filenames describe the same underlying file (i.e. inode)
func IsSymlink ¶
IsSymlink returns true if the given path exists and is a symlink.
func PathExists ¶
PathExists returns true if the given path exists, as a file or a directory.
func RecursiveCopy ¶
RecursiveCopy copies either a single file or a directory.
func RecursiveLink ¶
RecursiveLink hardlinks either a single file or a directory. Note that you can't hardlink directories so the behaviour is much the same as a recursive copy. If it can't link then it falls back to a copy.
func SortPaths ¶
SortPaths sorts a list of filepaths in lexicographic order by component (i.e. so all files in a directory sort after all subdirectories).
func Walk ¶
Walk implements an equivalent to filepath.Walk. It's implemented over github.com/karrick/godirwalk but the provided interface doesn't use that to make it a little easier to handle.
func WalkMode ¶
func WalkMode(rootPath string, callback func(name string, isDir bool, mode os.FileMode) error) error
WalkMode is like Walk but the callback receives an additional type specifying the file mode type. N.B. This only includes the bits of the mode that determine the mode type, not the permissions.
Types ¶
type PathHasher ¶
type PathHasher struct {
// contains filtered or unexported fields
}
A PathHasher is responsible for hashing & remembering paths.
func NewPathHasher ¶
func NewPathHasher(root string) *PathHasher
NewPathHasher returns a new PathHasher based on the given root directory.
func (*PathHasher) Hash ¶
func (hasher *PathHasher) Hash(path string, recalc bool) ([]byte, error)
Hash hashes a single path. It is memoised and so will only hash each path once, unless recalc is true which will then force a recalculation of it.
func (*PathHasher) MoveHash ¶
func (hasher *PathHasher) MoveHash(oldPath, newPath string, copy bool)
MoveHash is used when we move files from tmp to out and there was one there before; that's the only case in which the hash of a filepath could change.
func (*PathHasher) MustHash ¶
func (hasher *PathHasher) MustHash(path string) []byte
MustHash is as Hash but panics on error.
func (*PathHasher) SetHash ¶
func (hasher *PathHasher) SetHash(path string, hash []byte)
SetHash is used to directly set a hash for a path. This is used for remote files where we download them & therefore know the hash as they come in. TODO(peterebden): We should probably use this more for things like caches and so forth...