Documentation ¶
Index ¶
- func CopyDirectory(srcPath, dstPath string) error
- func CopyFile(srcPath, dstPath string) error
- func CreateFlockFile(dir string) (*os.File, error)
- func GetFilepath(baseDir, path string) string
- func HardLinkFiles(srcDir, dstDir string) error
- func IsDirOrSymlink(de os.DirEntry) bool
- func IsEmptyDir(path string) bool
- func IsPathExist(path string) bool
- func IsScheduledForRemoval(filename string) bool
- func IsTemporaryFileName(fn string) bool
- func MkdirAllFailIfExist(path string) error
- func MkdirAllIfNotExist(path string) error
- func MustClose(f *os.File)
- func MustFileSize(path string) uint64
- func MustGetFreeSpace(path string) uint64
- func MustRemoveAll(path string)
- func MustRemoveDirAtomic(dir string)
- func MustRemoveTemporaryDirs(dir string)
- func MustStopDirRemover()
- func MustSyncPath(path string)
- func MustWriteData(w io.Writer, data []byte)
- func ReadFileOrHTTP(path string) ([]byte, error)
- func ReadFullData(r io.Reader, data []byte) error
- func RemoveDirContents(dir string)
- func SymlinkRelative(srcPath, dstPath string) error
- func WriteFileAndSync(path string, data []byte) error
- func WriteFileAtomically(path string, data []byte, canOverwrite bool) error
- type MustReadAtCloser
- type ReaderAt
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CopyDirectory ¶ added in v1.54.0
CopyDirectory copies all the files in srcPath to dstPath.
func CreateFlockFile ¶ added in v1.25.0
CreateFlockFile creates flock.lock file in the directory dir and returns the handler to the file.
func GetFilepath ¶ added in v1.71.0
GetFilepath returns full path to file for the given baseDir and path.
func HardLinkFiles ¶
HardLinkFiles makes hard links for all the files from srcDir in dstDir.
func IsDirOrSymlink ¶
IsDirOrSymlink returns true if de is directory or symlink.
func IsEmptyDir ¶ added in v1.59.0
IsEmptyDir returns true if path points to empty directory.
func IsPathExist ¶
IsPathExist returns whether the given path exists.
func IsScheduledForRemoval ¶ added in v1.87.2
IsScheduledForRemoval returns true if the filename contains .must-remove. substring
func IsTemporaryFileName ¶ added in v1.25.0
IsTemporaryFileName returns true if fn matches temporary file name pattern from WriteFileAtomically.
func MkdirAllFailIfExist ¶
MkdirAllFailIfExist creates the given path dir if it isn't exist.
Returns error if path already exists.
func MkdirAllIfNotExist ¶
MkdirAllIfNotExist creates the given path dir if it isn't exist.
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 MustRemoveAll ¶ added in v1.19.0
func MustRemoveAll(path string)
MustRemoveAll removes path with all the contents.
It properly fsyncs the parent directory after path removal.
It properly handles NFS issue https://github.com/VictoriaMetrics/VictoriaMetrics/issues/61 .
func MustRemoveDirAtomic ¶ added in v1.82.0
func MustRemoveDirAtomic(dir string)
MustRemoveDirAtomic removes the given dir atomically.
It uses the following algorithm:
- Atomically rename the "<dir>" to "<dir>.must-remove.<XYZ>", where <XYZ> is an unique number.
- Remove the "<dir>.must-remove.XYZ" in background.
If the process crashes after the step 1, then the directory must be removed on the next process start by calling MustRemoveTemporaryDirs on the parent directory.
func MustRemoveTemporaryDirs ¶ added in v1.82.0
func MustRemoveTemporaryDirs(dir string)
MustRemoveTemporaryDirs removes all the subdirectories with ".must-remove.<XYZ>" suffix.
Such directories may be left on unclean shutdown during MustRemoveDirAtomic call.
func MustStopDirRemover ¶ added in v1.27.2
func MustStopDirRemover()
MustStopDirRemover must be called in the end of graceful shutdown in order to wait for removing the remaining directories from removeDirConcurrencyCh.
It is expected that nobody calls MustRemoveAll when MustStopDirRemover is called.
func MustSyncPath ¶ added in v1.19.2
func MustSyncPath(path string)
MustSyncPath syncs contents of the given path.
func ReadFileOrHTTP ¶ added in v1.71.0
ReadFileOrHTTP reads path either from local filesystem or from http if path starts with http or https.
func ReadFullData ¶
ReadFullData reads len(data) bytes from r.
func RemoveDirContents ¶
func RemoveDirContents(dir string)
RemoveDirContents 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 SymlinkRelative ¶
SymlinkRelative creates relative symlink for srcPath in dstPath.
func WriteFileAndSync ¶ added in v1.85.0
WriteFileAndSync 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 WriteFileAtomically 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.
func WriteFileAtomically ¶ added in v1.25.0
WriteFileAtomically 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.
Types ¶
type MustReadAtCloser ¶ added in v1.33.0
type MustReadAtCloser interface { // 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 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 filename.
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.