diff options
author | Jakob Borg <jakob@nym.se> | 2014-06-15 20:31:26 +0200 |
---|---|---|
committer | Jakob Borg <jakob@nym.se> | 2014-06-15 20:31:26 +0200 |
commit | 5fa8f8e50ca09977753686485ce4863df58a7e61 (patch) | |
tree | 0db4514d3b0c4aee0b4e3495092bce7abdd265c4 | |
parent | 9ca87f53149e28c15bdbcdf0a7d2dfcc0406ff51 (diff) |
Remove old index files on startup (fixes #366)
-rw-r--r-- | cmd/syncthing/main.go | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/cmd/syncthing/main.go b/cmd/syncthing/main.go index 485bb08be0..7f6f5a2aad 100644 --- a/cmd/syncthing/main.go +++ b/cmd/syncthing/main.go @@ -5,6 +5,7 @@ package main import ( + "crypto/sha1" "crypto/tls" "flag" "fmt" @@ -353,6 +354,29 @@ func main() { m.ScanRepos() m.SaveIndexes(confDir) + // Remove all .idx* files that don't belong to an active repo. + + validIndexes := make(map[string]bool) + for _, repo := range cfg.Repositories { + dir := expandTilde(repo.Directory) + id := fmt.Sprintf("%x", sha1.Sum([]byte(dir))) + validIndexes[id] = true + } + + allIndexes, err := filepath.Glob(filepath.Join(confDir, "*.idx*")) + if err == nil { + for _, idx := range allIndexes { + bn := filepath.Base(idx) + fs := strings.Split(bn, ".") + if len(fs) > 1 { + if _, ok := validIndexes[fs[0]]; !ok { + l.Infoln("Removing old index", bn) + os.Remove(idx) + } + } + } + } + // UPnP var externalPort = 0 |