gui: Add addresses for disconnected devices (fixes #3340)

Also fixes an issue where the discovery cache call would only return the
newest cache entry for a given device instead of the merged addresses
from all cache entries (which is more useful).

GitHub-Pull-Request: https://github.com/syncthing/syncthing/pull/3344
This commit is contained in:
Jakob Borg
2016-06-26 10:47:23 +00:00
committed by Audrius Butkevicius
parent b0d03d1f1c
commit ac3b03881a
6 changed files with 52 additions and 26 deletions

View File

@@ -12,6 +12,7 @@ import (
"strconv"
"github.com/syncthing/syncthing/lib/osutil"
"github.com/syncthing/syncthing/lib/util"
)
func init() {
@@ -102,7 +103,7 @@ 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 := uniqueSortedStrings(append(oldVersions, newVersions...))
versions := util.UniqueStrings(append(oldVersions, newVersions...))
if len(versions) > v.keep {
for _, toRemove := range versions[:len(versions)-v.keep] {

View File

@@ -14,6 +14,7 @@ import (
"github.com/syncthing/syncthing/lib/osutil"
"github.com/syncthing/syncthing/lib/sync"
"github.com/syncthing/syncthing/lib/util"
)
func init() {
@@ -280,7 +281,7 @@ func (v Staggered) Archive(filePath string) error {
// Use all the found filenames.
versions := append(oldVersions, newVersions...)
v.expire(uniqueSortedStrings(versions))
v.expire(util.UniqueStrings(versions))
return nil
}

View File

@@ -9,7 +9,6 @@ package versioner
import (
"path/filepath"
"regexp"
"sort"
)
// Inserts ~tag just before the extension of the filename.
@@ -32,17 +31,3 @@ 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
}