mirror of
https://github.com/Abdess/retroarch_system.git
synced 2026-11-06 01:53:56 -06:00
fix: rename extracted BIOS files into place
This commit is contained in:
1 parent
34293f7bbb
commit
2a243985c0
2 files changed
+48
-1
No files matched your search
+19
-1
@@ -191,9 +191,27 @@ EOF
|
|||||||
done
|
done
|
||||||
|
|
||||||
echo "Extracting to ${dest}/..."
|
echo "Extracting to ${dest}/..."
|
||||||
|
# unzip -o unlinks a file and writes its replacement under the final
|
||||||
|
# name, so a run stopped mid-file left a partial BIOS. Members land in
|
||||||
|
# the staging folder, on the same filesystem, and each is renamed into
|
||||||
|
# place: a file in the BIOS folder is the old one or the new one.
|
||||||
|
local extracted="${staging}/extracted"
|
||||||
for file in "${staging}"/*.zip; do
|
for file in "${staging}"/*.zip; do
|
||||||
unzip -o -q "$file" -d "$dest"
|
unzip -o -q "$file" -d "$extracted"
|
||||||
done
|
done
|
||||||
|
local target
|
||||||
|
target=$(cd "$dest" && pwd)
|
||||||
|
(
|
||||||
|
cd "$extracted"
|
||||||
|
find . -type f -exec sh -c '
|
||||||
|
target="$1"
|
||||||
|
shift
|
||||||
|
for member; do
|
||||||
|
mkdir -p "$target/$(dirname "$member")"
|
||||||
|
mv -f "$member" "$target/$member"
|
||||||
|
done
|
||||||
|
' sh "$target" {} +
|
||||||
|
)
|
||||||
|
|
||||||
cleanup_staging
|
cleanup_staging
|
||||||
trap - EXIT
|
trap - EXIT
|
||||||
|
|||||||
@@ -575,6 +575,35 @@ class TestDownloadShell(DownloaderCase):
|
|||||||
self.assertNotIn("unbound variable", proc.stderr)
|
self.assertNotIn("unbound variable", proc.stderr)
|
||||||
self.assertEqual(list(self.dest.iterdir()), [])
|
self.assertEqual(list(self.dest.iterdir()), [])
|
||||||
|
|
||||||
|
def test_an_interrupted_extraction_keeps_the_installed_file(self):
|
||||||
|
"""unzip -o unlinks a file and writes the new one under its final
|
||||||
|
name: a run killed mid-file left a partial BIOS where a valid one
|
||||||
|
was. Extraction now writes beside the folder and renames."""
|
||||||
|
shim = Path(_tempdir(self))
|
||||||
|
(shim / "unzip").write_text(
|
||||||
|
"#!/bin/sh\n"
|
||||||
|
'for target; do :; done\n'
|
||||||
|
'mkdir -p "$target/bios"\n'
|
||||||
|
'printf partial > "$target/bios/scph5501.bin"\n'
|
||||||
|
"exit 137\n"
|
||||||
|
)
|
||||||
|
(shim / "unzip").chmod(0o755)
|
||||||
|
installed = self.dest / "bios" / "scph5501.bin"
|
||||||
|
installed.parent.mkdir(parents=True)
|
||||||
|
installed.write_bytes(b"valid")
|
||||||
|
env = self.env()
|
||||||
|
env["PATH"] = f"{shim}{os.pathsep}{env['PATH']}"
|
||||||
|
proc = subprocess.run(
|
||||||
|
["bash", str(SHELL), self.platform, str(self.dest)],
|
||||||
|
env=env, capture_output=True, text=True, timeout=120,
|
||||||
|
)
|
||||||
|
self.assertNotEqual(proc.returncode, 0)
|
||||||
|
self.assertEqual(installed.read_bytes(), b"valid")
|
||||||
|
self.assertEqual(
|
||||||
|
sorted(p.name for p in self.dest.iterdir()), ["bios"],
|
||||||
|
"staging left behind",
|
||||||
|
)
|
||||||
|
|
||||||
def test_two_runs_into_one_folder_both_finish(self):
|
def test_two_runs_into_one_folder_both_finish(self):
|
||||||
"""Both runs staged in `<dest>/.retrobios-download` and the second
|
"""Both runs staged in `<dest>/.retrobios-download` and the second
|
||||||
emptied it while the first was still writing its parts."""
|
emptied it while the first was still writing its parts."""
|
||||||
|
|||||||
Reference in new issue
Block a user