Skip to content

Commit

Permalink
minor comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Bodong-Yang committed Dec 26, 2023
1 parent d66b68e commit 083da4b
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions otaclient/app/create_standby/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -605,30 +605,35 @@ def preserve_persist_entry(
src_path = self._src_root / origin_entry
dst_path = self._dst_root / origin_entry

# NOTE: always check if symlink first!
# ------ src is symlink ------ #
# NOTE: always check if symlink first as is_file/is_dir/exists all follow_symlinks
if src_path.is_symlink():
self._rm_target(dst_path)
self._prepare_parent(origin_entry)
self._prepare_symlink(src_path, dst_path)
return

# ------ src is file ------ #
if src_path.is_file():
self._rm_target(dst_path)
self._prepare_parent(origin_entry)
self._prepare_file(src_path, dst_path)
return

# ------ src is not regular file/symlink/dir ------ #
# we only process normal 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")

# ------ src doesn't exist ------ #
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)
return

# for src as dir, cleanup dst_dirc,
# ------ src is dir ------ #
# dive into src_dir and preserve everything under the src dir
self._prepare_parent(origin_entry)
for src_curdir, dnames, fnames in os.walk(src_path, followlinks=False):
Expand Down

0 comments on commit 083da4b

Please sign in to comment.