python / python/cpython

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

オープン
#129,453 コメント 2 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

extension-modules type-bug
主要言語
Python
スター
77.2k
フォーク
35.9k
PR マージ指標
PR 指標を取得中

説明

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

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

相対ターゲットのシンボリックリンクと、$HOME とは異なる作業ディレクトリを使って再現するところから始めます。histfile.c にある GNU readline の history_tempfile のロジックを読み、CPython's readline.write_history_file がどのようにそこへ到達するかを追跡します。テストした Linux 構成で、説明したシンボリックリンク構成に対する履歴の保存が成功し、このケースのリグレッションカバレッジが追加されていれば完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
linux, python
領域
cli, operating-systems
issue の種類
バグ
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
35/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。