classification
Title: shutil.chown should support dir_fd and follow_symlinks keyword arguments
Type: enhancement Stage: patch review
Components: Library (Lib) Versions: Python 3.5
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: Claudiu.Popa, avi, berker.peksag, cjwatson, hynek, ta1hia
Priority: normal Keywords: easy, patch

Created on 2013-05-31 13:09 by cjwatson, last changed 2019-09-09 18:21 by ta1hia.

Files
File name Uploaded Description Edit
issue18108.diff berker.peksag, 2014-06-14 15:13 review
Pull Requests
URL Status Linked Edit
PR 15811 open ta1hia, 2019-09-09 18:06
Messages (7)
msg190404 - (view) Author: Colin Watson (cjwatson) * Date: 2013-05-31 13:09
Python 3.3 added the dir_fd and follow_symlinks keyword arguments to os.chown; it also added the shutil.chown function.  Unfortunately the latter, while useful, does not support these new keyword arguments.  It would be helpful if it did.
msg220430 - (view) Author: Claudiu Popa (Claudiu.Popa) * (Python triager) Date: 2014-06-13 11:12
Hi. Would you like to provide a patch?
msg220564 - (view) Author: Berker Peksag (berker.peksag) * (Python committer) Date: 2014-06-14 15:13
Here's a patch.
msg220565 - (view) Author: Claudiu Popa (Claudiu.Popa) * (Python triager) Date: 2014-06-14 15:16
Looks good to me. But aren't the last two lines skipped if an error is raised by the first line from the with block?

+        with self.assertRaises(FileNotFoundError):
+            shutil.chown('invalid-file', user=uid, dir_fd=dirfd)
+            shutil.chown('invalid-file', group=gid, dir_fd=dirfd)
+            shutil.chown('invalid-file', user=uid, group=gid, dir_fd=dirfd)
msg221675 - (view) Author: Claudiu Popa (Claudiu.Popa) * (Python triager) Date: 2014-06-27 06:08
I got a failure on FreeBSD:

[1/1] test_shutil
test test_shutil failed -- Traceback (most recent call last):
  File "/tank/libs/cpython/Lib/test/test_shutil.py", line 1258, in test_chown
    shutil.chown(os.path.basename(filename), dir_fd=dirfd)
  File "/tank/libs/cpython/Lib/shutil.py", line 983, in chown
    raise ValueError("user and/or group must be set")
ValueError: user and/or group must be set


It seems that either user or group argument must be passed along with dir_fd.
msg346893 - (view) Author: Avinash Sajjanshetty (avi) * Date: 2019-06-29 18:08
I was looking for an easy patch to submit. I can take an attempt at this?
msg351543 - (view) Author: Tahia K (ta1hia) * Date: 2019-09-09 18:21
Hi everybody,

I just submitted a PR for this issue. It's my first contribution to the cPython project so please let me know if I need to change anything.
History
Date User Action Args
2019-09-09 18:21:09ta1hiasetmessages: + msg351543
2019-09-09 18:06:54ta1hiasetpull_requests: + pull_request15461
2019-09-09 15:20:32ta1hiasetnosy: + ta1hia
2019-06-29 18:08:16avisetnosy: + avi
messages: + msg346893
2014-06-27 06:08:14Claudiu.Popasetmessages: + msg221675
2014-06-14 15:16:38Claudiu.Popasetmessages: + msg220565
2014-06-14 15:13:35berker.peksagsetfiles: + issue18108.diff

nosy: + berker.peksag
messages: + msg220564

keywords: + patch
stage: needs patch -> patch review
2014-06-13 11:12:33Claudiu.Popasettype: enhancement
versions: + Python 3.5, - Python 3.4
keywords: + easy
nosy: + Claudiu.Popa

messages: + msg220430
stage: needs patch
2013-05-31 16:28:16hyneksetnosy: + hynek

versions: + Python 3.4, - Python 3.3
2013-05-31 13:09:57cjwatsoncreate