gpt4 book ai didi

python - 复制文件,保留权限和所有者

转载 作者:太空狗 更新时间:2023-10-29 17:22:47 26 4
gpt4 key购买 nike

shutil 的文档告诉我:

Even the higher-level file copying functions (shutil.copy(), shutil.copy2()) can’t copy all file metadata. On POSIX platforms, this means that file owner and group are lost as well as ACLs

如果我需要在python中复制文件,如何保留文件所有者和组?

该进程以 root 身份在 linux 上运行。

更新:我们不使用 ACL。我们只需要保留使用 tar 和 rsync 等工具保留的内容。

最佳答案

您也许可以使用os.stat 来获取guiduid,就像在this answer 中一样。然后在使用 os.chown 应对后重置 uidguid .

关于python - 复制文件,保留权限和所有者,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19787348/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com