python / python/cpython

pathlib.Path.touch incorrectly raises FileNotFoundError

Open
#96,366 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

stdlib type-bug
Dominant language
Python
Stars
77.2k
Forks
36k
PR merge metrics
PR metrics pending

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the three pathlib.Path.touch calls on CPython 3.10.4 under Ubuntu 22.04 in WSL2, then inspect pathlib.py at lines 1166 and 331. Determine whether the reported FileNotFoundError is reproducible and what filesystem condition causes it; done means a confirmed diagnosis with a focused regression test or a documented explanation.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
operating-systems
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.