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 <ncogh...@gmail.com> wrote:

> On 29 May 2018 at 06:23, Giampaolo Rodola' <g.rod...@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").
>> Thoughts?
>>
>
> 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
> "shutil.copytree").
>
> 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.
>
> Cheers,
> Nick.
>
> --
> Nick Coghlan   |   ncogh...@gmail.com   |   Brisbane, Australia
>
> _______________________________________________
> Python-ideas mailing list
> Python-ideas@python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/
>
>


-- 
--Guido van Rossum (python.org/~guido)
_______________________________________________
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to