diff --git a/lib/config/config.go b/lib/config/config.go index 6170ddea..80cb8635 100644 --- a/lib/config/config.go +++ b/lib/config/config.go @@ -389,8 +389,6 @@ func convertV20V21(cfg *Configuration) { } } - // there is also a symlink recovery step in Model.StartFolder() - cfg.Version = 21 } diff --git a/lib/model/model.go b/lib/model/model.go index 191fcec4..7f69c205 100644 --- a/lib/model/model.go +++ b/lib/model/model.go @@ -178,13 +178,8 @@ func (m *Model) StartDeadlockDetector(timeout time.Duration) { func (m *Model) StartFolder(folder string) { m.fmut.Lock() m.pmut.Lock() - folderCfg := m.folderCfgs[folder] - - if folderCfg.Versioning.Type != "" && m.cfg.RawCopy().OriginalVersion < 21 { - m.attemptSymlinkRecovery(folderCfg) - } - folderType := m.startFolderLocked(folder) + folderCfg := m.folderCfgs[folder] m.pmut.Unlock() m.fmut.Unlock() @@ -2726,76 +2721,3 @@ func rootedJoinedPath(root, rel string) (string, error) { return joined, nil } - -func (m *Model) attemptSymlinkRecovery(fcfg config.FolderConfiguration) { - fs, ok := m.folderFiles[fcfg.ID] - if !ok { - return - } - - // The window during which we had a broken release out, roughly. - startDate := time.Date(2017, 8, 8, 6, 0, 0, 0, time.UTC) - endDate := time.Date(2017, 8, 8, 12, 0, 0, 0, time.UTC) - - // Look through all our files looking for deleted symlinks. - fs.WithHave(protocol.LocalDeviceID, func(intf db.FileIntf) bool { - if !intf.IsSymlink() { - return true - } - - symlinkPath, err := rootedJoinedPath(fcfg.Path(), intf.FileName()) - if err != nil { - // odd - return true - } - - if _, err := os.Lstat(symlinkPath); err == nil { - // The symlink exists. Our work here is done. - return true - } - - fi := intf.(protocol.FileInfo) - if !fi.Deleted && fi.SymlinkTarget != "" { - // We haven't noticed the delete and put it into the - // index yet. Great! We can restore the symlink. - l.Infoln("Restoring incorrectly deleted symlink", symlinkPath) - os.Symlink(fi.SymlinkTarget, symlinkPath) - return true - } - - // It's deleted. Check if it was deleted in the bad window. - if fi.ModTime().Before(startDate) || !fi.ModTime().Before(endDate) { - return true - } - - // Try to find an older index entry. - for deviceID := range m.cfg.Devices() { - olderFI, ok := fs.Get(deviceID, fi.Name) - if !ok { - // This device doesn't have it. - continue - } - if olderFI.Deleted || !olderFI.IsSymlink() { - // The device has something deleted or not a - // symlink, doesn't help us. - continue - } - if olderFI.Version.GreaterEqual(fi.Version) { - // The device has something newer. We should - // chill and let the puller handle it. No - // need to look further for this specific - // symlink. - return true - } - - if olderFI.SymlinkTarget != "" { - // It has symlink data. Restore the symlink. - l.Infoln("Restoring incorrectly deleted symlink", symlinkPath) - os.Symlink(olderFI.SymlinkTarget, symlinkPath) - return true - } - } - - return true - }) -} diff --git a/lib/model/model_test.go b/lib/model/model_test.go index 0aa1d456..a8597ce9 100644 --- a/lib/model/model_test.go +++ b/lib/model/model_test.go @@ -141,67 +141,6 @@ func TestRequest(t *testing.T) { } } -func TestSymlinkRecovery(t *testing.T) { - if runtime.GOOS == "windows" { - t.Skip("symlinks not supported on Windows") - } - - ldb := db.OpenMemory() - - fs := db.NewFileSet("default", ldb) - - // device1 has an old entry - fs.Update(device1, []protocol.FileInfo{ - { - Name: "symlink-to-restore", - Type: protocol.FileInfoTypeSymlink, - Version: protocol.Vector{Counters: []protocol.Counter{{ID: 1, Value: 42}}}, - SymlinkTarget: "/tmp", - }, - }) - - badTime := time.Date(2017, 8, 8, 9, 0, 0, 0, time.UTC).Unix() - - // we have deleted it - fs.Update(protocol.LocalDeviceID, []protocol.FileInfo{ - { - Name: "symlink-to-restore", - Deleted: true, - ModifiedS: badTime, - Type: protocol.FileInfoTypeSymlink, - Version: protocol.Vector{Counters: []protocol.Counter{{ID: 1, Value: 42}, {ID: 2, Value: 1}}}, - }, - }) - - // Ensure the symlink does in fact not exist - symlinkPath := filepath.Join(defaultFolderConfig.Path(), "symlink-to-restore") - os.Remove(symlinkPath) - defer os.Remove(symlinkPath) - if _, err := os.Lstat(symlinkPath); err == nil { - t.Fatal("symlink should not exist") - } - - // Start up - m := NewModel(defaultConfig, protocol.LocalDeviceID, "syncthing", "dev", ldb, nil) - - folderCfg := defaultFolderConfig - folderCfg.Versioning = config.VersioningConfiguration{ - Type: "simple", - } - - m.AddFolder(folderCfg) - m.StartFolder("default") - m.ServeBackground() - defer m.Stop() - m.ScanFolder("default") - - // The symlink should have been restored as part of the StartFolder() - - if _, err := os.Lstat(symlinkPath); err != nil { - t.Error("should have restored symlink") - } -} - func genFiles(n int) []protocol.FileInfo { files := make([]protocol.FileInfo, n) t := time.Now().Unix()