Repository navigation
[filesystem] Preserve sibling ZIP files when writing non-ZIP extensions - #4342
Merged
anthrotype merged 2 commits intoOct 22, 2026
Merged
anthrotype merged 2 commits into
anthrotype merged 2 commits into
Conversation
anthrotype
reviewed
Oct 22, 2026
anthrotype
reviewed
Oct 22, 2026
Comment on lines
+225
to
+235
| if self._file == base_name + ".zip": | ||
| shutil.make_archive(base_name, format="zip", root_dir=self._temp_dir) | ||
| else: | ||
| with tempfile.TemporaryDirectory() as archive_dir: | ||
| archive = shutil.make_archive( | ||
| os.path.join(archive_dir, "archive"), | ||
| format="zip", | ||
| root_dir=self._temp_dir, | ||
| ) | ||
| os.makedirs(os.path.dirname(os.path.abspath(self._file)), exist_ok=True) | ||
| shutil.move(archive, self._file) |
Member
There was a problem hiding this comment.
I suggest we eliminate the branch where we special-case .zip and do the atomic replacement for all extensions. Also we can stage the archive in a temporary directory next to the destination file, so shutil.move() doesn't fall back to cross-filesystem copying:
def close(self):
if self.isclosed():
return
output_dir = os.path.dirname(os.path.abspath(self._file))
os.makedirs(output_dir, exist_ok=True)
with tempfile.TemporaryDirectory(dir=output_dir) as staging:
archive = shutil.make_archive(
os.path.join(staging, "archive"),
format="zip",
root_dir=self._temp_dir,
)
os.replace(archive, self._file)
super().close()
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Writing a .ufoz or extensionless archive currently stages it as .zip in the output directory. That destroys an unrelated ZIP with the same stem before moving the new archive to its final name.
Stage non-.zip output in a unique temporary directory, then move the completed archive to the requested filename. Keep direct .zip writes, automatic parent creation, and repeated-close behavior.
Regression tests preserve and read a real sibling ZIP, verify the requested archive, and cover .ufoz, uppercase .ZIP where it is a distinct name, extensionless output, and missing output parents.
Validation: the new tests produced 3 failures against unchanged production code; the patched module passes all 11 tests. The full suite passes 5,818 tests with 44 optional skips and 2 expected failures. Black checks pass. Native Windows/macOS execution remains for CI.
Validation results above are from the reviewed patch on upstream commit
8c0594d5187ab741d8782469d45114f289466144.