lib/model: Discard download progress upon receiving an index update (fixes #2993)

GitHub-Pull-Request: https://github.com/syncthing/syncthing/pull/3023
This commit is contained in:
Audrius Butkevicius 2016-05-01 06:49:29 +00:00 committed by Jakob Borg
parent 49387f9494
commit 29fa05ae05
2 changed files with 28 additions and 0 deletions

View File

@ -97,6 +97,9 @@ type deviceDownloadState struct {
// Update updates internal state of what has been downloaded into the temporary
// files by the remote device for this specific folder.
func (t *deviceDownloadState) Update(folder string, updates []protocol.FileDownloadProgressUpdate) {
if t == nil {
return
}
t.mut.RLock()
f, ok := t.folders[folder]
t.mut.RUnlock()

View File

@ -556,6 +556,10 @@ func (m *Model) Index(deviceID protocol.DeviceID, folder string, fs []protocol.F
l.Fatalf("Index for nonexistant folder %q", folder)
}
m.pmut.RLock()
m.deviceDownloads[deviceID].Update(folder, makeForgetUpdate(fs))
m.pmut.RUnlock()
fs = filterIndex(folder, fs, cfg.IgnoreDelete, ignores)
files.Replace(deviceID, fs)
@ -593,6 +597,10 @@ func (m *Model) IndexUpdate(deviceID protocol.DeviceID, folder string, fs []prot
l.Fatalf("IndexUpdate for nonexistant folder %q", folder)
}
m.pmut.RLock()
m.deviceDownloads[deviceID].Update(folder, makeForgetUpdate(fs))
m.pmut.RUnlock()
fs = filterIndex(folder, fs, cfg.IgnoreDelete, ignores)
files.Update(deviceID, fs)
@ -2216,3 +2224,20 @@ next:
return cleaned
}
// makeForgetUpdate takes an index update and constructs a download progress update
// causing to forget any progress for files which we've just been sent.
func makeForgetUpdate(files []protocol.FileInfo) []protocol.FileDownloadProgressUpdate {
updates := make([]protocol.FileDownloadProgressUpdate, 0, len(files))
for _, file := range files {
if file.IsSymlink() || file.IsDirectory() || file.IsDeleted() {
continue
}
updates = append(updates, protocol.FileDownloadProgressUpdate{
Name: file.Name,
Version: file.Version,
UpdateType: protocol.UpdateTypeForget,
})
}
return updates
}