From b6a489c2247fb87248e827cfc2d7eefe83a13f25 Mon Sep 17 00:00:00 2001 From: qlrddev Date: Fri, 20 Dec 2024 13:26:43 -0300 Subject: [PATCH] added exception treatment on shutil operations o airgap_update_screen --- src/app/screens/airgap_update_screen.py | 73 ++++++++++++++----------- 1 file changed, 42 insertions(+), 31 deletions(-) diff --git a/src/app/screens/airgap_update_screen.py b/src/app/screens/airgap_update_screen.py index c37bc99..16e86bc 100644 --- a/src/app/screens/airgap_update_screen.py +++ b/src/app/screens/airgap_update_screen.py @@ -52,37 +52,48 @@ def on_press(instance): def on_release(instance): new_firmware_bin = os.path.normpath(os.path.join(drive, "firmware.bin")) new_firmware_sig = os.path.normpath(os.path.join(drive, "firmware.bin.sig")) - shutil.copyfile(self.firmware_bin, new_firmware_bin) - shutil.copyfile(self.firmware_sig, new_firmware_sig) - - # After copy, make sha256 hash to show - sha256 = Sha256Verifyer(filename=new_firmware_bin) - sha256.load() - - # Now update the next screen - warn_screen = self.manager.get_screen("WarningAfterAirgapUpdateScreen") - - fns = [ - partial( - warn_screen.update, - name=self.name, - key="sdcard", - value=drive, - ), - partial( - warn_screen.update, - name=self.name, - key="hash", - value=sha256.data.split(" ", maxsplit=1)[0], - ), - partial(warn_screen.update, name=self.name, key="label"), - ] - - for fn in fns: - Clock.schedule_once(fn, 0) - - self.set_background(wid=instance.id, rgba=(0, 0, 0, 1)) - self.set_screen(name="WarningAfterAirgapUpdateScreen", direction="left") + try: + shutil.copyfile(self.firmware_bin, new_firmware_bin) + shutil.copyfile(self.firmware_sig, new_firmware_sig) + + # After copy, make sha256 hash to show + sha256 = Sha256Verifyer(filename=new_firmware_bin) + sha256.load() + + # Now update the next screen + warn_screen = self.manager.get_screen("WarningAfterAirgapUpdateScreen") + + fns = [ + partial( + warn_screen.update, + name=self.name, + key="sdcard", + value=drive, + ), + partial( + warn_screen.update, + name=self.name, + key="hash", + value=sha256.data.split(" ", maxsplit=1)[0], + ), + partial(warn_screen.update, name=self.name, key="label"), + ] + + for fn in fns: + Clock.schedule_once(fn, 0) + + self.set_background(wid=instance.id, rgba=(0, 0, 0, 1)) + self.set_screen(name="WarningAfterAirgapUpdateScreen", direction="left") + + except shutil.Error as err_exc: + self.redirect_exception(exception=err_exc) + + except shutil.ExecError as exec_exc: + self.redirect_exception(exception=exec_exc) + + # pylint: disable=broad-exception-caught + except Exception as exc: + self.redirect_exception(exception=exc) setattr(AirgapUpdateScreen, f"on_release_{self.id}_button_{row}", on_release)