Documentation ¶
Overview ¶
Package fileutils contains the utility functions about file management
Index ¶
- func AppendStringToFile(targetFile string, content string) (err error)
- func CopyFile(source, destination string) (err error)
- func CreateEmptyFile(fileName string) error
- func EnsureDirectoryExists(destinationDir string) error
- func EnsureParentDirectoryExist(fileName string) error
- func EnsurePgDataPerms(pgData string) error
- func FileExists(fileName string) (bool, error)
- func GetDirectoryContent(dir string) (files []string, err error)
- func GetFileSize(fileName string) (int64, error)
- func MoveDirectoryContent(sourceDirectory, destinationDirectory string) error
- func MoveFile(sourcePath, destPath string) (err error)
- func OpenFileAsync(ctx context.Context, fileName string, flag int, perm os.FileMode) (f *os.File, err error)
- func ReadFile(fileName string) ([]byte, error)
- func ReadFileLines(fileName string) (lines []string, err error)
- func RemoveDirectoryContent(dir string) (err error)
- func RemoveFile(fileName string) error
- func WriteFileAtomic(fileName string, contents []byte, perm os.FileMode) (bool, error)
- func WriteLinesToFile(fileName string, lines []string) (changed bool, err error)
- func WriteStringToFile(fileName string, contents string) (changed bool, err error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AppendStringToFile ¶
AppendStringToFile append the content of the given string to the end of the target file prepending new data with a carriage return
func CreateEmptyFile ¶
CreateEmptyFile create an empty file or return an error if the file already exist
func EnsureDirectoryExists ¶ added in v1.17.4
EnsureDirectoryExists check if the passed directory exists or not, and if it doesn't exist, create it using 0700 as permissions bits
func EnsureParentDirectoryExist ¶
EnsureParentDirectoryExist check if the directory containing a certain file exist or not, and if is not existent will create the directory using 0700 as permissions bits
func EnsurePgDataPerms ¶
EnsurePgDataPerms ensure PGDATA has 0700 permissions, which are required for PostgreSQL to successfully startup
func FileExists ¶
FileExists check if a file exists, and return an error otherwise
func GetDirectoryContent ¶
GetDirectoryContent return a slice of string with the name of the files in the dir directory
func GetFileSize ¶
GetFileSize returns the size of a file or an error
func MoveDirectoryContent ¶ added in v1.17.0
MoveDirectoryContent moves a directory from a source path to its destination by copying the source files or subdirectories recursively to the destination. Once this is done it deletes the files from the original location.
func MoveFile ¶
MoveFile moves a file from a source path to its destination by copying the source file to the destination and then removing it from the original location. This will work between different volumes too.
func OpenFileAsync ¶
func OpenFileAsync(ctx context.Context, fileName string, flag int, perm os.FileMode) (f *os.File, err error)
OpenFileAsync opens a file exiting in case the given context.Context is closed while waiting for the OpenFile to terminate, this can be useful with FIFO files, as Open will not return until the File is not opened with write permissions by another process or goroutine.
func ReadFile ¶
ReadFile reads source file and output the content as bytes. If the file does not exist, it returns an empty string with no error.
func ReadFileLines ¶ added in v1.19.6
ReadFileLines reads source file and output the content as a slice of strings. If the file does not exist, it returns an empty slice with no error.
func RemoveDirectoryContent ¶
RemoveDirectoryContent removes all the files and directories inside the provided path. The directory itself is preserved.
func RemoveFile ¶
RemoveFile removes a specified file. Also works if a directory is empty.
func WriteFileAtomic ¶
WriteFileAtomic atomically replace the content of a file. If the file doesn't exist, it's created. Returns an error status and a flag telling if the file has been changed or not.
func WriteLinesToFile ¶ added in v1.19.6
WriteLinesToFile replace the contents of a certain file with a slice of lines. If the file doesn't exist, it's created. Returns an error status and a flag telling if the file has been changed or not.
func WriteStringToFile ¶
WriteStringToFile replace the contents of a certain file with a string. If the file doesn't exist, it's created. Returns an error status and a flag telling if the file has been changed or not.
Types ¶
This section is empty.
Directories ¶
Path | Synopsis |
---|---|
Package compatibility provides a layer to cross-compile with other OS than Linux
|
Package compatibility provides a layer to cross-compile with other OS than Linux |