mirror of
https://github.com/octoleo/syncthing.git
synced 2025-01-08 17:24:08 +00:00
Merge pull request #1070 from AudriusButkevicius/staggered
Use unique versions in staggered versioner (fixes #1063)
This commit is contained in:
commit
97abdaca5a
@ -18,7 +18,6 @@ package versioner
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"sort"
|
||||
"strconv"
|
||||
|
||||
"github.com/syncthing/syncthing/internal/osutil"
|
||||
@ -124,10 +123,9 @@ func (v Simple) Archive(filePath string) error {
|
||||
|
||||
// Use all the found filenames. "~" sorts after "." so all old pattern
|
||||
// files will be deleted before any new, which is as it should be.
|
||||
versions := append(oldVersions, newVersions...)
|
||||
versions := uniqueSortedStrings(append(oldVersions, newVersions...))
|
||||
|
||||
if len(versions) > v.keep {
|
||||
sort.Strings(versions)
|
||||
for _, toRemove := range versions[:len(versions)-v.keep] {
|
||||
if debug {
|
||||
l.Debugln("cleaning out", toRemove)
|
||||
|
@ -18,7 +18,6 @@ package versioner
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
@ -357,9 +356,7 @@ func (v Staggered) Archive(filePath string) error {
|
||||
|
||||
// Use all the found filenames.
|
||||
versions := append(oldVersions, newVersions...)
|
||||
|
||||
sort.Strings(versions)
|
||||
v.expire(versions)
|
||||
v.expire(uniqueSortedStrings(versions))
|
||||
|
||||
return nil
|
||||
}
|
||||
|
@ -18,6 +18,7 @@ package versioner
|
||||
import (
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"sort"
|
||||
)
|
||||
|
||||
// Inserts ~tag just before the extension of the filename.
|
||||
@ -40,3 +41,17 @@ func filenameTag(path string) string {
|
||||
}
|
||||
return match[1]
|
||||
}
|
||||
|
||||
func uniqueSortedStrings(strings []string) []string {
|
||||
seen := make(map[string]struct{}, len(strings))
|
||||
unique := make([]string, 0, len(strings))
|
||||
for _, str := range strings {
|
||||
_, ok := seen[str]
|
||||
if !ok {
|
||||
seen[str] = struct{}{}
|
||||
unique = append(unique, str)
|
||||
}
|
||||
}
|
||||
sort.Strings(unique)
|
||||
return unique
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user