Documentation ¶
Overview ¶
Package fileutil implements utility functions related to files and paths.
Index ¶
- Constants
- Variables
- func CreateDirAll(dir string) error
- func Exist(name string) bool
- func Fdatasync(f *os.File) error
- func Fsync(f *os.File) error
- func IsDirWriteable(dir string) error
- func OpenDir(path string) (*os.File, error)
- func Preallocate(f *os.File, sizeInBytes int64, extendFile bool) error
- func PurgeFile(dirname string, suffix string, max uint, interval time.Duration, ...) <-chan error
- func PurgeFileWithDoneNotify(dirname string, suffix string, max uint, interval time.Duration, ...) (<-chan struct{}, <-chan error)
- func ReadDir(dirpath string) ([]string, error)
- func TouchDirAll(dir string) error
- func ZeroToEnd(f *os.File) error
- type LockedFile
Constants ¶
const ( // PrivateFileMode grants owner to read/write a file. PrivateFileMode = 0600 // PrivateDirMode grants owner to make/remove files inside the directory. PrivateDirMode = 0700 )
const ( F_OFD_GETLK = 37 F_OFD_SETLK = 37 F_OFD_SETLKW = 38 )
This used to call syscall.Flock() but that call fails with EBADF on NFS. An alternative is lockf() which works on NFS but that call lets a process lock the same file twice. Instead, use Linux's non-standard open file descriptor locks which will block if the process already holds the file lock.
constants from /usr/include/bits/fcntl-linux.h
Variables ¶
var (
ErrLocked = errors.New("fileutil: file already locked")
)
Functions ¶
func CreateDirAll ¶
CreateDirAll is similar to TouchDirAll but returns error if the deepest directory was not empty.
func Fdatasync ¶
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 ¶
IsDirWriteable checks if dir is writable by writing and removing a file to dir. It returns nil if dir is writable.
func Preallocate ¶
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 PurgeFileWithDoneNotify ¶ added in v3.2.28
func TouchDirAll ¶
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.