fileutil

package
v0.37.1 Latest Latest
Warning

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

Go to latest
Published: Jun 6, 2022 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package fileutil provides utility methods used when dealing with the filesystem in tsdb. It is largely copied from github.com/coreos/etcd/pkg/fileutil to avoid the dependency chain it brings with it. Please check github.com/coreos/etcd for licensing information.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CopyDirs

func CopyDirs(src, dest string) error

CopyDirs copies all directories, subdirectories and files recursively including the empty folders. Source and destination must be full paths.

func DirSize

func DirSize(dir string) (int64, error)

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 OpenDir

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

OpenDir opens a directory 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 Rename

func Rename(from, to string) error

Rename safely renames a file.

func Replace

func Replace(from, to string) error

Replace moves a file or directory to a new location and deletes any previous data. It is not atomic.

Types

type MmapFile

type MmapFile struct {
	// contains filtered or unexported fields
}

func OpenMmapFile

func OpenMmapFile(path string) (*MmapFile, error)

func OpenMmapFileWithSize

func OpenMmapFileWithSize(path string, size int) (mf *MmapFile, retErr error)

func (*MmapFile) Bytes

func (f *MmapFile) Bytes() []byte

func (*MmapFile) Close

func (f *MmapFile) Close() error

func (*MmapFile) File

func (f *MmapFile) File() *os.File

type Releaser

type Releaser interface {
	Release() error
}

Releaser provides the Release method to release a file lock.

func Flock

func Flock(fileName string) (r Releaser, existed bool, err error)

Flock locks the file with the provided name. If the file does not exist, it is created. The returned Releaser is used to release the lock. existed is true if the file to lock already existed. A non-nil error is returned if the locking has failed. Neither this function nor the returned Releaser is goroutine-safe.

Jump to

Keyboard shortcuts

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