python / python/cpython

readline error when saving interactive command history when history file path is a symlink to a relative path

Aperta
#129,453 2 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

extension-modules type-bug
Lingua principale
Python
Stelle
77.2k
Fork
35.9k
Metriche di merge delle PR
Metriche PR in attesa

Descrizione

Bug report

Bug description:

To reproduce the issue

  1. Set up home directory like following:
$HOME/
  .python_history --> foo/history_file
  foo/
    history_file
  1. Launch a Python interactive session with CWD different from $HOME
  2. 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)
  1. 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

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia con la riproduzione usando un symlink con destinazione relativa e una directory di lavoro diversa da $HOME. Leggi la logica history_tempfile di GNU readline in histfile.c e segui come CPython's readline.write_history_file la raggiunge. Il lavoro è concluso quando il salvataggio della cronologia riesce per la disposizione del symlink descritta sulle configurazioni Linux testate, con una copertura di regressione per questo caso.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
linux, python
Ambito
cli, operating-systems
Tipo di issue
Bug
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
35/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.