From f56a5545d4b0d4036d6b176d0d9d639ad3cf9304 Mon Sep 17 00:00:00 2001 From: Simon Frei Date: Fri, 3 Jan 2020 14:07:57 +0100 Subject: [PATCH] gui, lib/model: Prevent negative sync completion (fixes #4570) (#6248) --- gui/default/syncthing/core/syncthingController.js | 9 +++++++-- lib/model/model.go | 5 +++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/gui/default/syncthing/core/syncthingController.js b/gui/default/syncthing/core/syncthingController.js index 1bab5e46e..eb6b9c78c 100755 --- a/gui/default/syncthing/core/syncthingController.js +++ b/gui/default/syncthing/core/syncthingController.js @@ -849,10 +849,15 @@ angular.module('syncthing.core') if (typeof $scope.model[folder] === 'undefined') { return 100; } - if ($scope.model[folder].globalBytes === 0) { + if ($scope.model[folder].needTotalItems === 0) { return 100; } - + if ($scope.model[folder].needBytes == 0 && $scope.model[folder].needDeletes > 0) { + // We don't need any data, but we have deletes that we need + // to do. Drop down the completion percentage to indicate + // that we have stuff to do. + return 95; + } var pct = 100 * $scope.model[folder].inSyncBytes / $scope.model[folder].globalBytes; return Math.floor(pct); }; diff --git a/lib/model/model.go b/lib/model/model.go index e635dc6c6..3cc96b17d 100644 --- a/lib/model/model.go +++ b/lib/model/model.go @@ -894,6 +894,11 @@ func (m *model) NeedSize(folder string) db.Counts { }) } result.Bytes -= m.progressEmitter.BytesCompleted(folder) + // This may happen if we are in progress of pulling files that were + // deleted globally after the pull started. + if result.Bytes < 0 { + result.Bytes = 0 + } l.Debugf("%v NeedSize(%q): %v", m, folder, result) return result }