lib/fs: Expose fs option on interface (fixes #7385, ref #7381) (#7389)

This commit is contained in:
Simon Frei
2021-03-11 15:23:56 +01:00
committed by GitHub
parent cdef503db6
commit 3938b61c3f
9 changed files with 74 additions and 36 deletions
+18 -11
View File
@@ -26,24 +26,26 @@ var (
errNotRelative = errors.New("not a relative path")
)
func WithJunctionsAsDirs() Option {
return Option{
apply: func(fs Filesystem) {
if basic, ok := fs.(*BasicFilesystem); !ok {
l.Warnln("WithJunctionsAsDirs must only be used with FilesystemTypeBasic")
} else {
basic.junctionsAsDirs = true
}
},
id: "junctionsAsDirs",
type OptionJunctionsAsDirs struct{}
func (o *OptionJunctionsAsDirs) apply(fs Filesystem) {
if basic, ok := fs.(*BasicFilesystem); !ok {
l.Warnln("WithJunctionsAsDirs must only be used with FilesystemTypeBasic")
} else {
basic.junctionsAsDirs = true
}
}
func (o *OptionJunctionsAsDirs) String() string {
return "junctionsAsDirs"
}
// The BasicFilesystem implements all aspects by delegating to package os.
// All paths are relative to the root and cannot (should not) escape the root directory.
type BasicFilesystem struct {
root string
junctionsAsDirs bool
options []Option
}
func newBasicFilesystem(root string, opts ...Option) *BasicFilesystem {
@@ -82,7 +84,8 @@ func newBasicFilesystem(root string, opts ...Option) *BasicFilesystem {
}
fs := &BasicFilesystem{
root: root,
root: root,
options: opts,
}
for _, opt := range opts {
opt.apply(fs)
@@ -311,6 +314,10 @@ func (f *BasicFilesystem) URI() string {
return strings.TrimPrefix(f.root, `\\?\`)
}
func (f *BasicFilesystem) Options() []Option {
return f.options
}
func (f *BasicFilesystem) SameFile(fi1, fi2 FileInfo) bool {
// Like os.SameFile, we always return false unless fi1 and fi2 were created
// by this package's Stat/Lstat method.