|
@@ -26,24 +26,26 @@ var (
|
|
|
errNotRelative = errors.New("not a relative path")
|
|
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.
|
|
// 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.
|
|
// All paths are relative to the root and cannot (should not) escape the root directory.
|
|
|
type BasicFilesystem struct {
|
|
type BasicFilesystem struct {
|
|
|
root string
|
|
root string
|
|
|
junctionsAsDirs bool
|
|
junctionsAsDirs bool
|
|
|
|
|
+ options []Option
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
func newBasicFilesystem(root string, opts ...Option) *BasicFilesystem {
|
|
func newBasicFilesystem(root string, opts ...Option) *BasicFilesystem {
|
|
@@ -82,7 +84,8 @@ func newBasicFilesystem(root string, opts ...Option) *BasicFilesystem {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
fs := &BasicFilesystem{
|
|
fs := &BasicFilesystem{
|
|
|
- root: root,
|
|
|
|
|
|
|
+ root: root,
|
|
|
|
|
+ options: opts,
|
|
|
}
|
|
}
|
|
|
for _, opt := range opts {
|
|
for _, opt := range opts {
|
|
|
opt.apply(fs)
|
|
opt.apply(fs)
|
|
@@ -311,6 +314,10 @@ func (f *BasicFilesystem) URI() string {
|
|
|
return strings.TrimPrefix(f.root, `\\?\`)
|
|
return strings.TrimPrefix(f.root, `\\?\`)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+func (f *BasicFilesystem) Options() []Option {
|
|
|
|
|
+ return f.options
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
func (f *BasicFilesystem) SameFile(fi1, fi2 FileInfo) bool {
|
|
func (f *BasicFilesystem) SameFile(fi1, fi2 FileInfo) bool {
|
|
|
// Like os.SameFile, we always return false unless fi1 and fi2 were created
|
|
// Like os.SameFile, we always return false unless fi1 and fi2 were created
|
|
|
// by this package's Stat/Lstat method.
|
|
// by this package's Stat/Lstat method.
|