committed by
Jakob Borg
parent
bf744ded31
commit
afde0727fe
@@ -7,12 +7,10 @@
|
||||
package versioner
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/syncthing/syncthing/lib/fs"
|
||||
"github.com/syncthing/syncthing/lib/util"
|
||||
)
|
||||
|
||||
func init() {
|
||||
@@ -50,35 +48,12 @@ func (v Simple) Archive(filePath string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
file := filepath.Base(filePath)
|
||||
dir := filepath.Dir(filePath)
|
||||
|
||||
// Glob according to the new file~timestamp.ext pattern.
|
||||
pattern := filepath.Join(dir, TagFilename(file, TimeGlob))
|
||||
newVersions, err := v.versionsFs.Glob(pattern)
|
||||
if err != nil {
|
||||
l.Warnln("globbing:", err, "for", pattern)
|
||||
return nil
|
||||
}
|
||||
|
||||
// Also according to the old file.ext~timestamp pattern.
|
||||
pattern = filepath.Join(dir, file+"~"+TimeGlob)
|
||||
oldVersions, err := v.versionsFs.Glob(pattern)
|
||||
if err != nil {
|
||||
l.Warnln("globbing:", err, "for", pattern)
|
||||
return nil
|
||||
}
|
||||
|
||||
// Use all the found filenames.
|
||||
versions := util.UniqueTrimmedStrings(append(oldVersions, newVersions...))
|
||||
|
||||
// Amend with mtime, sort on mtime, delete the oldest first. Mtime,
|
||||
// nowadays at least, is the time when the archiving happened.
|
||||
versionsWithMtimes := versionsToVersionsWithMtime(v.versionsFs, versions)
|
||||
if len(versionsWithMtimes) > v.keep {
|
||||
for _, toRemove := range versionsWithMtimes[:len(versionsWithMtimes)-v.keep] {
|
||||
// Versions are sorted by timestamp in the file name, oldest first.
|
||||
versions := findAllVersions(v.versionsFs, filePath)
|
||||
if len(versions) > v.keep {
|
||||
for _, toRemove := range versions[:len(versions)-v.keep] {
|
||||
l.Debugln("cleaning out", toRemove)
|
||||
err = v.versionsFs.Remove(toRemove.name)
|
||||
err = v.versionsFs.Remove(toRemove)
|
||||
if err != nil {
|
||||
l.Warnln("removing old version:", err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user