Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lib/model: Don't crash when taking rename shortcut (fixes #6654) #6657

Merged
merged 1 commit into from
May 17, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 11 additions & 6 deletions lib/model/folder_sendrecv.go
Original file line number Diff line number Diff line change
Expand Up @@ -460,12 +460,7 @@ nextFile:
// Check our list of files to be removed for a match, in which case
// we can just do a rename instead.
key := string(fi.BlocksHash)
for i, candidate := range buckets[key] {
// Remove the candidate from the bucket
lidx := len(buckets[key]) - 1
buckets[key][i] = buckets[key][lidx]
buckets[key] = buckets[key][:lidx]

for candidate, ok := popCandidate(buckets, key); ok; candidate, ok = popCandidate(buckets, key) {
// candidate is our current state of the file, where as the
// desired state with the delete bit set is in the deletion
// map.
Expand Down Expand Up @@ -498,6 +493,16 @@ nextFile:
return changed, fileDeletions, dirDeletions, nil
}

func popCandidate(buckets map[string][]protocol.FileInfo, key string) (protocol.FileInfo, bool) {
cands := buckets[key]
if len(cands) == 0 {
return protocol.FileInfo{}, false
}

buckets[key] = cands[1:]
return cands[0], true
}

func (f *sendReceiveFolder) processDeletions(fileDeletions map[string]protocol.FileInfo, dirDeletions []protocol.FileInfo, snap *db.Snapshot, dbUpdateChan chan<- dbUpdateJob, scanChan chan<- string) {
for _, file := range fileDeletions {
select {
Expand Down