Skip to content

Commit

Permalink
PersistFilesHandler: add src_missing_ok=True
Browse files Browse the repository at this point in the history
  • Loading branch information
Bodong-Yang committed Dec 26, 2023
1 parent 807f8b5 commit 15d7f14
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions otaclient/app/create_standby/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,9 @@ def _prepare_parent(self, _src_path: Path, _dst_path: Path) -> None:

# API

def preserve_persist_entry(self, _persist_entry: StrOrPath):
def preserve_persist_entry(
self, _persist_entry: StrOrPath, *, src_missing_ok: bool = True
):
logger.info(
f"preserving {_persist_entry} from {self._src_root} to {self._dst_root}"
)
Expand All @@ -617,10 +619,13 @@ def preserve_persist_entry(self, _persist_entry: StrOrPath):
return

# we only process normal file/symlink/dir
if not src_path.is_dir():
raise ValueError(
f"{src_path=} must be presented and either a file/symlink/dir"
)
if src_path.exists() and not src_path.is_dir():
raise ValueError(f"{src_path=} must be either a file/symlink/dir")
if not src_path.exists():
_err_msg = f"{src_path=} not found"
logger.warning(_err_msg)
if not src_missing_ok:
raise ValueError(_err_msg)

# for src as dir, cleanup dst_dirc,
# dive into src_dir and preserve everything under the src dir
Expand Down

0 comments on commit 15d7f14

Please sign in to comment.