package fileutil

import "github.com/coreos/etcd/pkg/fileutil"

Package fileutil implements utility functions related to files and paths.

Index

Constants

const (
	// PrivateFileMode grants owner to read/write a file.
	PrivateFileMode = 0600
	// PrivateDirMode grants owner to make/remove files inside the directory.
	PrivateDirMode = 0700
)

Variables

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

Functions

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

func Fdatasync

func Fdatasync(f *os.File) error

Fdatasync on darwin platform invokes fcntl(F_FULLFSYNC) for actual persistence on physical drive media.

func Fsync

func Fsync(f *os.File) error

Fsync on HFS/OSX flushes the data on to the physical drive but the drive may not write it to the persistent media for quite sometime and it may be written in out-of-order sequence. Using F_FULLFSYNC ensures that the physical drive's buffer will also get flushed to the media.

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 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(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 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)

Source Files

fileutil.go lock.go lock_flock.go lock_unix.go preallocate.go preallocate_darwin.go purge.go sync_darwin.go

Version
v3.0.2+incompatible
Published
Jul 8, 2016
Platform
darwin/amd64
Imports
11 packages
Last checked
40 minutes ago

Tools for package owners.