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
来获取guid
和uid
,就像在this answer 中一样。然后在使用 os.chown
应对后重置 uid
和 guid
.
关于python - 复制文件,保留权限和所有者,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19787348/