Atomic append fails to create a missing file
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 70/100
Hướng nghiên cứu
Bắt đầu từ _write_file_atomic, nơi đích được đọc vô điều kiện khi append=True trước khi tệp tạm được tạo. Chạy lại bước tái hiện trong issue với atomic=True và thư mục cha cùng tệp đều không tồn tại, sau đó so sánh với đường dẫn atomic=False. Hoàn thành khi thao tác append nguyên tử tạo được tệp còn thiếu, lần append thứ hai giữ lại nội dung trước đó, và các test hiện có vẫn pass.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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.
- Ngôn ngữ chính
- Python
- Star
- 268
- Fork
- 19
- Merge trung bình
- 8 ngày 13 giờ
- Pull request đã merge (30 ngày)
- 4
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Không có hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của fabiocaccamo/python-fsutil
-
Add `toml` files operation support.Có thể làm lại được @fabiocaccamo đã nhận 1321 ngày trước và không có pull request nào đang mở. Đang mởenhancement
fabiocaccamo/python-fsutil#42 · 1 người được giao ·
Tất cả issue của fabiocaccamo/python-fsutil
Issue tương tự
-
Agentic
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
Imbad0202/academic-research-skills#979 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
reflex-dev/reflex#7561 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
prometheus-community/ansible#906 · 2 bình luận ·