[Python-ideas] Add shutil.chown(..., recursive=False)
ncoghlan at gmail.com
Tue May 29 08:57:57 EDT 2018
On 29 May 2018 at 06:23, Giampaolo Rodola' <g.rodola at gmail.com> wrote:
> ...as in (not tested):
> def _rchown(dir, user, group):
> for root, dirs, files in os.walk(dir, topdown=False):
> for name in files:
> chown(os.path.join(root, name), user, group)
> def chown(path, user=None, group=None, recursive=False):
> if recursive and os.path.isdir(path):
> _rchown(dir, user, group)
> It appears like a common enough use case to me ("chown -R path").
https://bugs.python.org/issue13033 is a long-open RFE for this, proposing
to add it as "shutil.chowntree" (naming inspired by "shutil.rmtree" and
The "walkdir" project I mention on that PR has been on hiatus for a few
years now (aside from a bit of activity to get a new release out in 2016
with several contributed fixes), but the main point of the comment where I
mentioned it still stands: the hard part of designing recursive state
modification APIs is deciding what to do when an operation fails after
you've already made changes to the state of the disk.
shutil.rmtree fortunately provides some good precedent there, but it does
mean this feature would need to be implemented as its own API, rather than
as an option on shutil.chown.
Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-ideas