diff options
author | Audrius Butkevicius <audrius.butkevicius@gmail.com> | 2016-05-01 06:49:29 +0000 |
---|---|---|
committer | Jakob Borg <jakob@nym.se> | 2016-05-01 06:49:29 +0000 |
commit | 29fa05ae0580e9a707171af7f0b00de6b92a5be8 (patch) | |
tree | 027ade34bcdc58e9013f38f63577e96c6d55a741 | |
parent | 49387f9494446c62baa39365772bfa7dcec581e0 (diff) |
lib/model: Discard download progress upon receiving an index update (fixes #2993)
GitHub-Pull-Request: https://github.com/syncthing/syncthing/pull/3023
-rw-r--r-- | lib/model/devicedownloadstate.go | 3 | ||||
-rw-r--r-- | lib/model/model.go | 25 |
2 files changed, 28 insertions, 0 deletions
diff --git a/lib/model/devicedownloadstate.go b/lib/model/devicedownloadstate.go index e3c05787fb..35f0fbd8dd 100644 --- a/lib/model/devicedownloadstate.go +++ b/lib/model/devicedownloadstate.go @@ -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() diff --git a/lib/model/model.go b/lib/model/model.go index 558d598371..e62e9bfd52 100644 --- a/lib/model/model.go +++ b/lib/model/model.go @@ -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 +} |