python / python/cpython

pathlib.Path.touch incorrectly raises FileNotFoundError

未关闭
#96,366 2 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

stdlib type-bug
主要语言
Python
星标
77.2k
派生
36k
PR 合并指标
PR 指标待抓取

描述

Bug report

In ipython, the first two calls to pathlib.Path.touch succeed but the third fails. I see no reason that it should fail, and if it should, the error raised is incorrect.

from pathlib import Path
log_filename = Path('/mnt/c/Users/Michael/OneDrive/PycharmProjects/beta_numbers/logs/perron_numbers_log0.txt')
log_filename.touch() # success
log_filename = Path('/mnt/c/Users/Michael/OneDrive/PycharmProjects/beta_numbers/logs/perron_numbers_log_.txt')
log_filename.touch() # success
log_filename = Path('/mnt/c/Users/Michael/OneDrive/PycharmProjects/beta_numbers/logs/perron_numbers_log_0.txt')
log_filename.touch()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3.10/pathlib.py", line 1166, in touch
    self._accessor.touch(self, mode, exist_ok)
  File "/usr/lib/python3.10/pathlib.py", line 331, in touch
    fd = os.open(path, flags, mode)
FileNotFoundError: [Errno 2] No such file or directory: '/mnt/c/Users/Michael/OneDrive/PycharmProjects/beta_numbers/logs/perron_numbers_log_0.txt'

Contents of /mnt/c/Users/Michael/OneDrive/PycharmProjects/beta_numbers/logs prior to the first touch:

  • -3_-1_-7.log
  • -7_-29_-43.log
  • -8_-3_-17.log
  • -9_-35_-51.log
  • analyze.log
  • find_close_orbit.log
  • test_log.txt
  • testy.log
  • update_legacy_data.log

Your environment

  • CPython versions tested on: 3.10.4
  • Operating system and architecture: Ubuntu 22.04 run on a Windows 10 x64 device through WSL2

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

首先,在 WSL2 中的 Ubuntu 22.04 上使用 CPython 3.10.4 重现三次 pathlib.Path.touch 调用,然后检查 pathlib.py 的第 1166 行和第 331 行。确定所报告的 FileNotFoundError 是否可以重现,以及是什么文件系统条件导致了它;完成的标准是确认诊断结果,并提供一个有针对性的回归测试或一份记录在案的解释。

由索引模型根据 Issue 内容生成。

评估

技术栈
python
领域
operating-systems
Issue 类型
缺陷
难度
4/5
预计耗时
3-5 天
活跃度
停滞
描述清晰度
需要澄清
新手友好度
35/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。