[Python-ideas] Add shutil.chown(..., recursive=False)
Guido van Rossum
guido at python.org
Tue May 29 12:38:48 EDT 2018
Honestly, despite the occasional use case(1), I'm not sure that this is a
battery we need in the stdlib. Nobody seems too excited about writing the
code, and when the operation is needed, shelling out to the system chown is
not too onerous. (Ditto for chmod.)
(1) Not even sure that a use case was shown -- it was just shown that the
operation is not necessarily useless.
On Tue, May 29, 2018 at 5:57 AM, Nick Coghlan <ncoghlan at gmail.com> wrote:
> 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
> Python-ideas mailing list
> Python-ideas at python.org
> Code of Conduct: http://python.org/psf/codeofconduct/
--Guido van Rossum (python.org/~guido)
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-ideas