Why does Python give “OSError: [Errno 36] File name too long” for filename shorter than filesystem's limit?

荒凉一梦 提交于 2019-12-04 21:39:00

问题


The following code yields an unexpected exception:

open("52bbe674cdc81d4140099b84fa69eea4249bcceee75bcbe4838d911ab076547cfdad3c1c5197752a98e5525fe76613dbe52dcdb1a9a397669babce0f101d010142cffa000000.csv", "w")
OSError: [Errno 36] File name too long: '52bbe674cdc81d4140099b84fa69eea4249bcceee75bcbe4838d911ab076547cfdad3c1c5197752a98e5525fe76613dbe52dcdb1a9a397669babce0f101d010142cffa000000.csv'

This is unexpected because my filesystem is ext4 which (according to Wikipedia) has a 255 byte filename length limit. The above filename has a length of 144.

So why does Python raise this exception when the filename length limit hasn't actually been exceeded?


回答1:


I've found a solution. It turns out that I'm not dealing with pure ext4---it's actually ecryptfs layered atop ext4, carried over from a previous Ubuntu install. As suggested in an unaccepted answer to this related question the ecryptfs layer imposes a limit of 143 characters to the filename length. A definitive answer to the file name length limit under ecryptfs can be found here.



来源:https://stackoverflow.com/questions/34503540/why-does-python-give-oserror-errno-36-file-name-too-long-for-filename-short

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!