Documentation ¶
Overview ¶
Package matchedfs allows to hide or alter permissions of an underlying afero.Fs.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Fs ¶
type Fs interface { afero.Fs // SetExcludeMatcher sets the Matcher to be used for excluding/hiding // files from the filesystem. SetExcludeMatcher(Matcher) SetExcludePathMatcher(PathMatcher) // AddPermissionMatcher adds a Matcher which applies the os.FileMode mask // to the matched paths mode bits. Specifically, a given file/directory // permissions are bitcleared by mode. AddPermissionMatcher(m Matcher, mode os.FileMode) AddPermissionPathMatcher(p PathMatcher, mode os.FileMode) }
Fs exposes the underlying afero.Fs according to the exclude and permission matchers. If the exclude matcher matches a path, associated operations return an os.ErrNotExists. If one of the permission matchers masks in such a way as to not allow an operation, the associated operation returns os.ErrPermission.
Example ¶
package main import ( "fmt" "os" "github.com/spf13/afero" "gitlab.com/tbhartman/go-matchedfs" ) type myMatcher struct { matchString []string } func (m *myMatcher) Match(name string) bool { for _, str := range m.matchString { if name == str { return true } } return false } func main() { fs := matchedfs.New(afero.NewMemMapFs()) fs.Mkdir("a", os.ModeDir|0700) fs.Mkdir("b", os.ModeDir|0700) fs.SetExcludeMatcher(&myMatcher{[]string{"a/"}}) _, errA := fs.Stat("a") if errA == nil { fmt.Println("a exists") } else { fmt.Println("a does not exist") } _, errB := fs.Stat("b") if errB == nil { fmt.Println("b exists") } else { fmt.Println("b does not exist") } }
Output: a does not exist b exists
type Matcher ¶
Matcher is the interface to match a path. The path is passed through filepath.Clean and filepath.ToSlash. If it matches an existing directory, a slash is appended. The resulting path is passed to Match.
type PathMatcher ¶
PathMatcher replicates the interface used by "github.com/sabhiram/go-gitignore" .