pathtools

package
v0.11.4 Latest Latest
Warning

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

Go to latest
Published: Jan 24, 2021 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	FollowSymlinks     = ShouldFollowSymlinks(true)
	DontFollowSymlinks = ShouldFollowSymlinks(false)
)

Variables

View Source
var GlobInvalidRecursiveErr = errors.New("pattern contains other characters between '**' and path separator")
View Source
var GlobLastRecursiveErr = errors.New("pattern has '**' as last path element")
View Source
var GlobMultipleRecursiveErr = errors.New("pattern contains multiple '**'")

Functions

func Glob

func Glob(pattern string, excludes []string, follow ShouldFollowSymlinks) (matches, deps []string, err error)

Glob returns the list of files and directories that match the given pattern but do not match the given exclude patterns, along with the list of directories and other dependencies that were searched to construct the file list. The supported glob and exclude patterns are equivalent to filepath.Glob, with an extension that recursive glob (** matching zero or more complete path entries) is supported. Any directories in the matches list will have a '/' suffix.

In general ModuleContext.GlobWithDeps or SingletonContext.GlobWithDeps should be used instead, as they will automatically set up dependencies to rerun the primary builder when the list of matching files changes.

func GlobPatternList

func GlobPatternList(patterns []string, prefix string) (globedList []string, depDirs []string, err error)

func GlobWithDepFile

func GlobWithDepFile(glob, fileListFile, depFile string, excludes []string) (files []string, err error)

GlobWithDepFile finds all files and directories that match glob. Directories will have a trailing '/'. It compares the list of matches against the contents of fileListFile, and rewrites fileListFile if it has changed. It also writes all of the the directories it traversed as dependencies on fileListFile to depFile.

The format of glob is either path/*.ext for a single directory glob, or path/**/*.ext for a recursive glob.

Returns a list of file paths, and an error.

In general ModuleContext.GlobWithDeps or SingletonContext.GlobWithDeps should be used instead, as they will automatically set up dependencies to rerun the primary builder when the list of matching files changes.

func HasGlob

func HasGlob(in []string) bool

HasGlob returns true if any string in the list contains any glob characters (*, ?, or [).

func IsGlob

func IsGlob(pattern string) bool

IsGlob returns true if the pattern contains any glob characters (*, ?, or [).

func Match

func Match(pattern, name string) (bool, error)

Match returns true if name matches pattern using the same rules as filepath.Match, but supporting recursive globs (**).

func MatchEscape

func MatchEscape(s string) string

MatchEscape returns its inputs with characters that would be interpreted by

func PrefixPaths

func PrefixPaths(paths []string, prefix string) []string

PrefixPaths returns a list of paths consisting of prefix joined with each element of paths. The resulting paths are "clean" in the filepath.Clean sense.

func ReplaceExtension

func ReplaceExtension(path string, extension string) string

func ReplaceExtensions

func ReplaceExtensions(paths []string, extension string) []string

func WriteFileIfChanged

func WriteFileIfChanged(filename string, data []byte, perm os.FileMode) error

WriteFileIfChanged wraps ioutil.WriteFile, but only writes the file if the files does not already exist with identical contents. This can be used along with ninja restat rules to skip rebuilding downstream rules if no changes were made by a rule.

Types

type FileSystem

type FileSystem interface {
	// Open opens a file for reading.  Follows symlinks.
	Open(name string) (ReaderAtSeekerCloser, error)

	// Exists returns whether the file exists and whether it is a directory.  Follows symlinks.
	Exists(name string) (bool, bool, error)

	Glob(pattern string, excludes []string, follow ShouldFollowSymlinks) (matches, dirs []string, err error)

	// IsDir returns true if the path points to a directory, false it it points to a file.  Follows symlinks.
	// Returns os.ErrNotExist if the path does not exist or is a symlink to a path that does not exist.
	IsDir(name string) (bool, error)

	// IsSymlink returns true if the path points to a symlink, even if that symlink points to a path that does
	// not exist.  Returns os.ErrNotExist if the path does not exist.
	IsSymlink(name string) (bool, error)

	// Lstat returns info on a file without following symlinks.
	Lstat(name string) (os.FileInfo, error)

	// Lstat returns info on a file.
	Stat(name string) (os.FileInfo, error)

	// ListDirsRecursive returns a list of all the directories in a path, following symlinks if requested.
	ListDirsRecursive(name string, follow ShouldFollowSymlinks) (dirs []string, err error)

	// ReadDirNames returns a list of everything in a directory.
	ReadDirNames(name string) ([]string, error)

	// Readlink returns the destination of the named symbolic link.
	Readlink(name string) (string, error)
	// contains filtered or unexported methods
}
var OsFs FileSystem = &osFs{}

func MockFs

func MockFs(files map[string][]byte) FileSystem

func NewOsFs

func NewOsFs(path string) FileSystem

type ReaderAtSeekerCloser

type ReaderAtSeekerCloser interface {
	io.Reader
	io.ReaderAt
	io.Seeker
	io.Closer
}
type ShouldFollowSymlinks bool

Jump to

Keyboard shortcuts

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