Skip to content

shutil.copy2 raises OSError if filesystem doesn't support chmod #70655

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
VojtchPachol mannequin opened this issue Mar 2, 2016 · 7 comments
Open

shutil.copy2 raises OSError if filesystem doesn't support chmod #70655

VojtchPachol mannequin opened this issue Mar 2, 2016 · 7 comments
Labels
3.8 (EOL) end of life 3.9 only security fixes stdlib Python modules in the Lib dir

Comments

@VojtchPachol
Copy link
Mannequin

VojtchPachol mannequin commented Mar 2, 2016

BPO 26468
Nosy @ericvsmith, @matrixise, @miss-islington
PRs
  • bpo-26468: note that shutil.copy2 would fail. #13765
  • [3.8] bpo-26468: Doc: improve the documentation of shutil.copy2 when it can fail. (GH-13765) #16102
  • 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:

    assignee = None
    closed_at = None
    created_at = <Date 2016-03-02.09:21:59.818>
    labels = ['3.8', 'library', '3.9', 'docs']
    title = "shutil.copy2 raises OSError if filesystem doesn't support chmod"
    updated_at = <Date 2019-09-13.13:43:37.527>
    user = 'https://bugs.python.org/VojtchPachol'

    bugs.python.org fields:

    activity = <Date 2019-09-13.13:43:37.527>
    actor = 'miss-islington'
    assignee = 'docs@python'
    closed = False
    closed_date = None
    closer = None
    components = ['Documentation', 'Library (Lib)']
    creation = <Date 2016-03-02.09:21:59.818>
    creator = 'Vojt\xc4\x9bch Pachol'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 26468
    keywords = ['patch']
    message_count = 6.0
    messages = ['261100', '261106', '261110', '352326', '352328', '352332']
    nosy_count = 5.0
    nosy_names = ['eric.smith', 'docs@python', 'matrixise', 'Vojt\xc4\x9bch Pachol', 'miss-islington']
    pr_nums = ['13765', '16102']
    priority = 'normal'
    resolution = None
    stage = 'patch review'
    status = 'open'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue26468'
    versions = ['Python 3.8', 'Python 3.9']

    @VojtchPachol
    Copy link
    Mannequin Author

    VojtchPachol mannequin commented Mar 2, 2016

    copy2 checks if os nodule has chmod and then it uses it without thinking.

    On filesystems that doesn't support chmod it ends with

    OSError: [Errno 95] Operation not supported: <filename>
    

    which is not acceptable since documentation says "copy2() never returns failure".

    @VojtchPachol VojtchPachol mannequin added the stdlib Python modules in the Lib dir label Mar 2, 2016
    @ericvsmith
    Copy link
    Member

    I agree that copy2 should not fail because chmod fails. Could you please provide the entire traceback message when it fails (on both 2.7 and 3.4 or 3.5)? And what OS are you running on, and what filesystem?

    It looks like the error happens because errno=95 (EOPNOTSUPP, probably) isn't in the list of errors that _copyxattr catches, while (ENOTSUP=134 on Linux) is.

    I think the documentation is also incorrect. Of course copy2 can fail: what about out of disk space? I think the documentation is trying to say that copy2 never fails because it can't preserve metadata. And the wording in the docs "copy2() never returns failure" is also odd, it should say "copy2() never raises an exception because it cannot preserve file metadata".

    @ericvsmith ericvsmith added the docs Documentation in the Doc dir label Mar 2, 2016
    @VojtchPachol
    Copy link
    Mannequin Author

    VojtchPachol mannequin commented Mar 2, 2016

    Actually it is a remote fs mounted via samba. OS is Linux.

    Tracebacks with Python versions I have:

    $ python2.7
    Python 2.7.11 (default, Jan 11 2016, 21:04:40) 
    [GCC 5.3.1 20160101] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import shutil
    >>> shutil.copy2("src", "dst")
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "/usr/lib/python2.7/shutil.py", line 131, in copy2
        copystat(src, dst)
      File "/usr/lib/python2.7/shutil.py", line 100, in copystat
        os.chmod(dst, mode)
    OSError: [Errno 95] Operation not supported: 'dst'
    >>> 
    $ python3.4
    Python 3.4.4 (default, Jan  5 2016, 15:35:18) 
    [GCC 5.3.1 20160101] on linux
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import shutil
    >>> shutil.copy2("src", "dst")
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "/usr/lib/python3.4/shutil.py", line 246, in copy2
        copystat(src, dst, follow_symlinks=follow_symlinks)
      File "/usr/lib/python3.4/shutil.py", line 191, in copystat
        lookup("chmod")(dst, mode, follow_symlinks=follow)
    OSError: [Errno 95] Operation not supported: 'dst'
    >>> 
    $ python3.5
    Python 3.5.1+ (default, Jan 13 2016, 15:09:18) 
    [GCC 5.3.1 20160101] on linux
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import shutil
    >>> shutil.copy2("src", "dst")
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "/usr/lib/python3.5/shutil.py", line 252, in copy2
        copystat(src, dst, follow_symlinks=follow_symlinks)
      File "/usr/lib/python3.5/shutil.py", line 197, in copystat
        lookup("chmod")(dst, mode, follow_symlinks=follow)
    OSError: [Errno 95] Operation not supported: 'dst'
    >>>

    @matrixise
    Copy link
    Member

    New changeset 9585f46 by Stéphane Wirtel (Windson yang) in branch 'master':
    bpo-26468: Doc: improve the documentation of shutil.copy2 when it can fail. (GH-13765)
    9585f46

    @matrixise
    Copy link
    Member

    I have merged the PR with the change in the documentation, feel free to open a new PR for the other part of this issue.

    @matrixise matrixise added 3.8 (EOL) end of life 3.9 only security fixes labels Sep 13, 2019
    @miss-islington
    Copy link
    Contributor

    New changeset c27bcc3 by Miss Islington (bot) in branch '3.8':
    bpo-26468: Doc: improve the documentation of shutil.copy2 when it can fail. (GH-13765)
    c27bcc3

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    @hauntsaninja
    Copy link
    Contributor

    hauntsaninja commented Oct 29, 2022

    Thanks for improving the docs here! Looks like there's still the fix to be made re: EOPNOTSUPP

    @hauntsaninja hauntsaninja reopened this Oct 29, 2022
    @hauntsaninja hauntsaninja removed the docs Documentation in the Doc dir label Oct 29, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.8 (EOL) end of life 3.9 only security fixes stdlib Python modules in the Lib dir
    Projects
    None yet
    Development

    No branches or pull requests

    4 participants