fix: keep existing contents in create_file

This commit is contained in:
2026-09-04 09:17:20 +00:00
parent a301097120
commit ec4168769e

View File

@@ -19,6 +19,12 @@ fn safe_create_file(path: PathBuf) -> Result<File, std::io::Error> {
OpenOptions::new().write(true).create_new(true).open(path) OpenOptions::new().write(true).create_new(true).open(path)
} }
// truncate(false) keeps an existing file's contents, which is what callers creating
// an empty __init__.py want
fn create_file(path: PathBuf) -> Result<File, std::io::Error> { fn create_file(path: PathBuf) -> Result<File, std::io::Error> {
OpenOptions::new().write(true).create(true).open(path) OpenOptions::new()
.write(true)
.create(true)
.truncate(false)
.open(path)
} }