Documentation
¶
Overview ¶
Package fileutil implements utility functions related to files and paths.
Index ¶
- Variables
- func Exist(name string) bool
- func Fdatasync(f *os.File) error
- func IsDirWriteable(dir string) error
- func Preallocate(f *os.File, sizeInBytes int) error
- func PurgeFile(dirname string, suffix string, max uint, interval time.Duration, ...) <-chan error
- func ReadDir(dirpath string) ([]string, error)
- func TouchDirAll(dir string) error
- type Lock
Constants ¶
This section is empty.
Variables ¶
var (
ErrLocked = errors.New("file already locked")
)
Functions ¶
func Fdatasync ¶
func Fdatasync(f *os.File) error
Fdatasync is similar to fsync(), but does not flush modified metadata unless that metadata is needed in order to allow a subsequent data retrieval to be correctly handled.
func IsDirWriteable ¶
func IsDirWriteable(dir string) error
IsDirWriteable checks if dir is writable by writing and removing a file to dir. It returns nil if dir is writable.
func Preallocate ¶
func Preallocate(f *os.File, sizeInBytes int) error
Preallocate tries to allocate the space for given file. This operation is only supported on linux by a few filesystems (btrfs, ext4, etc.). If the operation is unsupported, no error will be returned. Otherwise, the error encountered will be returned.
func PurgeFile ¶
func PurgeFile(dirname string, suffix string, max uint, interval time.Duration, stop <-chan struct{}) <-chan error
func ReadDir ¶
func ReadDir(dirpath string) ([]string, error)
ReadDir returns the filenames in the given directory in sorted order.
func TouchDirAll ¶
func TouchDirAll(dir string) error
TouchDirAll is similar to os.MkdirAll. It creates directories with 0700 permission if any directory does not exists. TouchDirAll also ensures the given directory is writable.
Types ¶
type Lock ¶
type Lock interface {
// Name returns the name of the file.
Name() string
// TryLock acquires exclusivity on the lock without blocking.
TryLock() error
// Lock acquires exclusivity on the lock.
Lock() error
// Unlock unlocks the lock.
Unlock() error
// Destroy should be called after Unlock to clean up
// the resources.
Destroy() error
}