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 steven.daprano
Recipients Max Staff, pitrou, r.david.murray, steven.daprano
Date 2017-06-13.00:42:41
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1497314562.09.0.958911784985.issue30641@psf.upfronthosting.co.za>
In-reply-to
Content
I don't understand what you actually are requesting here.

Are you requesting a way to tell whether or not the filename is too long? You've already been told that the way to do that is to check errno, and you say that you already knew that.

exc.errno == errno.ENAMETOOLONG

Or are you asking for a way to find out ahead of time what the maximum filename length will be? You say:

> it's almost impossible to reliably check the allowed filename length

I think that's right: it *is* almost impossible to reliably check the allowed filename length, except by trying it and seeing whether or not you can create the file.

The difficulty here is that there's no one maximum name length, it depends on the file system of the particular device you're accessing. So even if we had this `get_maximum_filename_length` function, and you wrote:

    if len(fname) < get_maximum_filename_length():
        with open(fname) as f: ...

the call to open might *still* fail with ENAMETOOLONG if you happen to be writing to a device or disk with a shorter than expected length.

E.g. FAT32 has a limit of either 8.3 bytes or 255 double-byte Unicode characters depending on the implementation; NTFS and HFS+ have a limit of 255 characters; ext4 has a limit of 255 bytes; Joliet has a limit of 64 characters; etc.

And then there's the question of the maximum allowed path.

So I think the first thing you should do is clarify exactly what it is that you're asking for:

- a way to check whether the exception is ENAMETOOLONG;

- specifically a new sub-exception for that case;

- a constant or function that returns the maximum file name length;

- or the maximum path name length;

- or something else.


But any of these (except the first, which already exists) is a new feature, not a bug fix, to it can only go into 3.7.
History
Date User Action Args
2017-06-13 00:42:42steven.dapranosetrecipients: + steven.daprano, pitrou, r.david.murray, Max Staff
2017-06-13 00:42:42steven.dapranosetmessageid: <1497314562.09.0.958911784985.issue30641@psf.upfronthosting.co.za>
2017-06-13 00:42:42steven.dapranolinkissue30641 messages
2017-06-13 00:42:41steven.dapranocreate