Skip to content

Commit

Permalink
lib/model: Add name of latest modifying device to conflict file (fixes
Browse files Browse the repository at this point in the history
…syncthing#3524)

GitHub-Pull-Request: syncthing#4161
LGTM: AudriusButkevicius, calmh
  • Loading branch information
nrm21 authored and calmh committed May 25, 2017
1 parent dd6bb6d commit 1235cea
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions lib/model/rwfolder.go
Original file line number Diff line number Diff line change
Expand Up @@ -852,7 +852,9 @@ func (f *sendReceiveFolder) deleteFile(file protocol.FileInfo) {
// of deleting. Also merge with the version vector we had, to indicate
// we have resolved the conflict.
file.Version = file.Version.Merge(cur.Version)
err = osutil.InWritableDir(f.moveForConflict, realName)
err = osutil.InWritableDir(func(name string) error {
return f.moveForConflict(name, file.ModifiedBy.String())
}, realName)
} else if f.versioner != nil {
err = osutil.InWritableDir(f.versioner.Archive, realName)
} else {
Expand Down Expand Up @@ -1454,7 +1456,10 @@ func (f *sendReceiveFolder) performFinish(state *sharedPullerState) error {
// we have resolved the conflict.

state.file.Version = state.file.Version.Merge(state.version)
if err = osutil.InWritableDir(f.moveForConflict, state.realName); err != nil {
err = osutil.InWritableDir(func(name string) error {
return f.moveForConflict(name, state.file.ModifiedBy.String())
}, state.realName)
if err != nil {
return err
}

Expand Down Expand Up @@ -1661,7 +1666,7 @@ func removeAvailability(availabilities []Availability, availability Availability
return availabilities
}

func (f *sendReceiveFolder) moveForConflict(name string) error {
func (f *sendReceiveFolder) moveForConflict(name string, lastModBy string) error {
if strings.Contains(filepath.Base(name), ".sync-conflict-") {
l.Infoln("Conflict for", name, "which is already a conflict copy; not copying again.")
if err := os.Remove(name); err != nil && !os.IsNotExist(err) {
Expand All @@ -1679,7 +1684,7 @@ func (f *sendReceiveFolder) moveForConflict(name string) error {

ext := filepath.Ext(name)
withoutExt := name[:len(name)-len(ext)]
newName := withoutExt + time.Now().Format(".sync-conflict-20060102-150405") + ext
newName := withoutExt + time.Now().Format(".sync-conflict-20060102-150405-") + lastModBy + ext
err := os.Rename(name, newName)
if os.IsNotExist(err) {
// We were supposed to move a file away but it does not exist. Either
Expand All @@ -1689,7 +1694,7 @@ func (f *sendReceiveFolder) moveForConflict(name string) error {
err = nil
}
if f.MaxConflicts > -1 {
matches, gerr := osutil.Glob(withoutExt + ".sync-conflict-????????-??????" + ext)
matches, gerr := osutil.Glob(withoutExt + ".sync-conflict-????????-??????*" + ext)
if gerr == nil && len(matches) > f.MaxConflicts {
sort.Sort(sort.Reverse(sort.StringSlice(matches)))
for _, match := range matches[f.MaxConflicts:] {
Expand Down

0 comments on commit 1235cea

Please sign in to comment.