Skip to content

Commit

Permalink
fix(update-server): clean up the downloaded update files after an upd…
Browse files Browse the repository at this point in the history
…ate. (#13087)
  • Loading branch information
vegano1 authored Jul 13, 2023
1 parent 662cd8c commit 2d085d9
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 0 deletions.
11 changes: 11 additions & 0 deletions update-server/otupdate/buildroot/update_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,17 @@ def write_machine_id(self, current_root: str, new_root: str) -> None:
new_mid.write(mid)
LOG.info(f"Wrote machine_id {mid.strip()} to {new_root}/etc/machine-id")

def clean_up(self, download_dir: str) -> None:
"""Deletes the update contents in the download dir."""
LOG.info(f"Cleaning up download dir {download_dir}.")
for file in os.listdir(download_dir):
filepath = os.path.join(download_dir, file)
LOG.debug(f"Deleting {filepath}")
try:
os.remove(filepath)
except Exception:
LOG.exception(f"Could not delete update file {filepath}.")


def _find_unused_partition() -> RootPartitions:
"""Find the currently-unused root partition to write to"""
Expand Down
4 changes: 4 additions & 0 deletions update-server/otupdate/common/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,10 @@ async def commit(request: web.Request, session: UpdateSession) -> web.Response:
except (OSError, CalledProcessError):
LOG.exception("Failed to update machine-id")
actions.commit_update()

# Clean up stale update files from the download dir
actions.clean_up(session.download_path)

session.set_stage(Stages.READY_FOR_RESTART)

return web.json_response(data=session.state, status=200)
5 changes: 5 additions & 0 deletions update-server/otupdate/common/update_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,8 @@ def commit_update(self) -> None:
def write_machine_id(self, current_root: str, new_root: str) -> None:
"""Copy the machine id over to the new partition"""
...

@abc.abstractmethod
def clean_up(self, download_dir: str) -> None:
"""Deletes the update files from the download dir."""
...
11 changes: 11 additions & 0 deletions update-server/otupdate/openembedded/update_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,3 +302,14 @@ def decomp_and_write(
)
if not success:
raise RuntimeError(msg)

def clean_up(self, download_dir: str) -> None:
"""Deletes the update contents in the download dir."""
LOG.info(f"Cleaning up download dir {download_dir}.")
for file in os.listdir(download_dir):
filepath = os.path.join(download_dir, file)
LOG.debug(f"Deleting {filepath}")
try:
os.remove(filepath)
except Exception:
LOG.exception(f"Could not delete update file {filepath}.")

0 comments on commit 2d085d9

Please sign in to comment.