Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

Atomic append fails to create a missing file

未关闭 适合新手
#201 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

@harbinresearcher 已经在做这个了。

开始于 2026年10月14日。

  • #202 来自 @harbinresearcher —— 未关闭

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
70/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
python
领域
backend

调研方向

从 _write_file_atomic 开始,在 append=True 时,目标文件会在创建临时文件之前被无条件读取。使用 issue 中的复现步骤,设置 atomic=True,并让父目录和文件都不存在,然后与 atomic=False 路径进行比较。完成的标准是:原子追加会创建缺失的文件,第二次追加保留之前的内容,并且现有测试仍然通过。

由索引模型根据 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 小时
30 天内合并 PR
4

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 有 Pull Request 模板
  • 没有贡献指南

从这里开始

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

fabiocaccamo/python-fsutil 的其他 Issue

查看 fabiocaccamo/python-fsutil 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

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