fileutils

package
v2.4.3 Latest Latest
Warning

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

Go to latest
Published: Sep 6, 2024 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateNewFileFromFilename

func CreateNewFileFromFilename(fileName string) (*os.File, error)

CreateNewFileFromFilename given a file name, this creates a new file on-disk for writing logs.

func CreateUniqueFileName

func CreateUniqueFileName(
	targetDir, identifier, fileExtension string,
	attempt int,
) string

CreateUniqueFileName creates a new unused filename at the target directory. targetDir: the directory to create the file in. identifier: the base name of the file. fileExtension: the file extension suffix. attempt: the current attempt number, to prevent infinite loops.

func DirExistsOrCreate

func DirExistsOrCreate(dir string) error

DirExistsOrCreate checks if a directory exists, and creates it if it doesn't

func FileExists

func FileExists(fileName string) bool

FileExists returns true if the file exists

func IsValidFilePathFormat

func IsValidFilePathFormat(path string) bool

IsValidFilePathFormat checks if the given string is formatted like a file path.

func NewFileWatcher

func NewFileWatcher(logger *slog.Logger, watchDir string) (*fsnotify.Watcher, error)

NewFileWatcher creates a new fsnotify.Watcher and adds the specified directory to it.

Example usage:

watch, err := NewFileWatcher(dirName)
if err != nil {
    log.Fatal(err)
}

err = WaitForFile(watch, time.Second*5) // err is set if timeout was reached
if err != nil {
    log.Fatal(err)
}

func RelocateExistingFileIfExists

func RelocateExistingFileIfExists(fileName string) error

RelocateExistingFileIfExists checks if a file exists, and if it does, renames it to a unique name

func WaitForFile

func WaitForFile(logger *slog.Logger, watcher *fsnotify.Watcher, timeout time.Duration) error

WaitForFile waits for a file event to occur in the watcher

Types

This section is empty.

Jump to

Keyboard shortcuts

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