fs

package
v0.0.0-...-4b9bf86 Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2020 License: MIT Imports: 4 Imported by: 1

README

Package fs

Package fs represents the constituents of a file system and provides type safe access.

Beyond a couple of convenience functions, it provides a tree of types and related functionalities.

The Type Tree

  • fsPath is just a string, and provides many basic functionalities (also from standard packages "path/filepath", "os", "io/ioutil").
    • fsInfo extends fsPath with an os.FileInfo and more functionalities and thus includes some 'reality check'.

      • FsFold extends fsInfo and represents the name of a folder / directory
      • FsFile extends fsInfo and represents the name of a file
        • FsData extends FsFile and represents the name and data of a file (used e.g. in "FsCache")
    • FsBase extends fsPath and represents a base name (no slashes)

    • Pattern extends fsPath and represents a pattern (may contain wildcards)

A Friendly Package

fs aims to be a friendly package.

Intentionally it provides a lot of functionalitites and methods.

Sometimes the full sorted lists given by tools such as godoc or go doc may be more confusing than helpful.

For better overview there is a tree of interfaces where each node summarises related methods.

Concurrency safe

As all types are intentionally immutable and thus safe in concurrent use.

The TypeS collections

For each type (incl. non-exported!) there is a corresponding container type suffixed with ...S, which is just a typesslice (thus the Uppercase "S": for both: plural, and slice) of typepointers, e.g. FsInfoS = []*fsInfo.

Such collections are provided / accepted by functions, and can easily be passed around as arguments or iterated over.

Creators and derivators

"New" as a prefix for creator functions is intentionally not used; "Force" is offered instead.

ForceFile, ForceFold (and NotDown and Recurse), ForceBase, ForceData are intentionally tolerant. They perform no reality check whatshowever but allow the user to express his intentions. Thus, they are to be used with good care, if at all.

The f.As<Type> methods are a safer way to create/derive related types.

Various corresponding Try<Type> methods even give access to eventual 'reality check' failures; in order to avoid panics, they should be used before any f.As<Type> .

Note: NewS is an exception - it creates an FsPathS, a collections of unqualified fsPathS.

Matching / Patterns

The type Pattern extends fsPath and represents a pattern, which may contain wildchars such as "*" & "?".

Patterns are supported in various ways:

  • Match is a convenience for filepath.Match and accepts variadic lists
  • MatchDisk and friends implicitly interpret the given string / fsPath as such, as internally a Glob against the disk is used.
  • A couple of Matches methods accept patterns and even lists of patterns.

Note: Currently, standard package "path/filepath" does not export it's isMeta function, which is useful for checking. Thus, duplication of knowledge would be required - and this is very much disliked.

Documentation

Overview

Package fs represents the constituents of a file system and provides type safe access.

See enclosed ReadMe.md for a conceptual overview and further details.

Index

Constants

View Source
const (

	// MatchAny matches any sequence of non-Separator characters
	MatchAny = `*`

	// MatchOne matches any single non-Separator character
	MatchOne = `?`

	// Dot is the extension separator - a period.
	Dot = `.`
)
View Source
const (
	// ListSep is the os.PathListSeparator
	ListSep = os.PathListSeparator
)
View Source
const (
	// Tab is the horizontal tabulation character/rune
	Tab = "\t"
)

Variables

View Source
var Perm os.FileMode = 0644 // default os.FileMode

Perm defaults to '0644' as os.FileMode

Functions

func Match

func Match(name string, patterns ...*Pattern) (matched bool, err error)

Match reports whether name matches any of the shell file name pattern lists.

Note: any name matches an empty patternlist and any empty pattern!

func MatchDisk

func MatchDisk(name string) (dirS FsFoldS, filS FsFileS, err error)

MatchDisk uses filepath.Glob and returns all entries matching the pattern, separated into directories and files, as slices of FsPath, and eventual encountered errors, which can only be ErrBadPattern or PathError

Types

type BaseFriendly

type BaseFriendly interface {
	PathFriendly
}

BaseFriendly summarises methods of type FsBase

Note: this interface is exposed not only for godoc ;-)

type DataFriendly

type DataFriendly interface {
	InfoFriendly

	ByteS() []byte
	Data() string
}

