def updateFile(install_path, diff_path, diff_list, conf_file_list, user, group, pkg_type):
uid = pwd.getpwnam(user).pw_uid
gid = grp.getgrnam(group).gr_gid
for diff in diff_list:
file = diff['file'].lstrip('/')
if pkg_type == 'conf' and file == "package.conf.yaml":
continue
src = os.path.join(diff_path, file)
dst = os.path.join(install_path, file)
if pkg_type != 'conf' and os.path.realpath(dst) in conf_file_list:
continue
if diff['op'] == "M":
shutil.copy2(src, dst)
os.chown(dst, uid, gid)
elif diff['op'] == "A":
public_file_list.append(file)
if not os.path.isdir(os.path.dirname(dst)):
mkdir(os.path.dirname(dst))
os.chown(os.path.dirname(dst), uid, gid)
if os.path.isdir(src):
mkdir(dst)
os.chown(dst, uid, gid)
else:
shutil.copy2(src, dst)
os.chown(dst, uid, gid)
elif diff['op'] == "X":
shutil.copymode(src, dst)
elif diff['op'] == "D":
if file in public_file_list:
continue
if os.path.isfile(dst):
os.remove(dst)
elif os.path.isdir(dst):
if os.path.islink(dst):
os.remove(dst)
else:
shutil.rmtree(dst)
return 0, 'ok'
评论列表
文章目录