mirror of
https://github.com/octoleo/syncthing.git
synced 2025-01-25 16:08:25 +00:00
Archive indexes and config from v0.8 on upgrade
This commit is contained in:
parent
4afe02cb21
commit
8bfe4374de
@ -293,7 +293,9 @@ func main() {
|
|||||||
rateBucket = ratelimit.NewBucketWithRate(float64(1000*cfg.Options.MaxSendKbps), int64(5*1000*cfg.Options.MaxSendKbps))
|
rateBucket = ratelimit.NewBucketWithRate(float64(1000*cfg.Options.MaxSendKbps), int64(5*1000*cfg.Options.MaxSendKbps))
|
||||||
}
|
}
|
||||||
|
|
||||||
removeLegacyIndexes()
|
// If this is the first time the user runs v0.9, archive the old indexes and config.
|
||||||
|
archiveLegacyConfig()
|
||||||
|
|
||||||
db, err := leveldb.OpenFile(filepath.Join(confDir, "index"), nil)
|
db, err := leveldb.OpenFile(filepath.Join(confDir, "index"), nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
l.Fatalln("leveldb.OpenFile():", err)
|
l.Fatalln("leveldb.OpenFile():", err)
|
||||||
@ -536,14 +538,39 @@ func resetRepositories() {
|
|||||||
os.RemoveAll(idx)
|
os.RemoveAll(idx)
|
||||||
}
|
}
|
||||||
|
|
||||||
func removeLegacyIndexes() {
|
func archiveLegacyConfig() {
|
||||||
pat := filepath.Join(confDir, "*.idx.gz*")
|
pat := filepath.Join(confDir, "*.idx.gz*")
|
||||||
idxs, err := filepath.Glob(pat)
|
idxs, err := filepath.Glob(pat)
|
||||||
if err == nil {
|
if err == nil && len(idxs) > 0 {
|
||||||
for _, idx := range idxs {
|
// There are legacy indexes. This is probably the first time we run as v0.9.
|
||||||
l.Infof("Reset: Removing %s", idx)
|
backupDir := filepath.Join(confDir, "backup-of-v0.8")
|
||||||
os.Remove(idx)
|
err = os.MkdirAll(backupDir, 0700)
|
||||||
|
if err != nil {
|
||||||
|
l.Warnln("Cannot archive config/indexes:", err)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for _, idx := range idxs {
|
||||||
|
l.Infof("Archiving %s", filepath.Base(idx))
|
||||||
|
os.Rename(idx, filepath.Join(backupDir, filepath.Base(idx)))
|
||||||
|
}
|
||||||
|
|
||||||
|
src, err := os.Open(filepath.Join(confDir, "config.xml"))
|
||||||
|
if err != nil {
|
||||||
|
l.Warnf("Cannot archive config:", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
defer src.Close()
|
||||||
|
|
||||||
|
dst, err := os.Create(filepath.Join(backupDir, "config.xml"))
|
||||||
|
if err != nil {
|
||||||
|
l.Warnf("Cannot archive config:", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
defer src.Close()
|
||||||
|
|
||||||
|
l.Infoln("Archiving config.xml")
|
||||||
|
io.Copy(dst, src)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user