DataFriendly summarises methods of type FsData

Note: this interface is exposed not only for godoc ;-)

type DiskFriendly

type DiskFriendly interface {
	Glob() (matches []string, err error)
	MatchDisk() (dirS FsFoldS, filS FsFileS, err error)
}

DiskFriendly summarises methods related to "what's on the disk" reality checks

Note: this interface is exposed not only for godoc ;-)

type Errors

type Errors struct {
	// contains filtered or unexported fields
}

Errors is a slice of error

func (Errors) Error

func (er Errors) Error() string

Error returns a Tab-terminated string listing the accumulated errors (the string is suitable for text\tabwriter; if there are no errors, a single Tab is returned - an empty Tab-terminated string)

type FileFriendly

type FileFriendly interface {
	InfoFriendly
	// File Create/Open
	Create() (*os.File, error)
	Open() (*os.File, error)
	// File Read/Write
	ReadFile() ([]byte, error)
	WriteFile(byteS []byte) error
}

FileFriendly summarises methods of type FsFile

Note: this interface is exposed not only for godoc ;-)

type FilePathFriendly

type FilePathFriendly interface {
	String() string

	Base() *FsBase
	Ext() *FsBase
	BaseLessExt() *FsBase
	Split() (dir, file string)
	SplitList() []string
	JoinWith(elem ...string) string
}

FilePathFriendly summarises methods related to file path strings

Note: this interface is exposed not only for godoc ;-)

type FoldFriendly

type FoldFriendly interface {
	InfoFriendly
	MkDir() error
	ReadDir() ([]os.FileInfo, error)

	Recurse() bool
	HasRecurse() bool

	TabString() string

	FileS(patterns ...*Pattern) (FilS FsFileS)
	ReadDirS() (entrieS FsInfoS, err error)
	SubDirS() (DirS []*FsFold)
}

FoldFriendly summarises methods of type FsFold

Note: this interface is exposed not only for godoc ;-)

type FsBase

type FsBase struct {
	// contains filtered or unexported fields
}

FsBase represents a basename of the file system.

Note: FsBase is immutable, and as such safe for concurrent use.

func Base

func Base(name string) *FsBase

Base is a typesafe convenience for filepath.Base()

func BaseLessExt

func BaseLessExt(name string) *FsBase

BaseLessExt returns name.Base() less name.Ext() as *FsBase

func Ext

func Ext(name string) *FsBase

Ext is a typesafe convenience for filepath.Ext()

func ForceBase

func ForceBase(name string) *FsBase

ForceBase returns a fresh FsBase representing the Base(name) of the given a name.

func (*FsBase) Accessible

func (p *FsBase) Accessible() error

Accessible - returns nil, or the error received from os.Open (or Close)

func (*FsBase) AsBase

func (p *FsBase) AsBase() *FsBase

AsBase returns a fresh FsBase for the given FsInfo, or panics, if path is not identical to it's own Base(name).

func (*FsBase) AsInfo

func (p *FsBase) AsInfo() *fsInfo

AsInfo returns a fresh FsInfo, and the error received from os.Stat() (if any), or panics, if TryInfo returns an error (from os.Stat()).

func (*FsBase) AsPath

func (p *FsBase) AsPath() *fsPath

AsPath returns (a pointer to) the underlying fsPath or panics, if TryPath detected some invlaid content.

Note: AsPath exists only for symmetry with respect to the other, higher types.

func (*FsBase) AsPattern

func (p *FsBase) AsPattern() *Pattern

AsPattern returns a fresh Pattern for the given fsPath, or panics, if TryPattern returns an error (ErrBadPattern).

func (*FsBase) Base

func (p *FsBase) Base() *FsBase

Base returns the last element of path. Trailing path separators are removed before extracting the last element. If the path is empty, Base returns ".". If the path consists entirely of separators, Base returns a single separator.

func (*FsBase) BaseLessExt

func (p *FsBase) BaseLessExt() *FsBase

BaseLessExt: name.Base() less name.Ext()

func (*FsBase) BaseMatches

func (p *FsBase) BaseMatches(patterns ...*Pattern) (matched bool, err error)

BaseMatches reports whether base name of fsPath matches any of the patterns.

