From b193b4b1dfcf4e27050ba76e2d714c0b2c80e014 Mon Sep 17 00:00:00 2001 From: sunnylqm Date: Sun, 22 Aug 2021 11:33:54 +0800 Subject: [PATCH] Check hash more strict --- lib/index.js | 37 +++++++++++++++++++++++++++---------- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/lib/index.js b/lib/index.js index 336d8d2..a3f61d6 100644 --- a/lib/index.js +++ b/lib/index.js @@ -165,6 +165,10 @@ export async function downloadUpdate(options, eventListeners) { logger(`duplicated downloaded hash ${downloadedHash}, ignored`); return; } + if (readyHash) { + logger(`hash ${readyHash} applied. reboot first`); + return; + } if (downloadingThrottling) { logger('repeated downloading, ignored'); return; @@ -215,21 +219,34 @@ export async function downloadUpdate(options, eventListeners) { return options.hash; } -export function switchVersion(hash) { - assertRelease(); - logger('switchVersion'); - Pushy.reloadUpdate({ hash }); -} - let readyHash; -export function switchVersionLater(hash) { - assertRelease(); +function assertHash(hash) { + if (!downloadedHash) { + logger(`no downloaded hash`); + return; + } + if (hash !== downloadedHash) { + logger(`use downloaded hash ${downloadedHash} first`); + return; + } if (readyHash === hash) { - logger(`duplicated ready hash ${readyHash}, ignored`); + logger(`hash ${readyHash} already applied. reboot first.`); return; } readyHash = hash; - logger('switchVersionLater'); +} + +export function switchVersion(hash) { + assertRelease(); + assertHash(hash); + logger('switchVersion: ' + hash); + Pushy.reloadUpdate({ hash }); +} + +export function switchVersionLater(hash) { + assertRelease(); + assertHash(hash); + logger('switchVersionLater: ' + hash); Pushy.setNeedUpdate({ hash }); }