Skip to content

Commit

Permalink
add logging for uid/gid mapping result
Browse files Browse the repository at this point in the history
  • Loading branch information
Bodong-Yang committed Dec 26, 2023
1 parent 083da4b commit 6ebe9bc
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions otaclient/app/create_standby/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@
from otaclient._utils.unix import (
ParsedPasswd,
ParsedGroup,
map_gid_by_grpnam,
map_uid_by_pwnam,
map_gid_by_grpnam as _utils_map_gid_by_grpnam,
map_uid_by_pwnam as _utils_map_uid_by_pwnam,
)
from ..common import create_tmp_fname
from ..configs import config as cfg
Expand Down Expand Up @@ -513,21 +513,39 @@ def __init__(
):
self._uid_mapper = functools.lru_cache()(
functools.partial(
map_uid_by_pwnam,
self.map_uid_by_pwnam,
src_db=ParsedPasswd(src_passwd_file),
dst_db=ParsedPasswd(dst_passwd_file),
)
)
self._gid_mapper = functools.lru_cache()(
functools.partial(
map_gid_by_grpnam,
self.map_gid_by_grpnam,
src_db=ParsedGroup(src_group_file),
dst_db=ParsedGroup(dst_group_file),
)
)
self._src_root = Path(src_root)
self._dst_root = Path(dst_root)

@staticmethod
def map_uid_by_pwnam(
*, src_db: ParsedPasswd, dst_db: ParsedPasswd, uid: int
) -> int:
_mapped_uid = _utils_map_uid_by_pwnam(src_db=src_db, dst_db=dst_db, uid=uid)
_usern = src_db._by_uid[uid]

logger.info(f"{_usern=}: mapping src_{uid=} to {_mapped_uid}")
return _mapped_uid

@staticmethod
def map_gid_by_grpnam(*, src_db: ParsedGroup, dst_db: ParsedGroup, gid: int) -> int:
_mapped_gid = _utils_map_gid_by_grpnam(src_db=src_db, dst_db=dst_db, gid=gid)
_groupn = src_db._by_gid[gid]

logger.info(f"{_groupn=}: mapping src_{gid=} to {_mapped_gid=}")
return _mapped_gid

def _chown_with_mapping(
self, _src_stat: os.stat_result, _dst_path: StrOrPath
) -> None:
Expand Down

0 comments on commit 6ebe9bc

Please sign in to comment.