Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

Atomic append fails to create a missing file

Đang mở Phù hợp với người mới
#201 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

@harbinresearcher đang làm issue này rồi.

Từ ngày 14/10/2026.

  • #202 của @harbinresearcher — đang mở

Đá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
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
python
Lĩnh vực
backend

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

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. 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.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của fabiocaccamo/python-fsutil

Tất cả issue của fabiocaccamo/python-fsutil

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.