func (*FsBase) Exists

func (p *FsBase) Exists() (bool, error)

Exists returns whether the given file or directory exists or not from http://stackoverflow.com/a/10510783

func (*FsBase) Ext

func (p *FsBase) Ext() *FsBase

Ext returns the file name extension used by path. The extension is the suffix beginning at the final dot in the final element of path; it is empty if there is no dot.

func (*FsBase) Glob

func (p *FsBase) Glob() (matches []string, err error)

Glob returns the names of all files matching the pattern (=PathText()), or nil if there is no matching entry(file/directory).

Note. The pattern may describe hierarchical names such as
/usr/*/bin/ed (assuming the Separator is '/').

Glob ignores file system errors such as I/O errors reading directories. The only possible returned error is ErrBadPattern, when pattern is malformed.

Note: If fsPath does not exist, Glob may return matches, if fsPath represents a pattern.
If fsPath exists, Glob should return exactly one match: itself (unless Ospwd has changed).

func (*FsBase) JoinWith

func (p *FsBase) JoinWith(elem ...string) string

JoinWith joins f with any number of path elements into a single path, adding a Separator if necessary. Join calls Clean on the result; in particular, all empty strings are ignored. On Windows, the result is a UNC path if and only if the first path element is a UNC path.

func (*FsBase) Match

func (p *FsBase) Match(pattern *Pattern) (matched bool, err error)

Match reports whether name matches the shell file name pattern.

func (*FsBase) MatchDisk

func (p *FsBase) MatchDisk() (dirS FsFoldS, filS FsFileS, err error)

MatchDisk is a convenience for MatchDisk(name).

func (*FsBase) PathMatches

func (p *FsBase) PathMatches(patterns ...*Pattern) (matched bool, err error)

PathMatches reports whether fsPath matches any of the patterns.

func (*FsBase) Split

func (p *FsBase) Split() (dir, file string)

Split splits path immediately following the final Separator, separating it into a directory and file name component. If there is no Separator in path, Split returns an empty dir and file set to path. The returned values have the property that path = dir+file.

func (*FsBase) SplitList

func (p *FsBase) SplitList() []string

SplitList splits a list of paths joined by the OS-specific ListSeparator, usually found in PATH or GOPATH environment variables. Unlike strings.Split, SplitList returns an empty slice when passed an empty string.

func (*FsBase) Stat

func (p *FsBase) Stat() (os.FileInfo, error)

Stat - returns the actual os.Stat() and the error received from os.Stat (of type *PathError)

Note: Stat does not refer to the FileInfo originally embedded into fsPath and thus may return
different FileInfo, if content of file system representetd by fsPath has changed.

func (*FsBase) String

func (p *FsBase) String() string

String returns the pathtext repreented by fsPath

func (*FsBase) TryBase

func (p *FsBase) TryBase() (*FsBase, bool)

TryBase returns a fresh FsBase for the given path, or false iff path is not identical to it's own Base(name).

func (*FsBase) TryInfo

func (p *FsBase) TryInfo() (*fsInfo, error)

TryInfo returns a fresh fsInfo, and the error received from os.Stat() (if any)

func (*FsBase) TryPath

func (p *FsBase) TryPath() (*fsPath, bool)

TryPath returns (a pointer to) the underlying fsPath false, iff fsPath contains

  • any filepath.ListSeparator (= os.PathListSeparator) or
  • any of the Match-Metacharacters (MatchAny "*" or MatchOne "?") Note: Match-Metacharacters "[" and "]" are intentionally permitted; they may be used not only in patterns, but also as valid name of some file or folder/directory.

func (*FsBase) TryPattern

func (p *FsBase) TryPattern() (*Pattern, bool)

TryPattern returns a fresh Pattern for the given path, and false iff ErrBadPattern is returned from Match.

type FsBaseS

type FsBaseS []*FsBase

FsBaseS represents a collection (slice) of (pointers to) FsBase's.

func (FsBaseS) String

func (f FsBaseS) String() string

String returns the FsBaseS-slice as string.

type FsData

type FsData struct {
	FsFile
	// contains filtered or unexported fields
}

FsData represents the data (as read upon it's creation) of a related FsFile and is intended to be used by higher packages such as FsCache.

Note: FsData is immutable, and as such safe for concurrent use.

func ForceData

func ForceData(name string, data []byte) *FsData

ForceData returns a fresh FsData having given name and data.

func (*FsData) AsFile

func (p *FsData) AsFile() *FsFile

AsFile returns a fresh FsFile for the given FsInfo, or panics, if the FsInfo represents a Dir.

func (*FsData) AsFold

func (p *FsData) AsFold() *FsFold

AsFold returns a fresh FsFold for the given FsInfo, or panics, if the FsInfo does not represent a Dir.

func (*FsData) AsNotDown

func (p *FsData) AsNotDown() *FsFold

AsNotDown returns a fresh FsFold representing a file system directory/file not to be recursed into.

func (*FsData) AsRecurse

func (p *FsData) AsRecurse() *FsFold

AsRecurse returns a fresh FsFold representing a file system directory/file to be recursed into.

func (*FsData) ByteS

func (p *FsData) ByteS() []byte

ByteS returns the cached data

func (*FsData) Data

func (p *FsData) Data() string

Data returns the cached data as string

func (*FsData) Exists

func (p *FsData) Exists() bool

Exists returns true, if OsPath is known to represent a real disk element which already exists on disk

func (*FsData) InfoEquals

func (p *FsData) InfoEquals(oi os.FileInfo) bool

InfoEquals returns true, if all FileInfo data is same.

func (*FsData) IsFold

func (p *FsData) IsFold() bool

IsFold returns IsDir, if it is known to exist, and false otherwise.

func (*FsData) SameFile

func (p *FsData) SameFile(oi os.FileInfo) bool

SameFile reports whether f and oi describe the same file. For example, on Unix this means that the device and inode fields of the two underlying structures are identical; on other systems the decision may be based on the path names. SameFile only applies to results returned by os.Stat. SameFile returns false in other cases.

func (*FsData) TryFile

func (p *FsData) TryFile() (*FsFile, bool)

TryFile returns a fresh FsFile, or nil and false iff fi.IsFold().

func (*FsData) TryFold

func (p *FsData) TryFold() (*FsFold, bool)

TryFold returns a fresh FsFold, or nil and false iff not p.IsFold().

type FsDataS

type FsDataS []*FsData

FsDataS represents a collection (slice) of (pointers to) FsData's.

func (FsDataS) String

func (f FsDataS) String() string

String returns the FsDataS-slice as string.

type FsFile

type FsFile struct {
	// contains filtered or unexported fields
}

FsFile represents a file of the file system.

Note: FsFile is immutable, and as such safe for concurrent use.

func ForceFile

func ForceFile(name string) *FsFile

ForceFile returns a fresh FsFile having given name.

func (*FsFile) AsData

func (f *FsFile) AsData() *FsData

AsData returns a fresh FsData for the given FsFile, or panics, if TryData returns an error (from ReadFile).

func (*FsFile) AsFile

func (p *FsFile) AsFile() *FsFile

AsFile returns a fresh FsFile for the given FsInfo, or panics, if the FsInfo represents a Dir.

func (*FsFile) AsFold

func (p *FsFile) AsFold() *FsFold

AsFold returns a fresh FsFold for the given FsInfo, or panics, if the FsInfo does not represent a Dir.

func (*FsFile) AsNotDown

func (p *FsFile) AsNotDown() *FsFold

AsNotDown returns a fresh FsFold representing a file system directory/file not to be recursed into.

func (*FsFile) AsRecurse

func (p *FsFile) AsRecurse() *FsFold

AsRecurse returns a fresh FsFold representing a file system directory/file to be recursed into.

func (*FsFile) Create

func (p *FsFile) Create() (*os.File, error)

Create creates the file named by OsPath.Path() with mode 0666 (before umask), truncating it if it already exists. If successful, methods on the returned File can be used for I/O; the associated file descriptor has mode O_RDWR. If there is an error, it will be of type *PathError.

Note: do not forget to defer file.Close()

func (*FsFile) Exists

func (p *FsFile) Exists() bool

Exists returns true, if OsPath is known to represent a real disk element which already exists on disk

func (*FsFile) InfoEquals

func (p *FsFile) InfoEquals(oi os.FileInfo) bool

InfoEquals returns true, if all FileInfo data is same.

func (*FsFile) IsFold

func (p *FsFile) IsFold() bool

IsFold returns IsDir, if it is known to exist, and false otherwise.

func (*FsFile) Open

func (p *FsFile) Open() (*os.File, error)

Open opens the file named by OsPath.Path() for reading. If successful, methods on the returned file can be used for reading; the associated file descriptor has mode O_RDONLY. If there is an error, it will be of type *PathError.

Note: do not forget to defer file.Close()

func (*FsFile) ReadFile

func (p *FsFile) ReadFile() ([]byte, error)

ReadFile reads the file named by OsPath.Path() and returns the contents.

Note: A successful call returns err == nil, not err == EOF.
Because ReadFile reads the whole file, it does not treat an EOF from Read as an error to be reported.
Note: for convenience, the contents is returned as string, not as []byte.

func (*FsFile) SameFile

func (p *FsFile) SameFile(oi os.FileInfo) bool

SameFile reports whether f and oi describe the same file. For example, on Unix this means that the device and inode fields of the two underlying structures are identical; on other systems the decision may be based on the path names. SameFile only applies to results returned by os.Stat. SameFile returns false in other cases.

func (*FsFile) TryData

func (f *FsFile) TryData() (*FsData, bool)

TryData returns a fresh FsData for the given FsFile, or false (and empty byteS/data) iff ReadFile() returned an error.

func (*FsFile) TryFile

func (p *FsFile) TryFile() (*FsFile, bool)

TryFile returns a fresh FsFile, or nil and false iff fi.IsFold().

func (*FsFile) TryFold

func (p *FsFile) TryFold() (*FsFold, bool)

TryFold returns a fresh FsFold, or nil and false iff not p.IsFold().

func (*FsFile) WriteFile

func (p *FsFile) WriteFile(byteS []byte) error

WriteFile writes data to a file named by fsPath. If the file does not exist, WriteFile creates it with permissions Perm; otherwise WriteFile truncates it before writing.

type FsFileS

type FsFileS []*FsFile

FsFileS represents a collection (slice) of (pointers to) FsFile's.

func MatchFiles

func MatchFiles(pathName string, patterns ...*Pattern) (filS FsFileS)

MatchFiles matches pathName against the Disk (via MatchDisk/Glob) and then returns only those files the base name of which matches any of the given patternlists. Any eventual filesystem errors are ignored and skipped over.

func (FsFileS) String

func (f FsFileS) String() string

String returns the FsFileS-slice as string.

type FsFold

type FsFold struct {
	// contains filtered or unexported fields
}

FsFold represents a folder / directory of the file system. It may indicate to be (or have been) recursed into.

Note: FsFold is immutable, and as such safe for concurrent use.

func ForceFold

func ForceFold(name string) *FsFold

ForceFold returns a fresh FsFold given a pathname.

func NotDown

func NotDown(name string) *FsFold

NotDown returns a fresh FsFold given a pathname, which also indicates not to be recursed into.

func Recurse

func Recurse(name string) *FsFold

Recurse returns a fresh FsFold given a pathname, which also indicates to be recursed.

func (*FsFold) AsFile

func (p *FsFold) AsFile() *FsFile

AsFile returns a fresh FsFile for the given FsInfo, or panics, if the FsInfo represents a Dir.

func (*FsFold) AsFold

func (p *FsFold) AsFold() *FsFold

AsFold returns a fresh FsFold for the given FsInfo, or panics, if the FsInfo does not represent a Dir.

func (*FsFold) AsNotDown

func (p *FsFold) AsNotDown() *FsFold

AsNotDown returns a fresh FsFold representing a file system directory/file not to be recursed into.

func (*FsFold) AsRecurse

func (p *FsFold) AsRecurse() *FsFold

AsRecurse returns a fresh FsFold representing a file system directory/file to be recursed into.

func (*FsFold) Exists

func (p *FsFold) Exists() bool

Exists returns true, if OsPath is known to represent a real disk element which already exists on disk

func (*FsFold) FileS

func (f *FsFold) FileS(patterns ...*Pattern) (FilS FsFileS)

FileS returns all files in f matching any of the patterns in the patternlists

func (*FsFold) HasRecurse

func (f *FsFold) HasRecurse() bool

HasRecurse returns true if this folder has a recurse indicator

func (*FsFold) InfoEquals

func (p *FsFold) InfoEquals(oi os.FileInfo) bool

InfoEquals returns true, if all FileInfo data is same.

func (*FsFold) IsFold

func (p *FsFold) IsFold() bool

IsFold returns IsDir, if it is known to exist, and false otherwise.

func (*FsFold) MkDir

func (p *FsFold) MkDir() error

MkDir uses os.MkdirAll to create a directory named by fsPath, along with any necessary parents, and returns nil, or else returns an error. The permission bits Perm are used for all created directories. If fsPath is already a directory, MkDir does nothing and returns nil.

func (*FsFold) ReadDir

func (p *FsFold) ReadDir() ([]os.FileInfo, error)

ReadDir reads the directory named by OsPath.Path() and returns a list of directory entries sorted by filename.

func (*FsFold) ReadDirS

func (f *FsFold) ReadDirS() (entrieS FsInfoS, err error)

ReadDirS reads the directory named by OsPath.Path() and returns a FsInfo slice of directory entries sorted by filename.

func (*FsFold) Recurse

func (f *FsFold) Recurse() bool

Recurse returns true if this folder indicates to be recursed into

func (*FsFold) SameFile

func (p *FsFold) SameFile(oi os.FileInfo) bool

SameFile reports whether f and oi describe the same file. For example, on Unix this means that the device and inode fields of the two underlying structures are identical; on other systems the decision may be based on the path names. SameFile only applies to results returned by os.Stat. SameFile returns false in other cases.

func (*FsFold) SubDirS

func (f *FsFold) SubDirS() (DirS []*FsFold)

SubDirS returns fi and all it's (recursed) subdirectories, the directory tree rooted at fi, so to say.

func (*FsFold) TabString

func (f *FsFold) TabString() string

TabString returns the Name and the Recurse flag as a Tab terminated string

func (*FsFold) TryFile

func (p *FsFold) TryFile() (*FsFile, bool)

TryFile returns a fresh FsFile, or nil and false iff fi.IsFold().

func (*FsFold) TryFold

func (p *FsFold) TryFold() (*FsFold, bool)

TryFold returns a fresh FsFold, or nil and false iff not p.IsFold().

type FsFoldS

type FsFoldS []*FsFold

FsFoldS represents a collection (slice) of (pointers to) FsFold's.

func MatchFolds

func MatchFolds(pathName string, patterns ...*Pattern) (dirS FsFoldS)

MatchFolds matches pathName against the Disk (via MatchDisk/Glob) and then returns only those folders/directories the base name of which matches any of the given patternlists. Any eventual filesystem errors are ignored and skipped over.

func SubDirS

func SubDirS(pathName string) (dirS FsFoldS)

SubDirS matches pathName against the Disk (via MatchDisk/Glob) and then returns all directories below any directory matching pathname as a breadth first sorted slice. Any eventual filesystem errors are ignored and skipped over.

func (FsFoldS) String

func (f FsFoldS) String() string

String returns the FsFoldS-slice as string.

type FsInfoS

type FsInfoS []*fsInfo

FsInfoS represents a collection (slice) of (pointers to) FsInfo's.

func (FsInfoS) AllDirs

func (f FsInfoS) AllDirs() bool

AllDirs returns true if and only if for all elements IsDir is true.

func (FsInfoS) String

func (f FsInfoS) String() string

String returns the FsInfoS-slice as string.

type FsPathS

type FsPathS []*fsPath

FsPathS represents a collection (slice) of (pointers to) fsPathes

func NewS

func NewS(names ...string) (pathS FsPathS)

NewS returns a non-empty slice of fsPath obtained via filepath.SplitList

func (FsPathS) Accessible

func (f FsPathS) Accessible() error

Accessible returns any errors encountered when accessing it's elements

func (FsPathS) String

func (f FsPathS) String() string

String returns the FsPathS-slice as string.

func (FsPathS) Validate

func (f FsPathS) Validate() error

Validate returns any errors encountered when validating it's elements

type InfoFriendly

type InfoFriendly interface {
	PathFriendly
	AsFile() *FsFile
	TryFile() (*FsFile, bool)
	AsFold() *FsFold
	TryFold() (*FsFold, bool)
	AsNotDown() *FsFold
	AsRecurse() *FsFold

	Exists() bool
	IsFold() bool

	SameFile(oi os.FileInfo) bool
	InfoEquals(oi os.FileInfo) bool
}

InfoFriendly summarises many methods inherited from internal type fsInfo in related groups / sub interfaces

Note: this interface is exposed not only for godoc ;-)

type MatchFriendly

type MatchFriendly interface {
	DiskFriendly
	Match(pattern *Pattern) (matched bool, err error)
	PathMatches(patterns ...*Pattern) (matched bool, err error)
	BaseMatches(patterns ...*Pattern) (matched bool, err error)
}

MatchFriendly summarises methods related to matching

Note: this interface is exposed not only for godoc ;-)

type OsFileInfoFriendly

type OsFileInfoFriendly interface {
	// obtain os.FileInfo
	Stat() (os.FileInfo, error)
}

OsFileInfoFriendly summarises methods related to os.FileInfo

Note: this interface is exposed not only for godoc ;-)

type PathFriendly

type PathFriendly interface {
	FilePathFriendly
	MatchFriendly
	OsFileInfoFriendly
	PathTypeFriendly
	Accessible() error
}

PathFriendly summarises many methods inherited from internal type fsPath in related groups / sub interfaces

Note: this interface is exposed not only for godoc ;-)

type PathTypeFriendly

type PathTypeFriendly interface {
	AsPath() *fsPath
	TryPath() (*fsPath, bool)
	AsInfo() *fsInfo
	TryInfo() (*fsInfo, error)
	AsBase() *FsBase
	TryBase() (*FsBase, bool)
	AsPattern() *Pattern
	TryPattern() (*Pattern, bool)
}

PathTypeFriendly summarises methods related to pathes

Note: this interface is exposed not only for godoc ;-)

type Pattern

type Pattern struct {
	// contains filtered or unexported fields
}

Pattern represents a file system pattern

Note: Pattern is immutable, and as such safe for concurrent use.

func ForcePattern

func ForcePattern(name string) *Pattern

ForcePattern returns a fresh Pattern representing the given a name.

func (*Pattern) Accessible

func (p *Pattern) Accessible() error

Accessible - returns nil, or the error received from os.Open (or Close)

func (*Pattern) AsBase

func (p *Pattern) AsBase() *FsBase

AsBase returns a fresh FsBase for the given FsInfo, or panics, if path is not identical to it's own Base(name).

func (*Pattern) AsInfo

func (p *Pattern) AsInfo() *fsInfo

AsInfo returns a fresh FsInfo, and the error received from os.Stat() (if any), or panics, if TryInfo returns an error (from os.Stat()).

func (*Pattern) AsPath

func (p *Pattern) AsPath() *fsPath

AsPath returns (a pointer to) the underlying fsPath or panics, if TryPath detected some invlaid content.

Note: AsPath exists only for symmetry with respect to the other, higher types.

func (*Pattern) AsPattern

func (p *Pattern) AsPattern() *Pattern

AsPattern returns a fresh Pattern for the given fsPath, or panics, if TryPattern returns an error (ErrBadPattern).

func (*Pattern) Base

func (p *Pattern) Base() *FsBase

Base returns the last element of path. Trailing path separators are removed before extracting the last element. If the path is empty, Base returns ".". If the path consists entirely of separators, Base returns a single separator.

func (*Pattern) BaseLessExt

func (p *Pattern) BaseLessExt() *FsBase

BaseLessExt: name.Base() less name.Ext()

func (*Pattern) BaseMatches

func (p *Pattern) BaseMatches(patterns ...*Pattern) (matched bool, err error)

BaseMatches reports whether base name of fsPath matches any of the patterns.

func (*Pattern) Exists

func (p *Pattern) Exists() (bool, error)

Exists returns whether the given file or directory exists or not from http://stackoverflow.com/a/10510783

func (*Pattern) Ext

func (p *Pattern) Ext() *FsBase

Ext returns the file name extension used by path. The extension is the suffix beginning at the final dot in the final element of path; it is empty if there is no dot.

func (*Pattern) Glob

func (p *Pattern) Glob() (matches []string, err error)

Glob returns the names of all files matching the pattern (=PathText()), or nil if there is no matching entry(file/directory).

Note. The pattern may describe hierarchical names such as
/usr/*/bin/ed (assuming the Separator is '/').

