From c670fbc9b03ba6da1eaaee753e4e5be35d8d70c0 Mon Sep 17 00:00:00 2001 From: Tobias Klein Date: Fri, 5 Nov 2021 15:55:33 +0100 Subject: [PATCH] assistant_controller / Gracefully handle situation when one or two repositories fail to update (see #395) --- .../module_assistant/assistant_controller.js | 31 +++++++++++++++---- 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/app/frontend/components/module_assistant/assistant_controller.js b/app/frontend/components/module_assistant/assistant_controller.js index a93494dff..4b4486edb 100644 --- a/app/frontend/components/module_assistant/assistant_controller.js +++ b/app/frontend/components/module_assistant/assistant_controller.js @@ -170,20 +170,39 @@ module.exports.updateRepositories = async function() { if (updateInProgress) { return; } - updateInProgress = true; - - preserveSelectedState(); + updateInProgress = true; + preserveSelectedState(); await notifySubscribers('startUpdate'); - const status = await ipcNsi.updateRepositoryConfig(process => notifySubscribers('progressUpdate', process)); - if (status == 0) { + + const MAX_FAILED_UPDATE_COUNT = 2; + var failedUpdateCount = 0; + const repoUpdateStatus = await ipcNsi.updateRepositoryConfig(process => notifySubscribers('progressUpdate', process)); + + for (var key in repoUpdateStatus) { + if (key != 'result' && repoUpdateStatus[key] == false) { + failedUpdateCount += 1; + console.warn("Repo update failed for " + key); + } + } + + if (failedUpdateCount > 0) { + console.warn("Total failed updates: " + failedUpdateCount); + } + + var overallStatus = 0; + if (failedUpdateCount > MAX_FAILED_UPDATE_COUNT) { + overallStatus = -1; + } + + if (overallStatus == 0) { restoreSelectedState(); const today = new Date(); state.reposUpdated = today; await ipcSettings.set('lastSwordRepoUpdate', today); } - await notifySubscribers('completedUpdate', status); + await notifySubscribers('completedUpdate', overallStatus); updateInProgress = false; };