Documentation
¶
Index ¶
- Constants
- func IsDirOrSymlink(de os.DirEntry) bool
- func IsPartiallyRemovedDir(dirPath string) bool
- func IsPathExist(path string) bool
- func IsTemporaryFileName(fn string) bool
- func MustClose(f *os.File)
- func MustCloseParallel(cs []MustCloser)
- func MustCopyDirectory(srcPath, dstPath string)
- func MustCopyFile(srcPath, dstPath string)
- func MustCreateFlockFile(dir string) *os.File
- func MustFileSize(path string) uint64
- func MustGetFreeSpace(path string) uint64
- func MustGetTotalSpace(path string) uint64
- func MustHardLinkFiles(srcDir, dstDir string)
- func MustMkdirFailIfExist(path string)
- func MustMkdirIfNotExist(path string)
- func MustReadData(r filestream.ReadCloser, data []byte)
- func MustReadDir(dir string) []os.DirEntry
- func MustRemoveDir(dirPath string)
- func MustRemoveDirContents(dir string)
- func MustRemovePath(path string)
- func MustSymlinkRelative(srcPath, dstPath string)
- func MustSyncPath(path string)
- func MustSyncPathAndParentDir(path string)
- func MustWriteAtomic(path string, data []byte, canOverwrite bool)
- func MustWriteData(w filestream.WriteCloser, data []byte)
- func MustWriteSync(path string, data []byte)
- type MustCloser
- type MustReadAtCloser
- type ParallelReaderAtOpener
- type ReaderAt
Constants ¶
const FlockFilename = "flock.lock"
FlockFilename is the filename for the file created by MustCreateFlockFile().
Variables ¶
This section is empty.
Functions ¶
func IsDirOrSymlink ¶
IsDirOrSymlink returns true if de is directory or symlink.
func IsPartiallyRemovedDir ¶ added in v1.110.15
IsPartiallyRemovedDir returns true if dirPath is partially removed because of unclean shutdown during the MustRemoveDir() call.
The caller must call MustRemoveDir(dirPath) on partially removed dirPath.
func IsPathExist ¶
IsPathExist returns whether the given path exists.
func IsTemporaryFileName ¶ added in v1.25.0
IsTemporaryFileName returns true if fn matches temporary file name pattern from MustWriteAtomic.
func MustCloseParallel ¶ added in v1.110.15
func MustCloseParallel(cs []MustCloser)
MustCloseParallel closes all the cs in parallel.
Parallel closing reduces the time needed to flush the data to the underlying files on close on high-latency storage systems such as NFS or Ceph.
func MustCopyDirectory ¶ added in v1.91.0
func MustCopyDirectory(srcPath, dstPath string)
MustCopyDirectory creates dstPath and copies all the files in srcPath to dstPath.
The caller is responsible for calling MustSyncPath() for the parent directory of dstPath.
func MustCopyFile ¶ added in v1.91.0
func MustCopyFile(srcPath, dstPath string)
MustCopyFile copies the file from srcPath to dstPath.
func MustCreateFlockFile ¶ added in v1.91.0
MustCreateFlockFile creates FlockFilename file in the directory dir and returns the handler to the file.
func MustFileSize ¶ added in v1.21.2
MustFileSize returns file size for the given path.
func MustGetFreeSpace ¶ added in v1.27.0
MustGetFreeSpace returns free space for the given directory path.
func MustGetTotalSpace ¶ added in v1.110.15
MustGetTotalSpace returns the total disk space for the given directory path.
func MustHardLinkFiles ¶ added in v1.91.0
func MustHardLinkFiles(srcDir, dstDir string)
MustHardLinkFiles creates dstDir and makes hard links for all the files from srcDir in dstDir.
The caller is responsible for calling MustSyncPath for the parent directory of dstDir.
func MustMkdirFailIfExist ¶ added in v1.91.0
func MustMkdirFailIfExist(path string)
MustMkdirFailIfExist creates the given path dir if it isn't exist.
If the directory at the given path already exists, then the function logs the fatal error and exits the process.
The caller is responsible for MustSyncPath() call for the parent directory for the path.
func MustMkdirIfNotExist ¶ added in v1.91.0
func MustMkdirIfNotExist(path string)
MustMkdirIfNotExist creates the given path dir if it isn't exist.
The caller is responsible for MustSyncPath() call for the parent directory for the path.
func MustReadData ¶ added in v1.91.0
func MustReadData(r filestream.ReadCloser, data []byte)
MustReadData reads len(data) bytes from r.
func MustReadDir ¶ added in v1.91.0
MustReadDir reads directory entries at the given dir.
func MustRemoveDir ¶ added in v1.110.15
func MustRemoveDir(dirPath string)
MustRemoveDir removes the dirPath with all its contents.
The dirPath contents may be partially deleted if unclean shutdown happens during the removal. The caller must verify whether the given directory is partially removed via IsPartiallyRemovedDir() call on the startup before using it. If the directory is partially removed, it must be removed again via MustRemoveDir() call.
func MustRemoveDirContents ¶ added in v1.110.15
func MustRemoveDirContents(dir string)
MustRemoveDirContents removes all the contents of the given dir if it exists.
It doesn't remove the dir itself, so the dir may be mounted to a separate partition.
func MustRemovePath ¶ added in v1.110.15
func MustRemovePath(path string)
MustRemovePath removes the given path. It must be either a file or an empty directory.
Use MustRemoveDir for removing non-empty directories.
func MustSymlinkRelative ¶ added in v1.91.0
func MustSymlinkRelative(srcPath, dstPath string)
MustSymlinkRelative creates relative symlink for srcPath in dstPath.
The caller is responsible for calling MustSyncPath() for the parent directory of dstPath.
func MustSyncPath ¶ added in v1.19.2
func MustSyncPath(path string)
MustSyncPath syncs contents of the given path.
func MustSyncPathAndParentDir ¶ added in v1.102.26
func MustSyncPathAndParentDir(path string)
MustSyncPathAndParentDir fsyncs the path and the parent dir.
This guarantees that the path is visible and readable after unclean shutdown.
func MustWriteAtomic ¶ added in v1.91.0
MustWriteAtomic atomically writes data to the given file path.
This function returns only after the file is fully written and synced to the underlying storage.
This function guarantees that the file at path either fully written or not written at all on app crash in the middle of the write.
If the file at path already exists, then the file is overwritten atomically if canOverwrite is true. Otherwise, error is returned.
func MustWriteData ¶
func MustWriteData(w filestream.WriteCloser, data []byte)
MustWriteData writes data to w.
func MustWriteSync ¶ added in v1.91.0
MustWriteSync writes data to the file at path and then calls fsync on the created file.
The fsync guarantees that the written data survives hardware reset after successful call.
This function may leave the file at the path in inconsistent state on app crash in the middle of the write. Use MustWriteAtomic if the file at the path must be either written in full or not written at all on app crash in the middle of the write.
Types ¶
type MustCloser ¶ added in v1.110.15
type MustCloser interface {
MustClose()
}
MustCloser must implement MustClose() function.
type MustReadAtCloser ¶ added in v1.33.0
type MustReadAtCloser interface {
// Path must return path for the reader (e.g. file path, url or in-memory reference)
Path() string
// MustReadAt must read len(p) bytes from offset off to p.
MustReadAt(p []byte, off int64)
// MustClose must close the reader.
MustClose()
}
MustReadAtCloser is rand-access read interface.
type ParallelReaderAtOpener ¶ added in v1.110.15
type ParallelReaderAtOpener struct {
// contains filtered or unexported fields
}
ParallelReaderAtOpener opens ReaderAt files in parallel.
ParallelReaderAtOpener speeds up opening multiple ReaderAt files on high-latency storage systems such as NFS or Ceph.
func (*ParallelReaderAtOpener) Add ¶ added in v1.110.15
func (pro *ParallelReaderAtOpener) Add(path string, rc *MustReadAtCloser, fileSize *uint64)
Add adds a task for opening the file at the given path and storing it to *r, while storing the file size into *fileSize.
Call Run() for running all the registered tasks in parallel.
func (*ParallelReaderAtOpener) Run ¶ added in v1.110.15
func (pro *ParallelReaderAtOpener) Run()
Run executes all the registered tasks in parallel.
type ReaderAt ¶
type ReaderAt struct {
// contains filtered or unexported fields
}
ReaderAt implements rand-access reader.
func MustOpenReaderAt ¶ added in v1.48.0
MustOpenReaderAt opens ReaderAt for reading from the file located at path.
MustClose must be called on the returned ReaderAt when it is no longer needed.
func NewReaderAt ¶ added in v1.97.2
NewReaderAt returns ReaderAt for reading from f.
NewReaderAt takes ownership for f, so it shouldn't be closed by the caller.
MustClose must be called on the returned ReaderAt when it is no longer needed.
func (*ReaderAt) MustFadviseSequentialRead ¶ added in v1.33.0
MustFadviseSequentialRead hints the OS that f is read mostly sequentially.
if prefetch is set, then the OS is hinted to prefetch f data.
func (*ReaderAt) MustReadAt ¶ added in v1.33.0
MustReadAt reads len(p) bytes at off from r.
func (*ReaderAt) SetUseLocalStats ¶ added in v1.87.4
func (r *ReaderAt) SetUseLocalStats()
SetUseLocalStats switches to local stats collection instead of global stats collection.
This function must be called before the first call to MustReadAt().
Collecting local stats may improve performance on systems with big number of CPU cores, since the locally collected stats is pushed to global stats only at MustClose() call instead of pushing it at every MustReadAt call.