package fileutil
import "go.etcd.io/etcd/client/pkg/v3/fileutil"
Package fileutil implements utility functions related to files and paths.
Index ¶
- Constants
- Variables
- func CheckDirPermission(dir string, perm os.FileMode) error
- func CreateDirAll(lg *zap.Logger, dir string) error
- func DirEmpty(name string) bool
- 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(lg *zap.Logger, dirname string, suffix string, max uint, interval time.Duration, stop <-chan struct{}) <-chan error
- func PurgeFileWithDoneNotify(lg *zap.Logger, dirname string, suffix string, max uint, interval time.Duration, stop <-chan struct{}) (<-chan struct{}, <-chan error)
- func PurgeFileWithoutFlock(lg *zap.Logger, dirname string, suffix string, max uint, interval time.Duration, stop <-chan struct{}) (<-chan struct{}, <-chan error)
- func ReadDir(d string, opts ...ReadDirOption) ([]string, error)
- func RemoveMatchFile(lg *zap.Logger, dir string, matchFunc func(fileName string) bool) error
- func TouchDirAll(lg *zap.Logger, dir string) error
- func ZeroToEnd(f *os.File) error
- type FileBufReader
- func NewFileBufReader(fr FileReader) *FileBufReader
- func (fbr *FileBufReader) FileInfo() fs.FileInfo
- type FileReader
- type LockedFile
- func LockFile(path string, flag int, perm os.FileMode) (*LockedFile, error)
- func TryLockFile(path string, flag int, perm os.FileMode) (*LockedFile, error)
- type ReadDirOp
- type ReadDirOption
Constants ¶
const ( // PrivateDirMode grants owner to make/remove files inside the directory. PrivateDirMode = 0700 )
const ( // PrivateFileMode grants owner to read/write a file. PrivateFileMode = 0600 )
Variables ¶
Functions ¶
func CheckDirPermission ¶
CheckDirPermission checks permission on an existing dir. Returns error if dir is empty or exist with a different permission than specified.
func CreateDirAll ¶
CreateDirAll is similar to TouchDirAll but returns error if the deepest directory was not empty.
func DirEmpty ¶
DirEmpty returns true if a directory empty and can access.
func Exist ¶
Exist returns true if a file or directory exists.
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 Fsync ¶
Fsync is a wrapper around file.Sync(). Special handling is needed on darwin platform.
func IsDirWriteable ¶
IsDirWriteable checks if dir is writable by writing and removing a file to dir. It returns nil if dir is writable.
func OpenDir ¶
OpenDir opens a directory for syncing.
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 PurgeFile ¶
func PurgeFile(lg *zap.Logger, dirname string, suffix string, max uint, interval time.Duration, stop <-chan struct{}) <-chan error
func PurgeFileWithDoneNotify ¶
func PurgeFileWithDoneNotify(lg *zap.Logger, dirname string, suffix string, max uint, interval time.Duration, stop <-chan struct{}) (<-chan struct{}, <-chan error)
func PurgeFileWithoutFlock ¶
func PurgeFileWithoutFlock(lg *zap.Logger, dirname string, suffix string, max uint, interval time.Duration, stop <-chan struct{}) (<-chan struct{}, <-chan error)
func ReadDir ¶
func ReadDir(d string, opts ...ReadDirOption) ([]string, error)
ReadDir returns the filenames in the given directory in sorted order.
func RemoveMatchFile ¶
RemoveMatchFile deletes file if matchFunc is true on an existing dir Returns error if the dir does not exist or remove file fail
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.
func ZeroToEnd ¶
ZeroToEnd zeros a file starting from SEEK_CUR to its SEEK_END. May temporarily shorten the length of the file.
Types ¶
type FileBufReader ¶
FileBufReader is a wrapper of bufio.Reader. It also provides file info.
func NewFileBufReader ¶
func NewFileBufReader(fr FileReader) *FileBufReader
func (*FileBufReader) FileInfo ¶
func (fbr *FileBufReader) FileInfo() fs.FileInfo
type FileReader ¶
FileReader is a wrapper of io.Reader. It also provides file info.
func NewFileReader ¶
func NewFileReader(f *os.File) FileReader
type LockedFile ¶
func LockFile ¶
func TryLockFile ¶
type ReadDirOp ¶
type ReadDirOp struct {
// contains filtered or unexported fields
}
ReadDirOp represents an read-directory operation.
type ReadDirOption ¶
type ReadDirOption func(*ReadDirOp)
ReadDirOption configures archiver operations.
func WithExt ¶
func WithExt(ext string) ReadDirOption
WithExt filters file names by their extensions. (e.g. WithExt(".wal") to list only WAL files)
Source Files ¶
dir_unix.go doc.go filereader.go fileutil.go lock.go lock_flock.go lock_linux.go preallocate.go preallocate_unix.go purge.go read_dir.go sync_linux.go
- Version
- v3.5.18 (latest)
- Published
- Jan 24, 2025
- Platform
- linux/amd64
- Imports
- 14 packages
- Last checked
- 5 days ago –
Tools for package owners.