Glob ignores file system errors such as I/O errors reading directories. The only possible returned error is ErrBadPattern, when pattern is malformed.

Note: If fsPath does not exist, Glob may return matches, if fsPath represents a pattern.
If fsPath exists, Glob should return exactly one match: itself (unless Ospwd has changed).

func (*Pattern) JoinWith

func (p *Pattern) JoinWith(elem ...string) string

JoinWith joins f with any number of path elements into a single path, adding a Separator if necessary. Join calls Clean on the result; in particular, all empty strings are ignored. On Windows, the result is a UNC path if and only if the first path element is a UNC path.

func (*Pattern) Match

func (p *Pattern) Match(pattern *Pattern) (matched bool, err error)

Match reports whether name matches the shell file name pattern.

func (*Pattern) MatchDisk

func (p *Pattern) MatchDisk() (dirS FsFoldS, filS FsFileS, err error)

MatchDisk is a convenience for MatchDisk(name).

func (*Pattern) PathMatches

func (p *Pattern) PathMatches(patterns ...*Pattern) (matched bool, err error)

PathMatches reports whether fsPath matches any of the patterns.

func (*Pattern) Split

func (p *Pattern) Split() (dir, file string)

Split splits path immediately following the final Separator, separating it into a directory and file name component. If there is no Separator in path, Split returns an empty dir and file set to path. The returned values have the property that path = dir+file.

