lib: Get rid of buggy filesystem wrapping (#8257)
This commit is contained in:
@@ -457,7 +457,7 @@ func TestIssue1262(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
actual := cfg.Folders()["test"].Filesystem().URI()
|
||||
actual := cfg.Folders()["test"].Filesystem(nil).URI()
|
||||
expected := `e:\`
|
||||
|
||||
if actual != expected {
|
||||
@@ -494,7 +494,7 @@ func TestFolderPath(t *testing.T) {
|
||||
Path: "~/tmp",
|
||||
}
|
||||
|
||||
realPath := folder.Filesystem().URI()
|
||||
realPath := folder.Filesystem(nil).URI()
|
||||
if !filepath.IsAbs(realPath) {
|
||||
t.Error(realPath, "should be absolute")
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ import (
|
||||
|
||||
"github.com/shirou/gopsutil/v3/disk"
|
||||
|
||||
"github.com/syncthing/syncthing/lib/db"
|
||||
"github.com/syncthing/syncthing/lib/fs"
|
||||
"github.com/syncthing/syncthing/lib/protocol"
|
||||
"github.com/syncthing/syncthing/lib/util"
|
||||
@@ -42,24 +43,29 @@ func (f FolderConfiguration) Copy() FolderConfiguration {
|
||||
return c
|
||||
}
|
||||
|
||||
func (f FolderConfiguration) Filesystem() fs.Filesystem {
|
||||
// Filesystem creates a filesystem for the path and options of this folder.
|
||||
// The fset parameter may be nil, in which case no mtime handling on top of
|
||||
// the fileystem is provided.
|
||||
func (f FolderConfiguration) Filesystem(fset *db.FileSet) fs.Filesystem {
|
||||
// This is intentionally not a pointer method, because things like
|
||||
// cfg.Folders["default"].Filesystem() should be valid.
|
||||
var opts []fs.Option
|
||||
// cfg.Folders["default"].Filesystem(nil) should be valid.
|
||||
opts := make([]fs.Option, 0, 3)
|
||||
if f.FilesystemType == fs.FilesystemTypeBasic && f.JunctionsAsDirs {
|
||||
opts = append(opts, new(fs.OptionJunctionsAsDirs))
|
||||
}
|
||||
filesystem := fs.NewFilesystem(f.FilesystemType, f.Path, opts...)
|
||||
if !f.CaseSensitiveFS {
|
||||
filesystem = fs.NewCaseFilesystem(filesystem)
|
||||
opts = append(opts, new(fs.OptionDetectCaseConflicts))
|
||||
}
|
||||
return filesystem
|
||||
if fset != nil {
|
||||
opts = append(opts, fset.MtimeOption())
|
||||
}
|
||||
return fs.NewFilesystem(f.FilesystemType, f.Path, opts...)
|
||||
}
|
||||
|
||||
func (f FolderConfiguration) ModTimeWindow() time.Duration {
|
||||
dur := time.Duration(f.RawModTimeWindowS) * time.Second
|
||||
if f.RawModTimeWindowS < 1 && runtime.GOOS == "android" {
|
||||
if usage, err := disk.Usage(f.Filesystem().URI()); err != nil {
|
||||
if usage, err := disk.Usage(f.Filesystem(nil).URI()); err != nil {
|
||||
dur = 2 * time.Second
|
||||
l.Debugf(`Detecting FS at "%v" on android: Setting mtime window to 2s: err == "%v"`, f.Path, err)
|
||||
} else if strings.HasPrefix(strings.ToLower(usage.Fstype), "ext2") || strings.HasPrefix(strings.ToLower(usage.Fstype), "ext3") || strings.HasPrefix(strings.ToLower(usage.Fstype), "ext4") {
|
||||
@@ -89,7 +95,7 @@ func (f *FolderConfiguration) CreateMarker() error {
|
||||
// begin with.
|
||||
permBits = 0700
|
||||
}
|
||||
fs := f.Filesystem()
|
||||
fs := f.Filesystem(nil)
|
||||
err := fs.Mkdir(DefaultMarkerName, permBits)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -106,7 +112,7 @@ func (f *FolderConfiguration) CreateMarker() error {
|
||||
|
||||
// CheckPath returns nil if the folder root exists and contains the marker file
|
||||
func (f *FolderConfiguration) CheckPath() error {
|
||||
fi, err := f.Filesystem().Stat(".")
|
||||
fi, err := f.Filesystem(nil).Stat(".")
|
||||
if err != nil {
|
||||
if !fs.IsNotExist(err) {
|
||||
return err
|
||||
@@ -124,7 +130,7 @@ func (f *FolderConfiguration) CheckPath() error {
|
||||
return ErrPathNotDirectory
|
||||
}
|
||||
|
||||
_, err = f.Filesystem().Stat(f.MarkerName)
|
||||
_, err = f.Filesystem(nil).Stat(f.MarkerName)
|
||||
if err != nil {
|
||||
if !fs.IsNotExist(err) {
|
||||
return err
|
||||
@@ -145,7 +151,7 @@ func (f *FolderConfiguration) CreateRoot() (err error) {
|
||||
permBits = 0700
|
||||
}
|
||||
|
||||
filesystem := f.Filesystem()
|
||||
filesystem := f.Filesystem(nil)
|
||||
|
||||
if _, err = filesystem.Stat("."); fs.IsNotExist(err) {
|
||||
err = filesystem.MkdirAll(".", permBits)
|
||||
@@ -256,7 +262,7 @@ func (f *FolderConfiguration) CheckAvailableSpace(req uint64) error {
|
||||
if val <= 0 {
|
||||
return nil
|
||||
}
|
||||
fs := f.Filesystem()
|
||||
fs := f.Filesystem(nil)
|
||||
usage, err := fs.Usage(".")
|
||||
if err != nil {
|
||||
return nil
|
||||
|
||||
@@ -199,7 +199,7 @@ func migrateToConfigV23(cfg *Configuration) {
|
||||
// marker name in later versions.
|
||||
|
||||
for i := range cfg.Folders {
|
||||
fs := cfg.Folders[i].Filesystem()
|
||||
fs := cfg.Folders[i].Filesystem(nil)
|
||||
// Invalid config posted, or tests.
|
||||
if fs == nil {
|
||||
continue
|
||||
@@ -235,18 +235,18 @@ func migrateToConfigV21(cfg *Configuration) {
|
||||
switch folder.Versioning.Type {
|
||||
case "simple", "trashcan":
|
||||
// Clean out symlinks in the known place
|
||||
cleanSymlinks(folder.Filesystem(), ".stversions")
|
||||
cleanSymlinks(folder.Filesystem(nil), ".stversions")
|
||||
case "staggered":
|
||||
versionDir := folder.Versioning.Params["versionsPath"]
|
||||
if versionDir == "" {
|
||||
// default place
|
||||
cleanSymlinks(folder.Filesystem(), ".stversions")
|
||||
cleanSymlinks(folder.Filesystem(nil), ".stversions")
|
||||
} else if filepath.IsAbs(versionDir) {
|
||||
// absolute
|
||||
cleanSymlinks(fs.NewFilesystem(fs.FilesystemTypeBasic, versionDir), ".")
|
||||
} else {
|
||||
// relative to folder
|
||||
cleanSymlinks(folder.Filesystem(), versionDir)
|
||||
cleanSymlinks(folder.Filesystem(nil), versionDir)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user