Documentation
¶
Index ¶
- Constants
- Variables
- func ByteSizeStr(sz uint64) string
- func CheckDirExists(path string) (bool, error)
- func CheckFileExists(path string) (bool, error)
- func DirExists(path string) bool
- func FileContentMatch(fn string, data []byte) (bool, error)
- func FileExists(path string) bool
- func JoinPathList(paths ...string) string
- func NormalizePathsToSlash(paths []string) []string
- func ReadJSONFile(fn string, v interface{}) error
- func ResolvesToSameFile(pathA, pathB string) bool
- func SearchDir(dir dirname, accept func(os.FileInfo) bool) []filename
- func SearchFilesAndSymlinks(dirs []string, accept func(os.FileInfo) bool) map[filename][]symlink
- func ValidateDirExists(path string) error
- func ValidateEmptyDirExists(path string) error
- func ValidateFileExists(path string) error
- func ValidateNoDirExists(path string) error
- func ValidateNoFileExists(path string) error
- func ValidateNoPathExists(path string) error
- func ValidatePathExists(path string) error
- func ValidatePathIsAbsolute(path string) error
- func ValidatePathIsNotAbsolute(path string) error
- func WriteFile(fn string, buf []byte, opts *WriteOptions) error
- func WriteFileIfChanged(fn string, data []byte) (err error)deprecated
- type BackupNameGenerator
- type FileEntriesWithErrors
- type WriteFeedback
- type WriteFeedbackProc
- type WriteFileEntry
- type WriteFileStatus
- type WriteFileset
- func (v *WriteFileset) Add(descr string, fn string, payload *bytes.Buffer) *WriteFileEntry
- func (v WriteFileset) Count(status WriteFileStatus) int
- func (v WriteFileset) CountPending() int
- func (v WriteFileset) Errors() error
- func (v WriteFileset) UpdateStatus() error
- func (v WriteFileset) WritePending() error
- func (v WriteFileset) WriteTagged(tags ...string) error
- type WriteOptions
Constants ¶
const ( FeedbackWriteBegin = WriteFeedback(iota) FeedbackWriteSucceded FeedbackWriteFailed FeedbackWriteSkipped FeedbackBackupBegin FeedbackBackupSucceded FeedbackBackupFailed FeedbackBackupRestoreFailed )
const ( StatErr = WriteFileStatus(iota) Unchanged Creating Overwriting Failed Skipped Succeeded )
Variables ¶
var ( ErrFileNotDir = errors.New("a file is located at the expected directory location") ErrDirNotFile = errors.New("a directory is located at the expected file location") ErrFileDoesNotExist = os.ErrNotExist ErrDirDoesNotExist = errors.New("directory does not exist") ErrDirIsNotEmpty = errors.New("directory is not empty") ErrPathDoesNotExist = errors.New("path does not exist") ErrFileExists = os.ErrExist ErrDirExists = errors.New("directory already exists") ErrPathIsNotAbsolute = errors.New("path is not absolute") ErrPathIsAbsolute = errors.New("path is absolute") )
Error Codes
Functions ¶
func ByteSizeStr ¶
func CheckDirExists ¶
func CheckFileExists ¶
func DirExists ¶
DirExists returns true if a directory exists at the specified location. If the path points to a file, this function returns false.
func FileContentMatch ¶ added in v0.6.0
FileContentMatch checks if the file has content that matches the specified data.
func FileExists ¶
FileExists returns true if a file exists at the specified location. If the path points to a directory, this function returns false.
func JoinPathList ¶
JoinPathList joins multiple paths into a string with OS-specific path separator. This is an opposite of the GOLANG's filepath.SplitList() function.
func NormalizePathsToSlash ¶
NormalizePathsToSlash normalizes a list of file paths: - removes empty paths - converts separators to slashes - removes duplicates - sorts lexicographically
func ReadJSONFile ¶ added in v0.6.0
ReadJSONFile is a version of json.Unmarshal that reads content from a file and ammends returned errors with location information (file:col:row)
func ResolvesToSameFile ¶
ResolvesToSameFile returns true if the two paths resolve to the same actual file. Follows symlinks.
func SearchDir ¶
SearchDir returns the list of paths within the specified directory that pass through the 'accept' callback. This is a non-recursive search.
func SearchFilesAndSymlinks ¶
SearchFilesAndSymlinks scans the provided set of directories and returns absolute filenames that pass through a functional 'accept' filter.
While searching, symlinks are resolved. For symlinks, the 'accept' is called twice: first on a symlink itself, then on its target.
Returns a map of real absolute file paths and symlinks pointing to those files.
func ValidateDirExists ¶
func ValidateEmptyDirExists ¶
func ValidateFileExists ¶
func ValidateNoDirExists ¶ added in v0.5.0
func ValidateNoFileExists ¶ added in v0.5.0
func ValidateNoPathExists ¶ added in v0.5.0
func ValidatePathExists ¶ added in v0.5.0
func ValidatePathIsAbsolute ¶ added in v0.5.0
func ValidatePathIsNotAbsolute ¶ added in v0.5.0
func WriteFile ¶ added in v0.6.0
func WriteFile(fn string, buf []byte, opts *WriteOptions) error
WriteFile writes data to the named file with configurable behavior and feedback.
func WriteFileIfChanged
deprecated
Types ¶
type BackupNameGenerator ¶ added in v0.6.0
func BackupNameNumeric ¶ added in v0.6.0
func BackupNameNumeric(suffix string, max_attempts int) BackupNameGenerator
BackupNameNumeric produces a backup name generator that injects a numbered suffix into the original filename:
- first backup: file<suffix>.ext
- n-th backup: file<suffix>_n.ext
- stops after max_attempts if generated filenames are already claimed by existing files
func BackupNameTimestamp ¶ added in v0.6.0
func BackupNameTimestamp(suffix string, timestamp_format string, max_attempts int) BackupNameGenerator
BackupNameTimestamp produces a backup name generator that injects a timestamp suffix into the original filename:
- naming pattern: file<suffix>timestamp.ext
- uses time.Now().Format(timestamp_format)
- stops after max_attempts if generated filenames are already claimed by existing files
type FileEntriesWithErrors ¶ added in v0.8.0
type FileEntriesWithErrors []*WriteFileEntry
func (FileEntriesWithErrors) Error ¶ added in v0.8.0
func (e FileEntriesWithErrors) Error() string
type WriteFeedback ¶ added in v0.6.0
type WriteFeedback int
type WriteFeedbackProc ¶ added in v0.6.0
type WriteFeedbackProc = func(fb WriteFeedback, fn string)
func MakeWriteFileFeedback ¶ added in v0.8.0
func MakeWriteFileFeedback(w io.Writer) WriteFeedbackProc
MakeWriteFileFeedback is a feedback example (use with os.Stdout or os.Stderr).
type WriteFileEntry ¶ added in v0.8.0
type WriteFileEntry struct { Descr string FilePath string Payload *bytes.Buffer Perm os.FileMode Backup BackupNameGenerator Tag string // contains filtered or unexported fields }
WriteFileEntry is an entry in WriteFileSet.
func NewWriteFileEntry ¶ added in v0.8.0
func NewWriteFileEntry(descr string, fn string, payload *bytes.Buffer) *WriteFileEntry
func (*WriteFileEntry) LastError ¶ added in v0.8.0
func (en *WriteFileEntry) LastError() error
func (*WriteFileEntry) Status ¶ added in v0.8.0
func (en *WriteFileEntry) Status() WriteFileStatus
func (*WriteFileEntry) UpdateStatus ¶ added in v0.8.0
func (en *WriteFileEntry) UpdateStatus()
type WriteFileStatus ¶ added in v0.8.0
type WriteFileStatus = int
func WriteFileEx ¶ added in v0.8.0
func WriteFileEx(fn string, buf []byte, opts *WriteOptions) (status WriteFileStatus, err error)
WriteFileEx writes data to the named file with configurable behavior and feedback, provides detailed status.
type WriteFileset ¶ added in v0.8.0
type WriteFileset struct { Entries []*WriteFileEntry OnFeedback WriteFeedbackProc }
WriteFileset bundles multiple pending file write operations together.
func (*WriteFileset) Add ¶ added in v0.8.0
func (v *WriteFileset) Add(descr string, fn string, payload *bytes.Buffer) *WriteFileEntry
Add adds new entry into the set.
func (WriteFileset) Count ¶ added in v0.8.0
func (v WriteFileset) Count(status WriteFileStatus) int
Count counts the entries with have the specified status value.
func (WriteFileset) CountPending ¶ added in v0.8.0
func (v WriteFileset) CountPending() int
CountPending counts the entries that are still pending for write operation.
func (WriteFileset) Errors ¶ added in v0.8.0
func (v WriteFileset) Errors() error
func (WriteFileset) UpdateStatus ¶ added in v0.8.0
func (v WriteFileset) UpdateStatus() error
UpdateStatus updates pending overwrite status for all entries in the set.
func (WriteFileset) WritePending ¶ added in v0.8.0
func (v WriteFileset) WritePending() error
WritePending writes out all pending entries.
func (WriteFileset) WriteTagged ¶ added in v0.8.0
func (v WriteFileset) WriteTagged(tags ...string) error
WriteTagged writes out pending entries that have matching tags.
type WriteOptions ¶ added in v0.6.0
type WriteOptions struct { Perm os.FileMode // file writing permissions, defaults to 0666 if unspecidied (perm == 0) OverwriteMatchingContent bool // backup and overwrite, even if content matches Backup BackupNameGenerator // backup filename generator, no backup by default OnFeedback WriteFeedbackProc // use this if logging or user feedback is required }
WriteOptions provides detailed configuration for tuning WriteFile behavior.