fileutils

package
v1.16.0 Latest Latest
Warning

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

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

Documentation

Overview

Package fileutils contains the utility functions about file management

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AppendStringToFile

func AppendStringToFile(targetFile string, content string) (err error)

AppendStringToFile append the content of the given string to the end of the target file prepending new data with a carriage return

func CopyFile

func CopyFile(source, destination string) (err error)

CopyFile copy a file from a location to another one

func CreateEmptyFile

func CreateEmptyFile(fileName string) error

CreateEmptyFile create an empty file or return an error if the file already exist

func EnsureDirectoryExist

func EnsureDirectoryExist(destinationDir string) error

EnsureDirectoryExist check if the passed directory exist or not, and if it doesn't exist will create it using 0700 as permissions bits

func EnsureParentDirectoryExist

func EnsureParentDirectoryExist(fileName string) error

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

func EnsurePgDataPerms(pgData string) error

EnsurePgDataPerms ensure PGDATA has 0700 permissions, which are required for PostgreSQL to successfully startup

func FileExists

func FileExists(fileName string) (bool, error)

FileExists check if a file exists, and return an error otherwise

func GetDirectoryContent

func GetDirectoryContent(dir string) (files []string, err error)

GetDirectoryContent return a slice of string with the name of the files in the dir directory

func GetFileSize

func GetFileSize(fileName string) (int64, error)

GetFileSize returns the size of a file or an error

func MoveFile

func MoveFile(sourcePath, destPath string) (err error)

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

func ReadFile(fileName string) ([]byte, error)

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 RemoveDirectoryContent

func RemoveDirectoryContent(dir string) (err error)

RemoveDirectoryContent removes all the files and directories inside the provided path. The directory itself is preserved.

func RemoveFile

func RemoveFile(fileName string) error

RemoveFile removes a specified file. Also works if a directory is empty.

func WriteFileAtomic

func WriteFileAtomic(fileName string, contents []byte, perm os.FileMode) (bool, error)

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 WriteStringToFile

func WriteStringToFile(fileName string, contents string) (changed bool, err error)

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

Jump to

Keyboard shortcuts

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