fix(updates): only the exit status decides apply_updates
apply_updates ran apk/opkg upgrade and returned success whatever happened, so a failed upgrade was reported as done. The command now prints its exit status after the marker get_available_updates already uses; a non-zero or missing status is a failure, named in "error". Closes #11
This commit is contained in:
1 parent
16e0fa9d5e
commit
c211ba0d9e
3 files changed
+68
-5
No files matched your search
@@ -480,7 +480,10 @@ class OpenWrtSystemMixin:
|
||||
return {"success": status == 0, "output": output}
|
||||
|
||||
def apply_updates(self, packages: list[str]) -> dict[str, Any]:
|
||||
"""Upgrade the given packages using the device's package manager."""
|
||||
"""Upgrade the given packages using the device's package manager.
|
||||
|
||||
Only the package manager's exit status decides ``success``.
|
||||
"""
|
||||
import re as _re
|
||||
|
||||
for pkg in packages:
|
||||
@@ -489,11 +492,18 @@ class OpenWrtSystemMixin:
|
||||
pm = self._pm_type()
|
||||
pkg_args = " ".join(packages)
|
||||
if pm == "apk":
|
||||
cmd = f"apk upgrade {pkg_args} 2>&1"
|
||||
cmd = f"apk upgrade {pkg_args}"
|
||||
else:
|
||||
cmd = f"opkg upgrade {pkg_args} 2>&1"
|
||||
output = self._send_command(cmd)
|
||||
return {"success": True, "output": output}
|
||||
cmd = f"opkg upgrade {pkg_args}"
|
||||
output, status = _split_status(self._send_command(f"{cmd} 2>&1; echo {_RC_MARKER}$?"))
|
||||
if status == 0:
|
||||
return {"success": True, "output": output}
|
||||
error = (
|
||||
f"{cmd.strip()} exited with status {status}"
|
||||
if status is not None
|
||||
else "No exit status came back from the device."
|
||||
)
|
||||
return {"success": False, "output": output, "error": error}
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# NTP
|
||||
|
||||
Reference in new issue
Block a user