Title: shutil.copystat should (allow to) copy ownership, and other attributes
Type: enhancement Stage:
Components: Library (Lib) Versions: Python 3.7
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: giampaolo.rodola, noctiflore
Priority: normal Keywords:

Created on 2017-04-11 15:42 by noctiflore, last changed 2018-06-12 10:09 by giampaolo.rodola.

Messages (2)
msg291499 - (view) Author: Florent Coriat (noctiflore) Date: 2017-04-11 15:42
shutil.copystat() copies permissions, timestamps and even flags and xattrs (if supported), but not ownership.
Furthermore, shutil.copy2() documentation until 2.7 used to say it behaves like cp -p, which preserves ownership, and not xattr nor flags. (On my system it silently fails to copy ownership when not root).

It may not be related, but comments in source code for the except NotImplementedError block concerning chmod mistakenly mentions chown-related functions.

I think copystat (and copy2) should at least provide an option to preserve ownership.
I do not know if it currently preserves SELinux context and ACL, but if not, it may also allow it.
It would be really useful for replication or backup applications to have a function that copies everything it can.
msg319373 - (view) Author: Giampaolo Rodola' (giampaolo.rodola) * (Python committer) Date: 2018-06-12 10:09
This could be achieved at least on Windows with CopyFileEx [1] and on OSX with copyfile(3) + COPYFILE_ALL which copies ACLs (but not users/groups). These are (were, in case of CopyFileEx) exposed in Such a new functionality would probably deserve a separate copy3() function but it would serve OSX and Windows only. I'm not sure how things would work on other POSIX platforms. 

Date User Action Args
2018-06-12 10:09:43giampaolo.rodolasetnosy: + giampaolo.rodola
messages: + msg319373
2017-04-14 17:59:26serhiy.storchakasetversions: - Python 3.5, Python 3.6
2017-04-11 15:42:33noctiflorecreate