def map_id(path, map_uid, map_gid):
"""
Remapping ownership of all files inside a container's rootfs.
map_gid and map_uid: Contain integers in a list with format:
[<start>, <target>, <count>]
"""
if map_uid:
uid_opts = get_mapping_opts(map_uid)
if map_gid:
gid_opts = get_mapping_opts(map_gid)
for root, _ignore, files in os.walk(os.path.realpath(path)):
for name in [root] + files:
file_path = os.path.join(root, name)
stat_info = os.lstat(file_path)
old_uid = stat_info.st_uid
old_gid = stat_info.st_gid
new_uid = get_map_id(old_uid, uid_opts) if map_uid else -1
new_gid = get_map_id(old_gid, gid_opts) if map_gid else -1
os.lchown(file_path, new_uid, new_gid)
评论列表
文章目录