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-14.06:49:03
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1613285344.43.0.125678321145.issue43219@roundup.psfhosted.org>
In-reply-to
Content
> IsADirectoryError: [Errno 21] Is a directory: 'not_a_dir/'

The trailing slash forces the OS to handle "not_a_dir" as a directory [1]. 

    A pathname that contains at least one non- <slash> character and that 
    ends with one or more trailing <slash> characters shall not be resolved
    successfully unless the last pathname component before the trailing 
    <slash> characters names an existing directory or a directory entry 
    that is to be created for a directory immediately after the pathname is
    resolved. 

Mode "w" corresponds to low-level POSIX open() flags O_CREAT | O_TRUNC | O_WRONLY. If write access is requested for a directory, the open() system call must fail with EISDIR [2].

    [EISDIR]
        The named file is a directory and oflag includes O_WRONLY or O_RDWR,
        or includes O_CREAT without O_DIRECTORY.

In most cases, opening a directory with O_CREAT also fails with E_ISDIR. POSIX does permit an implementation to create a directory with O_CREAT | O_DIRECTORY. In Linux, however, O_CREAT always creates a regular file, regardless of O_DIRECTORY, so open(pathname, O_CREAT | flags) always fails with EISDIR when pathname is an existing directory or names a directory by way of a trailing slash.

---
[1] https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap04.html#tag_04_13
[2] https://pubs.opengroup.org/onlinepubs/9699919799/functions/open.html
History
Date User Action Args
2021-02-14 06:49:04eryksunsetrecipients: + eryksun, jerpint
2021-02-14 06:49:04eryksunsetmessageid: <1613285344.43.0.125678321145.issue43219@roundup.psfhosted.org>
2021-02-14 06:49:04eryksunlinkissue43219 messages
2021-02-14 06:49:03eryksuncreate