This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author eryksun
Recipients eryksun, jerpint
Date 2021-02-17.02:02:47
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1613527367.9.0.888468476772.issue43219@roundup.psfhosted.org>
In-reply-to
Content
I left this open in case someone wants to modify shutil.copy() and shutil.copy2() to raise a less misleading exception when `dst` names a non-existing directory such as 'not_a_dir/'. Failing with IsADirectoryError (errno EISDIR) is confusing since shutil.copy() and shutil.copy2() do support a destination directory.

Note that in Windows this case fails with EINVAL, which is at least less misleading than EISDIR. The EINVAL error is based on WinAPI ERROR_INVALID_NAME (123). CreateFileW() can create a directory if passed particular parameters, in which case a trailing slash is allowed. Otherwise it fails with ERROR_INVALID_NAME (123), unless it's an open-existing disposition, in which case it fails with ERROR_FILE_NOT_FOUND (2). This is specified in [MS-FSA] 2.1.5.1 [1]:

    Phase 6 -- Location of file (final path component):

        Search ParentFile.DirectoryList for a Link where Link.Name or
        Link.ShortName matches FileNameToOpen. If such a link is found:

            Set File = Link.File.
            Set Open.File to File.
            Set Open.Link to Link.

        Else:

            If (CreateDisposition == FILE_OPEN || CreateDisposition ==
            FILE_OVERWRITE), the operation MUST be failed with
            STATUS_OBJECT_NAME_NOT_FOUND.

    Phase 7 -- Type of stream to open:

        If PathName contains a trailing backslash:

            If StreamTypeToOpen is DataStream or
            CreateOptions.FILE_NON_DIRECTORY_FILE is TRUE, the operation
            MUST be failed with STATUS_OBJECT_NAME_INVALID.

NTAPI STATUS_OBJECT_NAME_NOT_FOUND and STATUS_OBJECT_NAME_INVALID map to WinAPI ERROR_FILE_NOT_FOUND and ERROR_INVALID_NAME.

---
[1] https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-fsa/8ada5fbe-db4e-49fd-aef6-20d54b748e40
History
Date User Action Args
2021-02-17 02:02:47eryksunsetrecipients: + eryksun, jerpint
2021-02-17 02:02:47eryksunsetmessageid: <1613527367.9.0.888468476772.issue43219@roundup.psfhosted.org>
2021-02-17 02:02:47eryksunlinkissue43219 messages
2021-02-17 02:02:47eryksuncreate