lib/config, lib/fs: Make junction behaviour configurable (ref #6606) (#6907)

This commit is contained in:
Simon Frei
2020-08-19 19:58:51 +02:00
committed by GitHub
parent ce4d149bf5
commit fc2c46e82f
11 changed files with 49 additions and 17 deletions
+21 -4
View File
@@ -23,13 +23,24 @@ var (
ErrNotRelative = errors.New("not a relative path")
)
func WithJunctionsAsDirs() Option {
return func(fs Filesystem) {
if basic, ok := fs.(*BasicFilesystem); !ok {
l.Warnln("WithJunctionsAsDirs must only be used with FilesystemTypeBasic")
} else {
basic.junctionsAsDirs = true
}
}
}
// 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
root string
junctionsAsDirs bool
}
func newBasicFilesystem(root string) *BasicFilesystem {
func newBasicFilesystem(root string, opts ...Option) *BasicFilesystem {
if root == "" {
root = "." // Otherwise "" becomes "/" below
}
@@ -64,7 +75,13 @@ func newBasicFilesystem(root string) *BasicFilesystem {
root = longFilenameSupport(root)
}
return &BasicFilesystem{root}
fs := &BasicFilesystem{
root: root,
}
for _, opt := range opts {
opt(fs)
}
return fs
}
// rooted expands the relative path to the full path that is then used with os
@@ -145,7 +162,7 @@ func (f *BasicFilesystem) Lstat(name string) (FileInfo, error) {
if err != nil {
return nil, err
}
fi, err := underlyingLstat(name)
fi, err := f.underlyingLstat(name)
if err != nil {
return nil, err
}