#5304: mix relative path into Cache.dirSha so a file rename changes the hash#5320
Merged
yegor256 merged 2 commits intoJul 8, 2026
Merged
Conversation
…me changes the hash
Contributor
🚀 Performance AnalysisAll benchmarks are within the acceptable range. No critical degradation detected (threshold is 100%). Please refer to the detailed report for more information. Click to see the detailed report
✅ Performance gain: |
|
Contributor
Author
|
@yegor256, please take a look when you have a moment. |
|
@morphqdd Thanks for the contribution! You've earned +16 points. Please, keep them coming. Your running score is +588; don't forget to check your Zerocracy account too). |
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.



Closes #5304.
Cache.dirSha— the production directory-hashing path used byLinting,Transpiling, andParsingto decide whether cached compiled output can be reused — hashed each regular file'scontent independently (
new Sha(p).toString()), sorted by path only for iteration order, butnever fed the path itself into the digest. Two single-file directories whose one file has
identical content but a different name produced the exact same per-file content hash, so
dirSha(dirA)anddirSha(dirB)came out byte-for-byte identical — even though a file's name issemantically significant in this toolchain (the compiled output for
original-name.eoencodesthat name). Since
Cache.applytreats ashamatch as "reuse the cached content," a rename thathappens to collide this way could make the cache silently serve compiled output built for a
different file name.
This is the other half of the defect already fixed for
Sha.hash's own directory branch in#5254/#5262 — that fix addressed the delimiter-injection half (concatenating raw file contents
with no boundary), while
Cache.dirSha's independent reimplementation sidestepped that half (eachper-file contribution is already a fixed-length Base64 SHA-256 string) but never addressed the
path-omission half at all.
Mixed each file's relative path into the digest alongside its content hash, joined by a NUL byte
(
rel_path + "\0" + Sha(file), matching the fix suggested in the issue) — a NUL is safe as aseparator since file paths can't contain one, unlike a printable delimiter such as a space.
Test
Updated the existing
generatesCorrectHashForEntireFolderWithSeveralFilestest to expect the newper-entry format (
"file1.txt\0" + hashinstead of justhash).Added
generatesDifferentHashesForFoldersWithDifferentlyNamedIdenticalFiles, reproducing theexact scenario from the issue: two directories,
dirA/original-name.eoanddirB/completely-different-name.eo, both containing the same content, asserting their cached.sha256files are no longer identical.Ran the full
CacheTestsuite locally — all 10 tests pass.