Avoid data loss in dedup_public.py when a link cannot be created#1020
Merged
Conversation
When replacing a duplicate file with a link to the canonical copy, the script unlinked the original before creating the symlink/hardlink. If os.symlink or os.link then failed, the file was left deleted with no replacement and was lost permanently. Create the link at a temporary path and atomically os.replace it over the original instead, so a failed link leaves the original file intact. This script runs during the production deploy (build_prod_incremental.sh / build_prod_per_lang.sh). Add a regression test that injects an os.symlink failure and asserts the original file survives, plus a success case.
Xpirix
approved these changes
Jun 29, 2026
Xpirix
left a comment
Collaborator
There was a problem hiding this comment.
Great fix @Valyrian-Code , thanks! LGTM
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.
Problem
scripts/dedup_public.pyreplaces a file that is byte-identical to a base-language file with a link to that canonical copy. It did so by unlinking the original before creating the replacement:If
os.symlink/os.linkthen fails (disk, permissions, cross-device for hardlinks, etc.), the file is left deleted with no replacement and is lost permanently. Theexceptonly prints; it cannot restore the file. This script runs during the production deploy (build_prod_incremental.sh/build_prod_per_lang.sh), so a single failure mid-run drops a published asset.Fix
Create the link at a temporary path first, then atomically
os.replaceit over the original. A failed link now leaves the original file untouched.Test
Adds
test/test_dedup_public.py(builds on the pytest harness from #1015):os.symlinkfailure and asserts the original file survives intact;Reverting the fix makes the first test fail (the file is lost), confirming it has teeth.