all: Convert folders to use filesystem abstraction
GitHub-Pull-Request: https://github.com/syncthing/syncthing/pull/4228
This commit is contained in:
committed by
Jakob Borg
parent
ab8c2fb5c7
commit
3d8b4a42b7
@@ -23,6 +23,7 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/syncthing/syncthing/lib/fs"
|
||||
"github.com/syncthing/syncthing/lib/protocol"
|
||||
"github.com/syncthing/syncthing/lib/rand"
|
||||
"github.com/syncthing/syncthing/lib/upgrade"
|
||||
@@ -31,7 +32,7 @@ import (
|
||||
|
||||
const (
|
||||
OldestHandledVersion = 10
|
||||
CurrentVersion = 21
|
||||
CurrentVersion = 22
|
||||
MaxRescanIntervalS = 365 * 24 * 60 * 60
|
||||
)
|
||||
|
||||
@@ -319,6 +320,9 @@ func (cfg *Configuration) clean() error {
|
||||
if cfg.Version == 20 {
|
||||
convertV20V21(cfg)
|
||||
}
|
||||
if cfg.Version == 21 {
|
||||
convertV21V22(cfg)
|
||||
}
|
||||
|
||||
// Build a list of available devices
|
||||
existingDevices := make(map[protocol.DeviceID]bool)
|
||||
@@ -368,23 +372,38 @@ func (cfg *Configuration) clean() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func convertV21V22(cfg *Configuration) {
|
||||
for i := range cfg.Folders {
|
||||
cfg.Folders[i].FilesystemType = fs.FilesystemTypeBasic
|
||||
// Migrate to templated external versioner commands
|
||||
if cfg.Folders[i].Versioning.Type == "external" {
|
||||
cfg.Folders[i].Versioning.Params["command"] += " %FOLDER_PATH% %FILE_PATH%"
|
||||
}
|
||||
}
|
||||
|
||||
cfg.Version = 22
|
||||
}
|
||||
|
||||
func convertV20V21(cfg *Configuration) {
|
||||
for _, folder := range cfg.Folders {
|
||||
if folder.FilesystemType != fs.FilesystemTypeBasic {
|
||||
continue
|
||||
}
|
||||
switch folder.Versioning.Type {
|
||||
case "simple", "trashcan":
|
||||
// Clean out symlinks in the known place
|
||||
cleanSymlinks(filepath.Join(folder.Path(), ".stversions"))
|
||||
cleanSymlinks(folder.Filesystem(), ".stversions")
|
||||
case "staggered":
|
||||
versionDir := folder.Versioning.Params["versionsPath"]
|
||||
if versionDir == "" {
|
||||
// default place
|
||||
cleanSymlinks(filepath.Join(folder.Path(), ".stversions"))
|
||||
cleanSymlinks(folder.Filesystem(), ".stversions")
|
||||
} else if filepath.IsAbs(versionDir) {
|
||||
// absolute
|
||||
cleanSymlinks(versionDir)
|
||||
cleanSymlinks(fs.NewFilesystem(fs.FilesystemTypeBasic, versionDir), ".")
|
||||
} else {
|
||||
// relative to folder
|
||||
cleanSymlinks(filepath.Join(folder.Path(), versionDir))
|
||||
cleanSymlinks(folder.Filesystem(), versionDir)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -428,9 +447,7 @@ func convertV17V18(cfg *Configuration) {
|
||||
}
|
||||
|
||||
func convertV16V17(cfg *Configuration) {
|
||||
for i := range cfg.Folders {
|
||||
cfg.Folders[i].Fsync = true
|
||||
}
|
||||
// Fsync = true removed
|
||||
|
||||
cfg.Version = 17
|
||||
}
|
||||
@@ -670,21 +687,21 @@ loop:
|
||||
return devices[0:count]
|
||||
}
|
||||
|
||||
func cleanSymlinks(dir string) {
|
||||
func cleanSymlinks(filesystem fs.Filesystem, dir string) {
|
||||
if runtime.GOOS == "windows" {
|
||||
// We don't do symlinks on Windows. Additionally, there may
|
||||
// be things that look like symlinks that are not, which we
|
||||
// should leave alone. Deduplicated files, for example.
|
||||
return
|
||||
}
|
||||
filepath.Walk(dir, func(path string, info os.FileInfo, err error) error {
|
||||
filesystem.Walk(dir, func(path string, info fs.FileInfo, err error) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if info.Mode()&os.ModeSymlink != 0 {
|
||||
if info.IsSymlink() {
|
||||
l.Infoln("Removing incorrectly versioned symlink", path)
|
||||
os.Remove(path)
|
||||
return filepath.SkipDir
|
||||
filesystem.Remove(path)
|
||||
return fs.SkipDir
|
||||
}
|
||||
return nil
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user