fix: replace panicking expect() with map_or() for edge-case file paths#2679
fix: replace panicking expect() with map_or() for edge-case file paths#2679srpatcha wants to merge 3 commits intomozilla:mainfrom
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2679 +/- ##
===========================================
- Coverage 74.17% 25.77% -48.41%
===========================================
Files 70 60 -10
Lines 39207 37206 -2001
===========================================
- Hits 29083 9588 -19495
- Misses 10124 27618 +17494 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Path::file_name() returns None for paths ending in '..' which caused a panic. Build cache tools should handle unusual paths gracefully.
9ed2e8a to
fbd8a8a
Compare
prepare_add updated pending size before tempfile_in(), which never rolled back on failure. This caused make_space() to panic later when encountering negative available space. Moved state update after successful tempfile creation and replaced .expect() with ? operator. Signed-off-by: Srikanth Patchava <spatchava@meta.com> Signed-off-by: Srikanth Patchava <srikanth.patchava@outlook.com>
Add comprehensive cache statistics tracking with: - Thread-safe atomic counters for hit/miss/eviction tracking - Cache size and entry count monitoring - JSON and human-readable output formats - Time-window aggregation (minute, hour, day) - Statistics snapshot and reset API - Fix TOCTOU race condition in DiskCache::put_raw Includes extensive test suite with thread safety tests. Signed-off-by: Srikanth Patchava <spatchava@meta.com>
|
you pr is doing too many different things (like fix the panic and change files permissions) |
|
Hi @sylvestre, thank you for the feedback! You're right — I'll split this into separate PRs:
I'll close this PR and submit them individually. Thanks for the review! |
|
Closing this PR as requested by @sylvestre. Split into focused PRs:
The cache statistics module will be submitted as a separate PR. Thank you for the feedback! |
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.