readline error when saving interactive command history when history file path is a symlink to a relative path
还没有人认领这个 Issue。
- 主要语言
- Python
- 星标
- 77.2k
- 派生
- 35.9k
- PR 合并指标
- PR 指标待抓取
描述
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
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 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