readline error when saving interactive command history when history file path is a symlink to a relative path
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 77.2k
- Forks
- 35.9k
- PR merge metrics
- PR metrics pending
Description
Bug report
Bug description:
To reproduce the issue
- Set up home directory like following:
$HOME/
.python_history --> foo/history_file
foo/
history_file
- Launch a Python interactive session with CWD different from
$HOME - Execute the following
import readline
import os
history_path=os.path.expanduser("~/.python_history")
assert os.path.exists(history_path)
readline.write_history_file(history_path)
- Observe the following error
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
FileNotFoundError: [Errno 2] No such file or directory
Possible cause
This is likely due to how GNU readline commits history information to file. As of GNU readline v8.2 (used in Python 3.10 and 3.12 among others), it creates a temporary file in the parent directory of the history file, write to that temporary file, and then rename the temporary file to the history file. See history_tempfile in histfile.c of GNU readline.
GNU readline determines the parent directory from the readlink output of the user-supplied history file path. In this case, since the history file is a symlink with a relative path, the parent directory is resolved to the relative path foo/. If foo/ doesn't exist in the CWD, history saving fails.
CPython versions tested on:
3.10, 3.12
Operating systems tested on:
Linux
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the reproduction using a relative-target symlink and a working directory different from $HOME. Read GNU readline's history_tempfile logic in histfile.c and trace how CPython's readline.write_history_file reaches it. Done means saving history succeeds for the described symlink layout on the tested Linux configurations, with regression coverage for the case.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- linux, python
- Domain
- cli, operating-systems
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100