fileutils

package
v0.19.14 Latest Latest
Warning

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

Go to latest
Published: Dec 10, 2025 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CleanDirectory added in v0.10.0

func CleanDirectory(dirPath string) error

CleanDirectory removes all files and subdirectories within dirPath, leaving the directory itself intact.

func CompareDirectories added in v0.10.0

func CompareDirectories(dir1, dir2 string) (bool, error)

CompareDirectories checks if two directories have the same structure and content. Walks both folders and ensures the contents are identical (compares file hashes).

func CompareDirectoriesHasher added in v0.10.4

func CompareDirectoriesHasher(dir1, dir2 string, h hash.Hash) (bool, error)

CompareDirectoriesHasher checks if two directories have the same structure and content. Walks both folders and ensures the contents are identical (compares file hashes).

func ExistsAndIsDirectory

func ExistsAndIsDirectory(path string) (exists, isDir bool, err error)

func ReadOrPanic

func ReadOrPanic(p string) []byte

ReadOrPanic reads the entire file at the provided path or panics if it is not possible.

func ReplaceDirectory added in v0.10.0

func ReplaceDirectory(currentPath, targetPath string) error

ReplaceDirectory atomically replaces the directory at targetPath with the directory at currentPath. It removes any existing directory at currentPath and uses a unique lock file based on targetPath.

func ReplaceFile added in v0.10.0

func ReplaceFile(currentPath, targetPath string) error

ReplaceFile atomically replaces the file at targetPath with the file at currentPath, using a unique lock file based on targetPath.

func SafeReadFile

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

SafeReadFile reads the file at the provided path into a byte slice.

func SafeReadYAML

func SafeReadYAML(filePath string, targetPointer any, perm os.FileMode) (yamlAvailable bool, err error)

SafeReadYAML reads the YAML file at the path into the targetPointer. Returns true if the file exists or an error if an error occurred.

Types

type LockedFile added in v0.16.3

type LockedFile struct {
	// contains filtered or unexported fields
}

LockedFile wraps an *os.File and a file lock using gofrs/flock.

func OpenLockedFile added in v0.16.3

func OpenLockedFile(path string, flag int, perm os.FileMode) (*LockedFile, error)

OpenLockedFile opens the file with the specified flags and permissions, acquires an exclusive lock (blocking until it can be obtained), and returns a LockedFile. The lock file is created by appending ".lock" to the filename.

func (*LockedFile) Close added in v0.16.3

func (lf *LockedFile) Close() error

Close releases the lock and then closes the underlying file.

func (*LockedFile) Read added in v0.16.3

func (lf *LockedFile) Read(p []byte) (int, error)

func (*LockedFile) Stat added in v0.16.3

func (lf *LockedFile) Stat() (os.FileInfo, error)

Stat returns file metadata by delegating to the underlying os.File.

func (*LockedFile) Write added in v0.16.3

func (lf *LockedFile) Write(p []byte) (int, error)

Jump to

Keyboard shortcuts

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