fsutil

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultDirPerm os.FileMode = 0755

DefaultDirPerm is the default permission for created directories.

View Source
const DefaultFilePerm os.FileMode = 0644

DefaultFilePerm is the default permission for created files.

Variables

This section is empty.

Functions

func AddIgnoreRules

func AddIgnoreRules(ignoreFilePath string, rules []string) ([]string, error)

AddIgnoreRules appends the given rules to the ignore file, skipping duplicates and preserving existing order. Returns the rules actually added.

func ListIgnoreRules

func ListIgnoreRules(ignoreFilePath string) ([]string, error)

ListIgnoreRules reads the ignore file at path and returns all rules. Returns nil if the file does not exist.

func ReadIgnoreFile

func ReadIgnoreFile(path string) ([]string, error)

ReadIgnoreFile reads an ignore file and returns the active pattern lines. Comments (lines starting with '#') and blank lines are excluded. A UTF-8 BOM at the start of the file is stripped. Returns nil if the file does not exist.

func RemoveIgnoreRule

func RemoveIgnoreRule(ignoreFilePath string, pattern string) error

RemoveIgnoreRule removes the first rule matching the given pattern from the ignore file. Returns an error if the rule is not found.

func Walk

func Walk(root, ignoreFile string, fn func(path string, info os.FileInfo) error) error

Walk walks the file tree rooted at root, invoking fn for every file not excluded by the ignore file. It is equivalent to WalkCtx with context.Background. ignoreFile defaults to ".driftignore" when empty. Symbolic links are not followed (filepath.WalkDir semantics). The .drift directory is always skipped.

func WalkCtx

func WalkCtx(ctx context.Context, root, ignoreFile string, fn func(path string, info os.FileInfo) error) error

WalkCtx is the context-aware variant of Walk. It honors context cancellation: a cancelled context is surfaced before the walk starts and re-checked between entries, causing the walk to stop descending immediately. ignoreFile defaults to ".driftignore" when empty. Symbolic links are not followed, and the .drift directory is always skipped.

Nested ignore files in subdirectories are honored: a .driftignore in a subdirectory adds rules scoped to that subtree, following gitignore semantics. Patterns starting with "!" negate a previous match, and a trailing "/" restricts a pattern to directories only.

func WriteFileAtomic

func WriteFileAtomic(path string, data []byte, perm os.FileMode) error

WriteFileAtomic writes data to path atomically: it writes to a temp file in the same directory, fsyncs and closes it, applies perm, renames it over the target, and fsyncs the parent directory. On any error the temp file is removed and the target is left untouched. The temp file is closed before the rename so the rename succeeds on platforms (e.g. Windows) that reject renaming an open file.

Types

This section is empty.

Jump to

Keyboard shortcuts

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