Atomic append fails to create a missing file
評価
調査の方向性
_write_file_atomic から始めてください。append=True の場合、一時ファイルを作成する前に、移動先が無条件で読み込まれます。issue にある再現手順を、atomic=True を指定し、親ディレクトリとファイルが存在しない状態で実行し、その後 atomic=False の経路と比較してください。完了条件は、アトミックな追記で存在しないファイルが作成されること、2 回目の追記で以前の内容が保持されること、そして既存のテストがすべて通ることです。
索引モデルが issue の本文から書いたものです。
説明
Describe the bug
write_file(path, content, append=True, atomic=True) raises OSError: Invalid file path when the destination does not exist. The same call with atomic=False creates the file, consistent with append mode.
Reproduce
from pathlib import Path
from tempfile import TemporaryDirectory
import fsutil
with TemporaryDirectory() as directory:
path = str(Path(directory) / "new" / "file.txt")
fsutil.write_file(path, content="first", append=True, atomic=True)
Reproduced with Python 3.12.14 on Windows and python-fsutil 0.18.0 source at d3a77c552346dc72a081284a6fd017ecc1ba234f. No mocked filesystem or injected failure is required. This was found during a code review, rather than reported from a production application.
Expected behavior
Create the missing file, as non-atomic append does. A subsequent append should preserve its previous content.
Cause and scope
_write_file_atomic reads the destination unconditionally when append=True, before creating a temporary file. Reading a missing destination raises immediately.
This differs from #194: it does not concern errors after replacement or the Windows-specific FileNotFoundError cleanup handler. Those paths can remain unchanged.
AI assistance was used to investigate the source and prepare reproduction and tests. A focused fix is ready.
- 主要言語
- Python
- スター
- 268
- フォーク
- 19
- 平均マージ
- 8日 13時間
- マージ済み PR(30日)
- 4
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドなし
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
fabiocaccamo/python-fsutil のほかの issue
-
Add `toml` files operation support.再び着手できるかも @fabiocaccamo が 1321 日前に担当しましたが、オープン中のプルリクエストはありません。 オープンenhancement
fabiocaccamo/python-fsutil#42 · 担当者 1 名 ·
fabiocaccamo/python-fsutil の issue をすべて見る
似ている issue
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
Deltares/imod-python#1940 ·
メンテナーはふだん 1 日以内に返信
-
effort: low prio: low ready
難易度 1/5 1時間未満 初心者へのやさしさ 82/100
digitalfabrik/integreat-cms#4621 ·
メンテナーはふだん 5 日以内に返信
-
難易度 1/5 1時間未満 初心者へのやさしさ 88/100
ioos/compliance-checker#1375 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
メンテナーはふだん 1 日以内に返信
-
netbox status: backlog topic: testing type: housekeeping
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
netbox-community/netbox#23395 ·
メンテナーはふだん 1 日以内に返信