fix: clean download.sh staging on a failed part

This commit is contained in:
Abdessamad Derraz committed 2026-11-05 11:41:00 +01:00
1 parent d38cd58036
commit df5de91b37
2 files changed
+25 -2

No files matched your search

+12 -2
View File
@@ -29,6 +29,15 @@ case "$API_BASE" in
esac
API="${API_BASE%/}/repos/${REPO}/releases/latest"
# Global, not local to download_pack: the EXIT trap runs once that function's
# scope is gone, and under set -u a local would be unbound there.
STAGING=""
cleanup_staging() {
if [ -n "$STAGING" ]; then
rm -rf "$STAGING"
fi
}
usage() {
echo "Usage: $0 <platform> <destination>"
echo " $0 --list"
@@ -148,7 +157,8 @@ EOF
local staging="${dest%/}/.retrobios-download"
rm -rf "$staging"
mkdir -p "$staging"
trap 'rm -rf "$staging"' EXIT
STAGING="$staging"
trap cleanup_staging EXIT
local index=0
local url name
@@ -184,7 +194,7 @@ EOF
unzip -o -q "$file" -d "$dest"
done
rm -rf "$staging"
cleanup_staging
trap - EXIT
echo "Done! BIOS files extracted to ${dest}/"
}
+13
View File
@@ -371,6 +371,10 @@ class ReleaseServer:
]
self.index.write_text(json.dumps(release))
def drop_last_asset(self) -> None:
"""A part the release lists but no longer serves: its URL gives 404."""
(self.root / "assets" / self.names[-1]).unlink()
def corrupt_last_volume(self) -> None:
target = self.root / "assets" / self.names[-1]
target.write_bytes(target.read_bytes()[:-16] + b"0" * 16)
@@ -561,6 +565,15 @@ class TestDownloadShell(DownloaderCase):
proc = self.run_cli("nintendo", str(self.dest), expect_success=False)
self.assertIn(self.platform_label, proc.stdout + proc.stderr)
def test_a_failed_part_leaves_no_staging_behind(self):
"""The EXIT trap read a variable local to the function that set it:
under set -u it failed on `staging: unbound variable` and left the
parts already downloaded in the BIOS folder."""
self.server.drop_last_asset()
proc = self.run_cli(self.platform, str(self.dest), expect_success=False)
self.assertNotIn("unbound variable", proc.stderr)
self.assertEqual(list(self.dest.iterdir()), [])
class TestWholePackPython(WholePackCase, TestDownloadPython):
def test_info_reports_every_volume(self):