fs

package
v0.26.0 Latest Latest
Warning

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

Go to latest
Published: Jun 28, 2025 License: MIT Imports: 16 Imported by: 16

Documentation

Index

Constants

View Source
const (
	DefaultPermissionsDir  = os.FileMode(0775)
	DefaultPermissionsFile = os.FileMode(0664)
	StrictPermissionsFile  = os.FileMode(0600)
)
View Source
const (
	OutputDir = ".output"

	// Relative paths to `OutputDir`.
	OutBuildDir      = "build"
	OutBuildBinDir   = "build/bin"
	OutBuildShareDir = "build/share"
	OutBuildDocsDir  = "build/docs"

	OutPackageDir = "package"

	OutCoverageDir     = "coverage"
	OutCoverageDataDir = "coverage/data"
	OutCoverageBinDir  = "coverage/bin"

	OutImageDir = OutPackageDir

	DocsDir   = "docs"
	ImagesDir = "images"
)

These constants define general directories used throughout the repository.

Variables

This section is empty.

Functions

func AssertDirs

func AssertDirs(paths ...string)

AssertDirs asserts that `path` exists, otherwise panics.

func CopyFileOrDir

func CopyFileOrDir(src string, dest string, existsOk bool) (err error)

CopyFileOrDir copies a directory or file from `src` to `dest`. If `existsOk` is `true` it will replace `dest` if it exists. Copies also symlinks.

func Exists

func Exists(path string) (exists bool)

Exists checks if a path exists. Follows symlinks.

func ExistsE

func ExistsE(path string) (bool, error)

ExistsE checks if a path exists and returns any error associated with `os.Stat`. It follows symlinks.

func ExistsL

func ExistsL(path string) (exists bool)

ExistsL checks if a path exists. It does not follow symlink.

func ExistsLE

func ExistsLE(path string) (bool, error)

ExistsLE checks if a path exists and returns any error associated with `os.Stat`. It does not follow symlinks.

func FindFiles

func FindFiles(
	rootDir string,
	opts ...FindOptions,
) (files []string, traversedFiles int64, err error)

Find all files in `rootDir`. Note: Take care when using WithPathFilter or WithPathFilterPatterns because they will influence how the files are walked. This function uses goroutines under to hood.

func FindFilesByPatterns added in v0.24.0

func FindFilesByPatterns(
	rootDir string,
	includeGlobPatterns []string,
	excludeGlobPatterns []string,
	opts ...FindOptions,
) (files []string, traversedFiles int64, err error)

Find all files in `rootDir` which match glob patterns `includePatterns` and not `excludePatterns` (they match the full path). This function uses goroutines under to hood.

func FindPaths added in v0.24.0

func FindPaths(
	rootDir string,
	opts ...FindOptions,
) (files []string, traversedFiles int64, err error)

Find all paths in `rootDir`. Note: Take care when using WithPathFilter or WithPathFilterPatterns because they will influence how the files are walked. This function uses goroutines under to hood.

func IgnoredDirectoriesDefault

func IgnoredDirectoriesDefault() []string

DefaultIgnoredDirectories returns all by default ignored directories.

func IsExecutable

func IsExecutable(path string) bool

IsExecutable checks if the `path` is executable.

func MakeAbsolute

func MakeAbsolute(p string) string

MakeAbsolute makes path `p` absolute to the current working directory.

func MakeAbsoluteTo

func MakeAbsoluteTo(base string, p string) string

MakeAbsoluteTo makes a path absolute to the `base` directory.

func MakeAllAbsolute

func MakeAllAbsolute(p ...string) []string

MakeAllAbsolute makes all paths absolute to the current working directory. This function works inplace!

func MakeAllAbsoluteTo

func MakeAllAbsoluteTo(base string, p ...string) []string

MakeAllAbsoluteTo makes all paths absolute to the `base` directory. This function works inplace!

func MakeRelativeTo added in v0.26.0

func MakeRelativeTo(base string, path string) (s string, e error)

MakeRelativeTo makes a `path` relative to `base`.

func MatchByPatterns

func MatchByPatterns(s string, includeGlobs, excludeGlobs []string) bool

Match a string `name` by some include and exclude glob patterns (doublestar allowed). All errors of `doublestar.ErrBadPattern` will be ignored for performance reason. If `includeGlobs` is empty, it acts as `*` include all.

func MkDirs

func MkDirs(paths ...string) (err error)

MkDirs creates all directories in `path`.

Types

type FindOptions added in v0.24.0

type FindOptions func(opts *queryOptions) error

Options to pass to various query function.

func WithPathFilter

func WithPathFilter(f PathFilter, useAnd bool) FindOptions

WithPathFilter set a custom path filter.

func WithPathFilterPatterns added in v0.26.0

func WithPathFilterPatterns(include []string, exclude []string, useAnd bool) FindOptions

WithPathFilterPatterns sets the doublestar glob patterns path filter on discovered paths.

`useAnd` will logically and this filter to a default one if set.

func WithReportOnlyDirs added in v0.26.0

func WithReportOnlyDirs(enable bool) FindOptions

WithReportOnlyDirs sets to only walk directories (no files) which means any matching filters are done on directory paths only.

func WithWalkDirFilter added in v0.26.0

func WithWalkDirFilter(f PathFilter, useAnd bool) FindOptions

WithWalkDirFilter sets a custom walk filter to determine which directories to skip.

func WithWalkDirFilterDefault added in v0.26.0

func WithWalkDirFilterDefault(useAnd bool) FindOptions

WithWalkDirFilterDefault sets the default walk directory filter if non it set. Note: This is not the same as the `[WithPathFilter]` counter part as it determines the discovery of files when walking the tree. `useAnd` will logically and this filter to a default one if set.

func WithWalkDirFilterPatterns added in v0.26.0

func WithWalkDirFilterPatterns(include []string, exclude []string, useAnd bool) FindOptions

WithWalkDirFilterPatterns sets doublestar glob patterns to skip directories when walking over the filesystem.

type PathFilter added in v0.24.0

type PathFilter func(path string, info os.DirEntry) bool

PathFilter is the filter which returns true for directories to recurse into when querying.

Jump to

Keyboard shortcuts

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