Eryk Sun <eryk...@gmail.com> added the comment:

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

----------
components: +Library (Lib)
type:  -> behavior
versions: +Python 3.10, Python 3.8, Python 3.9 -Python 3.7

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue43219>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to