files

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: May 6, 2025 License: MPL-2.0 Imports: 12 Imported by: 55

Documentation

Index

Constants

View Source
const (
	// Files lists only files
	Files ListFlag = 1 << iota
	// Directories lists only directories
	Directories
	// Recursively traverses directories
	Recursive
	// Ignores empty directories
	NotEmpty
	AllFlat              = Files | Directories
	AllRecursive         = Files | Directories | Recursive
	FilesRecursive       = Files | Recursive
	DirectoriesRecursive = Directories | Recursive
	FilesFlat            = Files
	DirectoriesFlat      = Directories
)

Variables

This section is empty.

Functions

func DirectoryExists added in v0.5.0

func DirectoryExists(dirname string) bool

func FileExists added in v0.5.0

func FileExists(filename string) bool

FileExists checks if a file exists and is not a directory

func GetULimit added in v0.3.0

func GetULimit() (syscall.Rlimit, error)

func GlobRoot added in v0.5.0

func GlobRoot(glob string) (string, string, error)

GlobRoot takes in a glob and tries to resolve the prefix of the glob such that the prefix exists in the filesystem.

If the given glob is relative, then GlobRoot converts it into an absolute path before attempting resolution.

If the given glob is can be resolved to an existing file in the system, then the parent directory of the file along with the full path of the file is returned

func InclusionsFromExtensions

func InclusionsFromExtensions(extensions []string) []string

InclusionsFromExtensions takes a list of file extensions and convert into a .gitgnore format inclusions list

func InclusionsFromFiles

func InclusionsFromFiles(filenames []string) []string

InclusionsFromFiles takes a list of file names convert into a .gitgnore format inclusions list

func ListFiles

func ListFiles(listPath string, opts *ListOptions) ([]string, error)

ListFiles returns path of files and or folders under listPath inclusions/exclusions/recursion is defined by opts

func ListFilesWithContext added in v0.9.0

func ListFilesWithContext(ctx context.Context, listPath string, opts *ListOptions) ([]string, error)

func Match added in v0.5.0

func Match(pattern, value string, options ...MatchOption) bool

func ResolveGlobRoots added in v0.5.0

func ResolveGlobRoots(pattern []string, rootPaths ...string) []string

ResolveGlobRoots resolve the glob patter for each of the given root paths

func SetULimit added in v0.3.0

func SetULimit(ulimit uint64) error

func ShouldIncludePath

func ShouldIncludePath(path string, include, exclude []string) bool

ShouldIncludePath returns whether the specified file path satisfies the inclusion and exclusion options (in .gitignore format) Note: it is expected the pattern will be absolute, i.e including the base path: /tmp/foo/**/*.json

func SplitPath added in v0.5.0

func SplitPath(path string) []string

SplitPath splits the given path using the os.PathSeparator

func Tildefy added in v0.5.0

func Tildefy(filePath string) (string, error)

Tildefy converts ~ to home directory

Types

type ListFlag

type ListFlag uint

type ListOptions

type ListOptions struct {
	// .gitignore (fnmatch) format patterns for file inclusions and exclusions
	Include []string
	Exclude []string
	Flags   ListFlag
	// max results
	MaxResults int
}

type MatchOption added in v0.6.0

type MatchOption func(config *matchConfig)
var WithAsDir MatchOption = func(config *matchConfig) {
	config.asDir = true
}

Jump to

Keyboard shortcuts

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