readline error when saving interactive command history when history file path is a symlink to a relative path
Personne n'a encore pris cette issue.
- Langage dominant
- Python
- Étoiles
- 77.2k
- Forks
- 35.9k
- Métriques de merge des PR
- Métriques de PR en attente
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
Guide de contribution
Ouvrir le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Piste de recherche
Commencez par reproduire le problème en utilisant un lien symbolique à cible relative et un répertoire de travail différent de $HOME. Lisez la logique history_tempfile de GNU readline dans histfile.c et suivez le chemin de CPython's readline.write_history_file jusqu'à celle-ci. Le travail est terminé lorsque l'enregistrement de l'historique réussit pour la disposition de lien symbolique décrite sur les configurations Linux testées, avec une couverture de régression pour ce cas.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Évaluation
- Stack technique
- linux, python
- Domaine
- cli, operating-systems
- Type d'issue
- Bug
- Difficulté
- 4/5
- Temps estimé
- 3-5 jours
- Activité
- À l'abandon
- Clarté
- Plutôt claire
- Accessibilité débutants
- 35/100