mirror of
https://github.com/octoleo/syncthing.git
synced 2025-01-03 15:17:25 +00:00
Merge pull request #1319 from AudriusButkevicius/renames
Fix issues with renames
This commit is contained in:
commit
5d9a41f712
@ -334,8 +334,9 @@ func (p *Puller) pullerIteration(ignores *ignore.Matcher) int {
|
|||||||
df, ok := p.model.CurrentFolderFile(p.folder, file.Name)
|
df, ok := p.model.CurrentFolderFile(p.folder, file.Name)
|
||||||
// Local file can be already deleted, but with a lower version
|
// Local file can be already deleted, but with a lower version
|
||||||
// number, hence the deletion coming in again as part of
|
// number, hence the deletion coming in again as part of
|
||||||
// WithNeed
|
// WithNeed, furthermore, the file can simply be of the wrong
|
||||||
if ok && !df.IsDeleted() {
|
// type if we haven't yet managed to pull it.
|
||||||
|
if ok && !df.IsDeleted() && !df.IsSymlink() && !df.IsDirectory() {
|
||||||
// Put files into buckets per first hash
|
// Put files into buckets per first hash
|
||||||
key := string(df.Blocks[0].Hash)
|
key := string(df.Blocks[0].Hash)
|
||||||
buckets[key] = append(buckets[key], df)
|
buckets[key] = append(buckets[key], df)
|
||||||
@ -343,6 +344,9 @@ func (p *Puller) pullerIteration(ignores *ignore.Matcher) int {
|
|||||||
}
|
}
|
||||||
case file.IsDirectory() && !file.IsSymlink():
|
case file.IsDirectory() && !file.IsSymlink():
|
||||||
// A new or changed directory
|
// A new or changed directory
|
||||||
|
if debug {
|
||||||
|
l.Debugln("Creating directory", file.Name)
|
||||||
|
}
|
||||||
p.handleDir(file)
|
p.handleDir(file)
|
||||||
default:
|
default:
|
||||||
// A new or changed file or symlink. This is the only case where we
|
// A new or changed file or symlink. This is the only case where we
|
||||||
@ -370,19 +374,25 @@ nextFile:
|
|||||||
|
|
||||||
// Local file can be already deleted, but with a lower version
|
// Local file can be already deleted, but with a lower version
|
||||||
// number, hence the deletion coming in again as part of
|
// number, hence the deletion coming in again as part of
|
||||||
// WithNeed
|
// WithNeed, furthermore, the file can simply be of the wrong type if
|
||||||
if !f.IsSymlink() && !f.IsDeleted() {
|
// the global index changed while we were processing this iteration.
|
||||||
|
if !f.IsDeleted() && !f.IsSymlink() && !f.IsDirectory() {
|
||||||
key := string(f.Blocks[0].Hash)
|
key := string(f.Blocks[0].Hash)
|
||||||
for i, candidate := range buckets[key] {
|
for i, candidate := range buckets[key] {
|
||||||
if scanner.BlocksEqual(candidate.Blocks, f.Blocks) {
|
if scanner.BlocksEqual(candidate.Blocks, f.Blocks) {
|
||||||
// Remove the candidate from the bucket
|
// Remove the candidate from the bucket
|
||||||
l := len(buckets[key]) - 1
|
lidx := len(buckets[key]) - 1
|
||||||
buckets[key][i] = buckets[key][l]
|
buckets[key][i] = buckets[key][lidx]
|
||||||
buckets[key] = buckets[key][:l]
|
buckets[key] = buckets[key][:lidx]
|
||||||
|
|
||||||
|
// candidate is our current state of the file, where as the
|
||||||
|
// desired state with the delete bit set is in the deletion
|
||||||
|
// map.
|
||||||
|
desired := fileDeletions[candidate.Name]
|
||||||
// Remove the pending deletion (as we perform it by renaming)
|
// Remove the pending deletion (as we perform it by renaming)
|
||||||
delete(fileDeletions, candidate.Name)
|
delete(fileDeletions, candidate.Name)
|
||||||
|
|
||||||
p.renameFile(candidate, f)
|
p.renameFile(desired, f)
|
||||||
|
|
||||||
p.queue.Done(fileName)
|
p.queue.Done(fileName)
|
||||||
continue nextFile
|
continue nextFile
|
||||||
@ -408,11 +418,18 @@ nextFile:
|
|||||||
doneWg.Wait()
|
doneWg.Wait()
|
||||||
|
|
||||||
for _, file := range fileDeletions {
|
for _, file := range fileDeletions {
|
||||||
|
if debug {
|
||||||
|
l.Debugln("Deleting file", file.Name)
|
||||||
|
}
|
||||||
p.deleteFile(file)
|
p.deleteFile(file)
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := range dirDeletions {
|
for i := range dirDeletions {
|
||||||
p.deleteDir(dirDeletions[len(dirDeletions)-i-1])
|
dir := dirDeletions[len(dirDeletions)-i-1]
|
||||||
|
if debug {
|
||||||
|
l.Debugln("Deleting dir", dir.Name)
|
||||||
|
}
|
||||||
|
p.deleteDir(dir)
|
||||||
}
|
}
|
||||||
|
|
||||||
return changed
|
return changed
|
||||||
|
Loading…
Reference in New Issue
Block a user