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 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 Issue。

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. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 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 摘要。