fileutil

package
v0.0.0-...-b544036 Latest Latest
Warning

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

Go to latest
Published: Mar 16, 2022 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateAndSyncFile

func CreateAndSyncFile(filePath string, content []byte, perm os.FileMode) error

CreateAndSyncFile creates a file, writes the content and syncs the file

func CreateAndSyncFileAtomically

func CreateAndSyncFileAtomically(dir, tmpFile, finalFile string, content []byte, perm os.FileMode) error

CreateAndSyncFileAtomically writes the content to the tmpFile, fsyncs the tmpFile, renames the tmpFile to the finalFile. In other words, in the event of a crash, either the final file will not be visible or it will have the full contents. The tmpFile should not be existing. The finalFile, if exists, will be overwritten (default rename behavior)

func CreateDirIfMissing

func CreateDirIfMissing(dirPath string) (bool, error)

CreateDirIfMissing makes sure that the dir exists and returns whether the dir is empty

func DirEmpty

func DirEmpty(dirPath string) (bool, error)

DirEmpty returns true if the dir at dirPath is empty

func DirExists

func DirExists(path string) (bool, error)

DirExists returns true if the dir already exists

func FileExists

func FileExists(path string) (bool, int64, error)

FileExists checks whether the given file exists. If the file exists, this method also returns the size of the file.

func ListSubdirs

func ListSubdirs(dirPath string) ([]string, error)

ListSubdirs returns the subdirectories

func RemoveContents

func RemoveContents(dir string) error

RemoveContents removes all the files and subdirs under the specified directory. It returns nil if the specified directory does not exist.

func SyncDir

func SyncDir(dirPath string) error

SyncDir fsyncs the given dir

func SyncParentDir

func SyncParentDir(path string) error

SyncParentDir fsyncs the parent dir of the given path

Types

This section is empty.

Jump to

Keyboard shortcuts

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