浏览代码

gui, lib/model: Prevent negative sync completion (fixes #4570) (#6248)

Simon Frei 5 年之前
父节点
当前提交
f56a5545d4
共有 2 个文件被更改,包括 12 次插入2 次删除
  1. 7 2
      gui/default/syncthing/core/syncthingController.js
  2. 5 0
      lib/model/model.go

+ 7 - 2
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);
         };

+ 5 - 0
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
 }