Documentation ¶
Overview ¶
Package fileutil contains various utility functions useful for dealing with files and dirs.
Index ¶
- func CheckDirPeriodic(dir string, delay time.Duration, action func() error)
- func CopyFile(src, dest string, destFlags int) error
- func CopySomeFiles(srcDir, destDir string, flist []string) error
- func DirMatchCaseInsensitive(dir string, entries []string) (hit bool, results []string)
- func DirSizeM(dir string) string
- func FindCaseInsensitive(root, name string, maxdepth int) (files []string, err error)
- func ForcePathCase(basepath, target string) (success bool)
- func FreeSpace(dir string) int64
- func FreeSpaceM(dir string) string
- func Globlike(p string) bool
- func IsEmptyDir(dir string) bool
- func IsMountpoint(dir string) bool
- func IsXZ(fname string) bool
- func IsXZSha256(fname string) bool
- func ListFilesAndSize(dir, pattern string) (size int64, files []string)
- func MkdirOwned(root, dir, owner, group string, mode os.FileMode) bool
- func ReadConfigLines(path string, maxLines int) ([]string, error)
- func ReadHeader(fname string, n int64) (head []byte, err error)
- func RecursiveCopy(src, dest string) error
- func RenameUnique(old, newPfx string) (success bool)
- func ShowProgress(done chan struct{}, activityDesc, path string)
- func ToMegs(size int64) string
- func WaitFor(path string, timeout time.Duration) (found bool)
- func WaitForChan(path string, stop chan struct{}) (found bool)
- func WaitForDir(watchedIsMountpoint bool, watchDir string)
- type UtfVariant
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CheckDirPeriodic ¶
Checks that a dir's inode does not change; if it does, call action(). Call from goroutine. Returns (exiting goroutine) if action returns error.
func CopySomeFiles ¶
Copy files in flist to destDir, stripping srcDir. flist must be absolute paths. NOTE: may be slow to return, due to use of O_SYNC
func DirMatchCaseInsensitive ¶
Case-insensitive search of 'dir' for all of 'entries'. results will be an array the same size as entries, containing any matches - in the same order as entries. In the event of multiple files matching one of entries, the first seen is chosen.
func FindCaseInsensitive ¶
Perform case-insensitive search for file matching name (not a glob), under root, max depth maxdepth. Ignores symlinks. Returns absolute paths.
func ForcePathCase ¶
ForcePathCase ensures correct case for some dir or file target in basepath. If target exists with different case, rename. If multiple variations exist, delete all but one.
func FreeSpaceM ¶
Returns human-readable free space (in MB) for FS containing given dir.
func Globlike ¶
Crude check that given path is not a glob. Does not understand escape sequences, so could return false positives.
func IsMountpoint ¶
IsMountpoint searchs for given dir in /proc/self/mountinfo, returns true if found
func IsXZSha256 ¶
Checks for XZ header and stream option byte indicating sha256
func ListFilesAndSize ¶
Recursively find all files matching pattern in dir; return them and their total size. 'dir' must not be a glob pattern.
func MkdirOwned ¶
Create dir in root with given owner, group, and mode
func ReadConfigLines ¶
ReadConfigLines reads a config file at the given path. Whitespace is stripped, as are comments (anything between # and \n). Individual lines are returned, up to maxLines.
func ReadHeader ¶
return n bytes from beginning of file
func RecursiveCopy ¶
RecursiveCopy walks tree rooted at src, copies dir 'src' to a subdir of dest.
NOTE: may be slow to return, due to use of O_SYNC.
func RenameUnique ¶
Renames old in same dir, using newPfx + random suffix (via os.TempFile)
func ShowProgress ¶
func ShowProgress(done chan struct{}, activityDesc, path string)
Called from a goroutine, updates lcd with size of a file. Use with download or decompress operation; close(done) to stop.
func WaitFor ¶
WaitFor waits for a file to appear or times out. Returns true if file appears, false otherwise. Sleeps .1s between checks.
func WaitForChan ¶
WaitForChan is like WaitFor, but returns no later than when stop chan is closed
func WaitForDir ¶
WaitForDir waits for a dir to exist, and, if watchedIsMountpoint is true, waits for a fs to mount there.
Types ¶
type UtfVariant ¶
type UtfVariant uint
const ( None UtfVariant = iota Utf32be Utf32le Utf16be Utf16le Utf8 )
func DetectBOM ¶
func DetectBOM(fd io.ReadSeeker) (v UtfVariant, err error)
Check for UTF byte order mark; if present, seeks past it