lib/model: Add name of latest modifying device to conflict file (fixes #3524)
GitHub-Pull-Request: https://github.com/syncthing/syncthing/pull/4161 LGTM: AudriusButkevicius, calmh
This commit is contained in:
parent
dd6bb6d5fd
commit
1235cead35
@ -852,7 +852,9 @@ func (f *sendReceiveFolder) deleteFile(file protocol.FileInfo) {
|
|||||||
// of deleting. Also merge with the version vector we had, to indicate
|
// of deleting. Also merge with the version vector we had, to indicate
|
||||||
// we have resolved the conflict.
|
// we have resolved the conflict.
|
||||||
file.Version = file.Version.Merge(cur.Version)
|
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 {
|
} else if f.versioner != nil {
|
||||||
err = osutil.InWritableDir(f.versioner.Archive, realName)
|
err = osutil.InWritableDir(f.versioner.Archive, realName)
|
||||||
} else {
|
} else {
|
||||||
@ -1454,7 +1456,10 @@ func (f *sendReceiveFolder) performFinish(state *sharedPullerState) error {
|
|||||||
// we have resolved the conflict.
|
// we have resolved the conflict.
|
||||||
|
|
||||||
state.file.Version = state.file.Version.Merge(state.version)
|
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
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1661,7 +1666,7 @@ func removeAvailability(availabilities []Availability, availability Availability
|
|||||||
return availabilities
|
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-") {
|
if strings.Contains(filepath.Base(name), ".sync-conflict-") {
|
||||||
l.Infoln("Conflict for", name, "which is already a conflict copy; not copying again.")
|
l.Infoln("Conflict for", name, "which is already a conflict copy; not copying again.")
|
||||||
if err := os.Remove(name); err != nil && !os.IsNotExist(err) {
|
if err := os.Remove(name); err != nil && !os.IsNotExist(err) {
|
||||||
@ -1679,7 +1684,7 @@ func (f *sendReceiveFolder) moveForConflict(name string) error {
|
|||||||
|
|
||||||
ext := filepath.Ext(name)
|
ext := filepath.Ext(name)
|
||||||
withoutExt := name[:len(name)-len(ext)]
|
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)
|
err := os.Rename(name, newName)
|
||||||
if os.IsNotExist(err) {
|
if os.IsNotExist(err) {
|
||||||
// We were supposed to move a file away but it does not exist. Either
|
// We were supposed to move a file away but it does not exist. Either
|
||||||
@ -1689,7 +1694,7 @@ func (f *sendReceiveFolder) moveForConflict(name string) error {
|
|||||||
err = nil
|
err = nil
|
||||||
}
|
}
|
||||||
if f.MaxConflicts > -1 {
|
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 {
|
if gerr == nil && len(matches) > f.MaxConflicts {
|
||||||
sort.Sort(sort.Reverse(sort.StringSlice(matches)))
|
sort.Sort(sort.Reverse(sort.StringSlice(matches)))
|
||||||
for _, match := range matches[f.MaxConflicts:] {
|
for _, match := range matches[f.MaxConflicts:] {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user