python / cpython

The Python programming language
https://www.python.org/
Other
61.16k stars 29.52k forks source link

shutil.chown should support dir_fd and follow_symlinks keyword arguments #62308

Closed 419ab78f-33bf-4c9e-994c-1dcf22375792 closed 2 months ago

419ab78f-33bf-4c9e-994c-1dcf22375792 commented 11 years ago
BPO 18108
Nosy @cjwatson, @PCManticore, @berkerpeksag, @hynek, @phmc, @avinassh, @tahia-khan
PRs
  • python/cpython#15811
  • Files
  • issue18108.diff
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields: ```python assignee = None closed_at = None created_at = labels = ['easy', 'type-feature', 'library'] title = 'shutil.chown should support dir_fd and follow_symlinks keyword arguments' updated_at = user = 'https://github.com/cjwatson' ``` bugs.python.org fields: ```python activity = actor = 'pconnell' assignee = 'none' closed = False closed_date = None closer = None components = ['Library (Lib)'] creation = creator = 'cjwatson' dependencies = [] files = ['35633'] hgrepos = [] issue_num = 18108 keywords = ['patch', 'easy'] message_count = 7.0 messages = ['190404', '220430', '220564', '220565', '221675', '346893', '351543'] nosy_count = 7.0 nosy_names = ['cjwatson', 'Claudiu.Popa', 'berker.peksag', 'hynek', 'pconnell', 'avi', 'ta1hia'] pr_nums = ['15811'] priority = 'normal' resolution = None stage = 'patch review' status = 'open' superseder = None type = 'enhancement' url = 'https://bugs.python.org/issue18108' versions = ['Python 3.5'] ```

    Linked PRs

    419ab78f-33bf-4c9e-994c-1dcf22375792 commented 11 years ago

    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.

    5df057ac-c83d-447e-8c45-910556b17608 commented 10 years ago

    Hi. Would you like to provide a patch?

    berkerpeksag commented 10 years ago

    Here's a patch.

    5df057ac-c83d-447e-8c45-910556b17608 commented 10 years ago

    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)

    5df057ac-c83d-447e-8c45-910556b17608 commented 10 years ago

    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.

    8757755e-276e-49e0-a171-34adb12510d4 commented 5 years ago

    I was looking for an easy patch to submit. I can take an attempt at this?

    386ed059-90e4-4d3b-a514-65c314a59ef6 commented 4 years ago

    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.