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

标签 python file-permissions

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/

相关文章:

python - Python 对象的属性是否有一个名称以使其具有与其代码等效的控制台表示?

linux - Jenkins Linux 文件访问或组问题

Android M权限被授予后被拒绝

python2.7 - 从充满 unicode 的 .txt 文件中读取字典

python - 从 pandas groupby 中的每个组中选择前 n 个元素

python - pandas 中特定数字的累积结果

Drupal - 目录sites/default/files 存在但不可写且无法写入

c++ - 如何在Qt/C++中设置Windows文件权限

php - 即使具有(似乎)正确的文件权限,上传目标文件夹似乎也不可写

python - 对话流 : manage several credentials for several agents