Skip to content

Commit

Permalink
added exception treatment on shutil operations o airgap_update_screen
Browse files Browse the repository at this point in the history
  • Loading branch information
qlrddev committed Dec 20, 2024
1 parent 1c674b8 commit b6a489c
Showing 1 changed file with 42 additions and 31 deletions.
73 changes: 42 additions & 31 deletions src/app/screens/airgap_update_screen.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit b6a489c

Please sign in to comment.