From d46a7ff2f55979f308387cba16d1c06d5a3db4ba Mon Sep 17 00:00:00 2001 From: Bodong YANG Date: Tue, 20 Feb 2024 05:27:20 +0000 Subject: [PATCH] implement fast fix for handling swapfile in persist handling --- otaclient/app/ota_client.py | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/otaclient/app/ota_client.py b/otaclient/app/ota_client.py index 730615bc7..0f7fb9510 100644 --- a/otaclient/app/ota_client.py +++ b/otaclient/app/ota_client.py @@ -46,6 +46,8 @@ ) from . import log_setting +from otaclient._utils.linux import create_swapfile, detect_swapfile_size + try: from otaclient import __version__ # type: ignore except ImportError: @@ -304,13 +306,23 @@ def _process_persistents(self): for _perinf in self._otameta.iter_metafile( ota_metadata.MetafilesV1.PERSISTENT_FNAME ): - _perinf_path = Path(_perinf.path) + _per_fpath = Path(_perinf.path) + + # NOTE(20240220): fast fix for handling swapfile + if str(_per_fpath) in ["/swapfile", "/swap.img"]: + _new_swapfile = standby_slot_mp / _per_fpath + try: + _swapfile_size = detect_swapfile_size(_per_fpath) # in MiB + assert _swapfile_size is not None + create_swapfile(_new_swapfile, _swapfile_size) + except Exception as e: + logger.warning(f"failed to create {_per_fpath}: {e!r}") + continue + if ( - _perinf_path.is_file() - or _perinf_path.is_dir() - or _perinf_path.is_symlink() + _per_fpath.is_file() or _per_fpath.is_dir() or _per_fpath.is_symlink() ): # NOTE: not equivalent to perinf.path.exists() - _copy_tree.copy_with_parents(_perinf_path, standby_slot_mp) + _copy_tree.copy_with_parents(_per_fpath, standby_slot_mp) def _execute_update( self,