mirror of
https://github.com/octoleo/syncthing.git
synced 2024-11-09 23:00:58 +00:00
Move .stversions to repo root only (fixes #364)
This commit is contained in:
parent
f510f5f205
commit
dbb4b67205
@ -309,8 +309,8 @@ func (p *puller) fixupDirectories() {
|
||||
err := os.Remove(dir)
|
||||
if err == nil {
|
||||
deleted++
|
||||
} else if p.versioner == nil { // Failures are expected in the presence of versioning
|
||||
l.Warnln(err)
|
||||
} else {
|
||||
l.Warnln("Delete dir:", err)
|
||||
}
|
||||
}
|
||||
|
||||
@ -569,8 +569,13 @@ func (p *puller) handleEmptyBlock(b bqBlock) {
|
||||
os.Remove(of.temp)
|
||||
os.Chmod(of.filepath, 0666)
|
||||
if p.versioner != nil {
|
||||
if err := p.versioner.Archive(of.filepath); err == nil {
|
||||
if debug {
|
||||
l.Debugln("pull: deleting with versioner")
|
||||
}
|
||||
if err := p.versioner.Archive(p.repoCfg.Directory, of.filepath); err == nil {
|
||||
p.model.updateLocal(p.repoCfg.ID, f)
|
||||
} else if debug {
|
||||
l.Debugln("pull: error:", err)
|
||||
}
|
||||
} else if err := os.Remove(of.filepath); err == nil || os.IsNotExist(err) {
|
||||
p.model.updateLocal(p.repoCfg.ID, f)
|
||||
@ -666,7 +671,7 @@ func (p *puller) closeFile(f scanner.File) {
|
||||
osutil.ShowFile(of.temp)
|
||||
|
||||
if p.versioner != nil {
|
||||
err := p.versioner.Archive(of.filepath)
|
||||
err := p.versioner.Archive(p.repoCfg.Directory, of.filepath)
|
||||
if err != nil {
|
||||
if debug {
|
||||
l.Debugf("pull: error: %q / %q: %v", p.repoCfg.ID, f.Name, err)
|
||||
|
@ -43,27 +43,51 @@ func NewSimple(params map[string]string) Versioner {
|
||||
|
||||
// Move away the named file to a version archive. If this function returns
|
||||
// nil, the named file does not exist any more (has been archived).
|
||||
func (v Simple) Archive(path string) error {
|
||||
_, err := os.Stat(path)
|
||||
func (v Simple) Archive(repoPath, filePath string) error {
|
||||
_, err := os.Stat(filePath)
|
||||
if err != nil && os.IsNotExist(err) {
|
||||
if debug {
|
||||
l.Debugln("not archiving nonexistent file", filePath)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
versionsDir := filepath.Join(repoPath, ".stversions")
|
||||
_, err = os.Stat(versionsDir)
|
||||
if err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
if debug {
|
||||
l.Debugln("archiving", path)
|
||||
l.Debugln("creating versions dir", versionsDir)
|
||||
}
|
||||
os.MkdirAll(versionsDir, 0755)
|
||||
osutil.HideFile(versionsDir)
|
||||
} else {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
file := filepath.Base(path)
|
||||
dir := filepath.Join(filepath.Dir(path), ".stversions")
|
||||
if debug {
|
||||
l.Debugln("archiving", filePath)
|
||||
}
|
||||
|
||||
file := filepath.Base(filePath)
|
||||
inRepoPath, err := filepath.Rel(repoPath, filepath.Dir(filePath))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
dir := filepath.Join(versionsDir, inRepoPath)
|
||||
err = os.MkdirAll(dir, 0755)
|
||||
if err != nil && !os.IsExist(err) {
|
||||
return err
|
||||
} else {
|
||||
osutil.HideFile(dir)
|
||||
}
|
||||
|
||||
ver := file + "~" + time.Now().Format("20060102-150405")
|
||||
err = osutil.Rename(path, filepath.Join(dir, ver))
|
||||
dst := filepath.Join(dir, ver)
|
||||
if debug {
|
||||
l.Debugln("moving to", dst)
|
||||
}
|
||||
err = osutil.Rename(filePath, dst)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -77,6 +101,9 @@ func (v Simple) Archive(path string) error {
|
||||
if len(versions) > v.keep {
|
||||
sort.Strings(versions)
|
||||
for _, toRemove := range versions[:len(versions)-v.keep] {
|
||||
if debug {
|
||||
l.Debugln("cleaning out", toRemove)
|
||||
}
|
||||
err = os.Remove(toRemove)
|
||||
if err != nil {
|
||||
l.Warnln(err)
|
||||
|
@ -5,7 +5,7 @@
|
||||
package versioner
|
||||
|
||||
type Versioner interface {
|
||||
Archive(path string) error
|
||||
Archive(repoPath, filePath string) error
|
||||
}
|
||||
|
||||
var Factories = map[string]func(map[string]string) Versioner{}
|
||||
|
Loading…
Reference in New Issue
Block a user