mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-24 23:36:04 +00:00
fix(droiddeckctl): address review on logs latest
Stream each archive entry to disk instead of reading it into memory, refuse an archive from a session that started after the state call, and delete the exported zip from shared storage once it has been pulled.
This commit is contained in:
1 parent
2fb066507a
commit
8cc652e812
2 files changed
+24
-6
No files matched your search
+14
-6
@@ -434,7 +434,8 @@ def unpack_logs(archive: Path, destination: Path, session_id: str) -> None:
|
||||
if entry.is_dir() or not name or not target.is_relative_to(destination):
|
||||
continue
|
||||
target.parent.mkdir(parents=True, exist_ok=True)
|
||||
target.write_bytes(z.read(entry))
|
||||
with z.open(entry) as source, target.open("wb") as copy:
|
||||
shutil.copyfileobj(source, copy)
|
||||
except (OSError, zipfile.BadZipFile) as exc:
|
||||
raise ControlError(f"Could not unpack the session logs: {exc}", "LOG_PULL_FAILED") from exc
|
||||
|
||||
@@ -765,11 +766,18 @@ def execute(args: argparse.Namespace, adb: str, serial: str) -> dict:
|
||||
result = run_adb(adb, serial, "pull", remote_dir, str(destination), timeout=120)
|
||||
else:
|
||||
zip_path = checked(exported, "LOG_PULL_FAILED")["zip"]
|
||||
with tempfile.TemporaryDirectory() as temp:
|
||||
local_zip = Path(temp) / "logs.zip"
|
||||
result = run_adb(adb, serial, "pull", zip_path, str(local_zip), timeout=120)
|
||||
if result.returncode == 0:
|
||||
unpack_logs(local_zip, destination, exported.get("sessionId") or session["id"])
|
||||
try:
|
||||
if exported.get("sessionId", session["id"]) != session["id"]:
|
||||
raise ControlError("A new session started while the logs were exported; run logs again",
|
||||
"LOG_PULL_FAILED")
|
||||
with tempfile.TemporaryDirectory() as temp:
|
||||
local_zip = Path(temp) / "logs.zip"
|
||||
result = run_adb(adb, serial, "pull", zip_path, str(local_zip), timeout=120)
|
||||
if result.returncode == 0:
|
||||
unpack_logs(local_zip, destination, session["id"])
|
||||
finally:
|
||||
# The copy sits in shared storage, so it does not outlive the pull.
|
||||
run_adb(adb, serial, "shell", "rm", "-f", zip_path, timeout=30)
|
||||
if result.returncode != 0:
|
||||
detail = (result.stderr or result.stdout).decode(errors="replace").strip()
|
||||
raise ControlError(detail or "adb pull failed", "LOG_PULL_FAILED")
|
||||
|
||||
Reference in new issue
Block a user