Documentation ¶
Index ¶
- Constants
- Variables
- func AmendFile(filePath string, data []byte, flag AmendOptions) error
- func AmendFileLocked(filePath string, data []byte, flag AmendOptions) error
- func AppendToFile(filepath string, data []byte) error
- func CaseSensitivePath(path string) (string, error)
- func CopyAndRenameFiles(fromPath, toPath string, exclude ...string) error
- func CopyAsset(assetName, dest string) error
- func CopyFile(src, target string) error
- func CopyFiles(src, dst string) error
- func CopyFilesDirReader(reader DirReader, src, dst, placeholderFileName string) error
- func CopyMultipleFiles(files map[string]string) error
- func CopySymlink(src, dest string) error
- func DirExists(path string) bool
- func FileContains(path string, searchText []byte) (bool, error)
- func FileExists(path string) bool
- func FindFileInPath(dir, filename string) (string, error)
- func GetLongPathName(path string) (string, error)
- func GetShortPathName(path string) (string, error)
- func HashDirectory(path string) (string, error)
- func HideFile(path string) error
- func IsBinary(fileBytes []byte) bool
- func IsDir(path string) bool
- func IsEmptyDir(path string) (bool, error)
- func IsExecutable(path string) bool
- func IsSymlink(path string) bool
- func IsWritable(path string) bool
- func Join(elem ...string) string
- func ListDirSimple(sourcePath string, includeDirs bool) ([]string, error)
- func ListFilesUnsafe(sourcePath string) []string
- func LogPath(path string) error
- func Mkdir(path string, subpath ...string) error
- func MkdirUnlessExists(path string) error
- func ModTime(path string) (time.Time, error)
- func MoveAllFiles(fromPath, toPath string) error
- func MoveAllFilesCrossDisk(src, dst string) error
- func MoveAllFilesRecursively(fromPath, toPath string, cb MoveAllFilesCallback) error
- func PathContainsParent(path, parentPath string) (bool, error)
- func PathInList(listSep, pathList, path string) (bool, error)
- func PathsEqual(paths ...string) (bool, error)
- func PathsMatch(paths ...string) (bool, error)
- func PrepareDir(path string) (string, error)
- func PrependToFile(filepath string, data []byte) error
- func ReadFile(filePath string) ([]byte, error)
- func ReadFileUnsafe(src string) []byte
- func ReplaceAll(filename, find, replace string) error
- func ResolvePath(path string) (string, error)
- func ResolvePathIfPossible(path string) string
- func ResolveUniquePath(path string) (string, error)
- func Sha256Hash(path string) (string, error)
- func SymlinkTarget(symlink string) (string, error)
- func TargetExists(path string) bool
- func TempDirFromBaseDirUnsafe(baseDir string) string
- func TempDirUnsafe() string
- func TempFilePathUnsafe(dir, pattern string) string
- func TempFileUnsafe(dir, pattern string) *os.File
- func Touch(path string) error
- func TouchFileUnlessExists(path string) error
- func WriteFile(filePath string, data []byte) (rerr error)
- func WriteTempFile(pattern string, data []byte) (string, error)
- func WriteTempFileToDir(dir, pattern string, data []byte, perm os.FileMode) (string, error)
- type AmendOptions
- type DirEntries
- type DirEntry
- type DirReader
- type ErrAlreadyExist
- type MoveAllFilesCallback
Constants ¶
const DirMode = os.ModePerm
DirMode is the mode used for created dirs
const FileMode = 0o644
FileMode is the mode used for created files
const LineEnd = "\n"
Variables ¶
var ErrorFileNotFound = errs.New("File could not be found")
Functions ¶
func AmendFile ¶
func AmendFile(filePath string, data []byte, flag AmendOptions) error
AmendFile amends data to a file, supports append, or prepend
func AmendFileLocked ¶
func AmendFileLocked(filePath string, data []byte, flag AmendOptions) error
func AppendToFile ¶
AppendToFile appends the data to the file (if it exists) with the given data, if the file doesn't exist it is created and the data is written
func CaseSensitivePath ¶
func CopyAndRenameFiles ¶
CopyAndRenameFiles copies files from fromDir to toDir. If the target file exists already, the source file is first copied next to the target file, and then overwrites the target by renaming the source. This method is more robust and than copying directly, in case the target file is opened or executed.
func CopyFiles ¶
CopyFiles will copy all of the files/dirs within one directory to another. Both directories must already exist
func CopyFilesDirReader ¶
func CopyMultipleFiles ¶
func CopySymlink ¶
CopySymlink reads the symlink at src and creates a new link at dest
func FileExists ¶
FileExists checks if the given file (not folder) exists
func FindFileInPath ¶
FindFileInPath will find a file by the given file-name in the directory provided or in one of the parent directories of that path by walking up the tree. If the file is found, the path to that file is returned, otherwise an failure is returned.
func GetLongPathName ¶
GetLongPathName returns the Windows long path (ie. ~1 notation is expanded) This function does not alter the path in any way on Linux or MacOS
func GetShortPathName ¶
GetShortPathName returns the Windows short path This function does not alter the path in any way on Linux or MacOS
func HashDirectory ¶
HashDirectory will sha256 hash the given directory
func IsEmptyDir ¶
IsEmptyDir returns true if the directory at the provided path has no files (including dirs) within it.
func IsExecutable ¶
IsExecutable determines if the file at the given path has any execute permissions. This function does not care whether the current user can has enough privilege to execute the file.
func IsWritable ¶
IsWritable returns true if the given path is writable
func Join ¶
Join is identical to filepath.Join except that it doesn't clean the input, allowing for more consistent behavior
func ListDirSimple ¶
ListDirSimple recursively lists filepaths under the given sourcePath This does not follow symlinks
func ListFilesUnsafe ¶
ListFilesUnsafe lists filepaths under the given sourcePath non-recursively
func LogPath ¶
LogPath will walk the given file path and log the name, permissions, mod time, and file size of all files it encounters
func MkdirUnlessExists ¶
MkdirUnlessExists will make the directory structure if it doesn't already exists
func MoveAllFiles ¶
MoveAllFiles will move all of the files/dirs within one directory to another directory. Both directories must already exist.
func MoveAllFilesCrossDisk ¶
MoveAllFilesCrossDisk will move all of the files/dirs within one directory to another directory even across disks. Both directories must already exist.
func MoveAllFilesRecursively ¶
func MoveAllFilesRecursively(fromPath, toPath string, cb MoveAllFilesCallback) error
MoveAllFilesRecursively moves files and directories from one directory to another. Unlike in MoveAllFiles, the destination directory does not need to be empty, and may include directories that are moved from the source directory. It also counts the moved files for use in a progress bar. Warnings are printed if - a source file overwrites an existing destination file - a sub-directory exists in both the source and and the destination and their permissions do not match
func PathContainsParent ¶
PathContainsParent checks if the directory path is equal to or a child directory of the targeted directory. Symlinks are evaluated for this comparison.
func PathInList ¶
PathInList returns whether the provided path list contains the provided path.
func PathsEqual ¶
PathsEqual checks whether the paths given all resolve to the same path
func PathsMatch ¶
PathsMatch checks if all the given paths resolve to the same value
func PrepareDir ¶
PrepareDir prepares a path by ensuring it exists and the path is consistent
func PrependToFile ¶
PrependToFile prepends the data to the file (if it exists) with the given data, if the file doesn't exist it is created and the data is written
func ReadFileUnsafe ¶
ReadFileUnsafe is an unsafe version of os.ReadFile, DO NOT USE THIS OUTSIDE OF TESTS
func ReplaceAll ¶
ReplaceAll replaces all instances of search text with replacement text in a file, which may be a binary file.
func ResolvePath ¶
ResolvePath gets the absolute location of the provided path and fully evaluates the result if it is a symlink.
func ResolvePathIfPossible ¶
func ResolveUniquePath ¶
ResolveUniquePath gets the absolute location of the provided path with the best effort attempt to produce the same result for all possible paths to the given target.
func Sha256Hash ¶
Sha256Hash will sha256 hash the given file
func SymlinkTarget ¶
SymlinkTarget retrieves the target of the given symlink
func TargetExists ¶
TargetExists checks if the given file or folder exists
func TempDirUnsafe ¶
func TempDirUnsafe() string
TempDirUnsafe returns a temp path or panics if it cannot be created This is for use in tests, do not use it outside tests!
func TempFilePathUnsafe ¶
func TempFileUnsafe ¶
TempFileUnsafe returns a tempfile handler or panics if it cannot be created This is for use in tests, do not use it outside tests!
func Touch ¶
Touch will attempt to "touch" a given filename by trying to open it read-only or create the file with 0644 perms if it does not exist.
func TouchFileUnlessExists ¶
TouchFileUnlessExists will attempt to "touch" a given filename if it doesn't already exists
func WriteFile ¶
WriteFile writes data to a file, if it exists it is overwritten, if it doesn't exist it is created and data is written
func WriteTempFile ¶
WriteTempFile writes data to a temp file.
Types ¶
type AmendOptions ¶
type AmendOptions uint8
AmendOptions used to specify write actions for WriteFile
const ( // AmendByAppend content to end of file AmendByAppend AmendOptions = iota // WriteOverwrite file with contents WriteOverwrite // AmendByPrepend - add content start of file AmendByPrepend )
type DirEntries ¶
type DirEntries []DirEntry
func ListDir ¶
func ListDir(sourcePath string, includeDirs bool) (DirEntries, error)
ListDir recursively lists filepaths under the given sourcePath This does not follow symlinks
func (DirEntries) RelativePaths ¶
func (d DirEntries) RelativePaths() []string
type ErrAlreadyExist ¶
type ErrAlreadyExist struct {
Path string
}
func (*ErrAlreadyExist) Error ¶
func (e *ErrAlreadyExist) Error() string
type MoveAllFilesCallback ¶
type MoveAllFilesCallback func(fromPath, toPath string)
MoveAllFilesCallback is invoked for every file that we move