func (*Pattern) SplitList

func (p *Pattern) SplitList() []string

SplitList splits a list of paths joined by the OS-specific ListSeparator, usually found in PATH or GOPATH environment variables. Unlike strings.Split, SplitList returns an empty slice when passed an empty string.

func (*Pattern) Stat

func (p *Pattern) Stat() (os.FileInfo, error)

Stat - returns the actual os.Stat() and the error received from os.Stat (of type *PathError)

Note: Stat does not refer to the FileInfo originally embedded into fsPath and thus may return
different FileInfo, if content of file system representetd by fsPath has changed.

func (*Pattern) String

func (p *Pattern) String() string

String returns the pathtext repreented by fsPath

func (*Pattern) TryBase

func (p *Pattern) TryBase() (*FsBase, bool)

TryBase returns a fresh FsBase for the given path, or false iff path is not identical to it's own Base(name).

func (*Pattern) TryInfo

func (p *Pattern) TryInfo() (*fsInfo, error)

TryInfo returns a fresh fsInfo, and the error received from os.Stat() (if any)

func (*Pattern) TryPath

func (p *Pattern) TryPath() (*fsPath, bool)

TryPath returns (a pointer to) the underlying fsPath false, iff fsPath contains

  • any filepath.ListSeparator (= os.PathListSeparator) or
  • any of the Match-Metacharacters (MatchAny "*" or MatchOne "?") Note: Match-Metacharacters "[" and "]" are intentionally permitted; they may be used not only in patterns, but also as valid name of some file or folder/directory.

func (*Pattern) TryPattern

func (p *Pattern) TryPattern() (*Pattern, bool)

TryPattern returns a fresh Pattern for the given path, and false iff ErrBadPattern is returned from Match.

type PatternFriendly

type PatternFriendly interface {
	PathFriendly
}

PatternFriendly summarises methods of type Pattern

Note: this interface is exposed not only for godoc ;-)

type PatternS

type PatternS []*Pattern

PatternS represents a collection (slice) of (pointers to) Pattern's.

func NewPatternS

func NewPatternS(names ...string) (patternS PatternS)

NewPatternS returns a non-empty slice of Patterns obtained via filepath.SplitList

func (PatternS) String

func (f PatternS) String() string

String returns the PatternS-slice as string.

Jump to

Keyboard shortcuts

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