utils

package
v0.0.0-...-a6598b8 Latest Latest
Warning

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

Go to latest
Published: May 1, 2024 License: Apache-2.0 Imports: 14 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CompareSha

func CompareSha(inputFilename string, shaFilename string) (change bool, newSha []byte, err error)

CompareSha calculates the sha of a input file and compares with a sha stored in a sha file. If the inputFilename does not exist then it reports no change. If shaFilename output does not exist then it reports change.

func ComputeShaFile

func ComputeShaFile(filename string) ([]byte, error)

ComputeShaFile computes the sha256 for the content of a file

func CopyDir

func CopyDir(src string, dst string) (err error)

CopyDir recursively copies a directory tree, attempting to preserve permissions. Source directory must exist, destination directory must *not* exist. Symlinks are ignored and skipped.

func CopyFile

func CopyFile(src, dst string) (err error)

CopyFile copies the contents of the file named src to the file named by dst. The file will be created if it does not already exist. If the destination file exists, all it's contents will be replaced by the contents of the source file. The file mode will be copied from the source and the copied data is synced/flushed to stable storage.

func DirExists

func DirExists(log *base.LogObject, dirname string) bool

DirExists checks directory existence.

func DirSync

func DirSync(dirName string) error

DirSync flushes changes made to a directory.

func FileExists

func FileExists(log *base.LogObject, filename string) bool

FileExists checks file existence.

func MoveDir

func MoveDir(log *base.LogObject, src string, dst string) error

MoveDir recursively move a directory tree, attempting to preserve permissions. if file exists in dst (sub)directory it will be replaced

func ReadSavedCounter

func ReadSavedCounter(log *base.LogObject, fileName string) (uint32, bool)

ReadSavedCounter returns counter value from provided file If the file doesn't exist or doesn't contain an integer it returns false

func ReadWithMaxSize

func ReadWithMaxSize(log *base.LogObject, filename string, maxReadSize int) ([]byte, error)

ReadWithMaxSize returns the content but limits the size to maxReadSize and truncates if longer

func SaveShaInFile

func SaveShaInFile(filename string, sha []byte) error

SaveShaInFile saves the value to use used by future CompareSha calls.

func StatAndRead

func StatAndRead(log *base.LogObject, filename string, maxReadSize int) (string, time.Time, error)

StatAndRead returns the content and Modtime We limit the size we read maxReadSize and truncate if longer

func Writable

func Writable(dir string) bool

Writable checks if the directory is writable

func WriteRename

func WriteRename(fileName string, b []byte) error

WriteRename write data to a fmpfile and then rename it to a desired name

func WriteRenameWithBackup

func WriteRenameWithBackup(fileName string, b []byte) error

WriteRenameWithBackup : just like WriteRename but additionally it creates a backup of the original file at the same path but with the ".bak" extension added.

Types

This section is empty.

Jump to

Keyboard shortcuts

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