fix: replace panicking expect() with map_or() for edge-case file paths#2679
Open
srpatcha wants to merge 1 commit intomozilla:mainfrom
Open
fix: replace panicking expect() with map_or() for edge-case file paths#2679srpatcha wants to merge 1 commit intomozilla:mainfrom
srpatcha wants to merge 1 commit intomozilla:mainfrom
Conversation
Path::file_name() returns None for paths ending in '..' which caused a panic. Build cache tools should handle unusual paths gracefully.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2679 +/- ##
==========================================
+ Coverage 74.17% 74.19% +0.01%
==========================================
Files 70 70
Lines 39207 39206 -1
==========================================
+ Hits 29083 29087 +4
+ Misses 10124 10119 -5 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
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.
Fix panic on edge-case file paths in LRU disk cache init
Problem
LruDiskCache::init()insrc/lru_disk_cache/mod.rscalls.expect("Bad path?")onfile.file_name(), which panics if the path ends in..or is otherwise unusual. A build cache tool should handle unexpected file system states gracefully rather than crashing.Root Cause
Path::file_name()returnsNonewhen the path terminates in..or consists solely of a root or prefix. The.expect()call converts this into a panic. While uncommon, symlinks or filesystem corruption could produce such paths in the cache directory.Fix
Replaced
.expect("Bad path?").starts_with(TEMPFILE_PREFIX)with.map_or(false, |name| name.starts_with(TEMPFILE_PREFIX)). Paths without a valid file name component are now treated as non-temporary files (skipping the cleanup branch) rather than crashing.Testing
...Impact
Affects sccache users whose cache directories may contain unusual file paths. A panic in cache init prevents the entire build cache from working.