diff --git a/lib/model/devicedownloadstate.go b/lib/model/devicedownloadstate.go index e3c05787..35f0fbd8 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 558d5983..e62e9bfd 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 +}