[New-bugs-announce] [issue45965] fileinput.input(path, inplace=True) crashes for valid filename with 252-255 characters

Jamil Raichouni report at bugs.python.org
Thu Dec 2 10:46:59 EST 2021


New submission from Jamil Raichouni <raichouni at gmail.com>:

import fileinput
from pathlib import Path
path = Path(252 * "x")
path.write_text("")
for line in fileinput.input(path, inplace=True):
    pass

raises an

OSError: [Errno 63] File name too long

for perfectly valid (yes, quite long) file names.

Reason:

Internally the fileinput library creates a backup file when we pass 'inplace=True' to fileinput.input() and that backup file gets a file name that is longer than the name for the file of interest.

Enhancement idea:

Work with a backup file name that is sth like GUID.bak or remove some chars from the original file name.

Hint:

vim /path/to/my/file creates a .swp file and can handle very long file names with 252-255 chars.

----------
components: Library (Lib)
files: long_filename_passed_to_fileinput.ipynb
messages: 407534
nosy: jamil.raichouni
priority: normal
severity: normal
status: open
title: fileinput.input(path, inplace=True) crashes for valid filename with 252-255 characters
type: enhancement
versions: Python 3.10
Added file: https://bugs.python.org/file50471/long_filename_passed_to_fileinput.ipynb

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue45965>
_______________________________________


More information about the New-bugs-announce mailing list