fileutil

package
v3.4.16 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 15, 2021 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package fileutil implements utility functions related to files and paths.

Index

Constants

View Source
const (
	// https://msdn.microsoft.com/en-us/library/windows/desktop/aa365203(v=vs.85).aspx
	LOCKFILE_EXCLUSIVE_LOCK   = 2
	LOCKFILE_FAIL_IMMEDIATELY = 1
)
View Source
const (
	// PrivateDirMode grants owner to make/remove files inside the directory.
	PrivateDirMode = 0777
)
View Source
const (
	// PrivateFileMode grants owner to read/write a file.
	PrivateFileMode = 0600
)

Variables

View Source
var (
	ErrLocked = errors.New("fileutil: file already locked")
)

Functions

func CheckDirPermission

func CheckDirPermission(dir string, perm os.FileMode) error

CheckDirPermission checks permission on an existing dir. Returns error if dir is empty or exist with a different permission than specified.

func CreateDirAll

func CreateDirAll(dir string) error

CreateDirAll is similar to TouchDirAll but returns error if the deepest directory was not empty.

func Exist

func Exist(name string) bool

Exist returns true if a file or directory exists.

func Fdatasync

func Fdatasync(f *os.File) error

Fdatasync is a wrapper around file.Sync(). Special handling is needed on linux platform.

func Fsync

func Fsync(f *os.File) error

Fsync is a wrapper around file.Sync(). Special handling is needed on darwin platform.

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 OpenDir

func OpenDir(path string) (*os.File, error)

OpenDir opens a directory in windows with write access for syncing.

func Preallocate

func Preallocate(f *os.File, sizeInBytes int64, extendFile bool) 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(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 ReadDir

func ReadDir(d string, opts ...ReadDirOption) ([]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.

func ZeroToEnd

func ZeroToEnd(f *os.File) error

ZeroToEnd zeros a file starting from SEEK_CUR to its SEEK_END. May temporarily shorten the length of the file.

Types

type LockedFile

type LockedFile struct{ *os.File }

func LockFile

func LockFile(path string, flag int, perm os.FileMode) (*LockedFile, error)

func TryLockFile

func TryLockFile(path string, flag int, perm os.FileMode) (*LockedFile, error)

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)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL