Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ All notable changes to Diskern are documented here. The format follows

## [Unreleased]

### Added

- npm download caches are now classified as safe package-manager cache files

### Fixed

- The CLI scan summary now says "1 file" instead of "1 files" when a
Expand Down
7 changes: 7 additions & 0 deletions crates/diskern-core/rules/base.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,13 @@
"verdict": "safe",
"description": "pip download cache. Packages are re-downloaded on demand."
},
{
"id": "npm-cache",
"patterns": ["**/.npm/_cacache/**", "**/appdata/local/npm-cache/**"],
"category": "package_manager_cache",
"verdict": "safe",
"description": "npm's download cache. Re-fetched on demand; removing it only makes the next install download packages again."
},
{
"id": "unix-system-logs",
"patterns": ["/var/log/**", "/private/var/log/**"],
Expand Down
32 changes: 32 additions & 0 deletions crates/diskern-core/src/rules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,38 @@ mod tests {
}
}

#[test]
fn npm_cache_is_safe_to_remove() {
let db = RulesDb::embedded();
for path in [
"/home/u/.npm/_cacache/content-v2/sha512/aa/package",
"/Users/u/.npm/_cacache/index-v5/ab/cd",
"C:\\Users\\u\\AppData\\Local\\npm-cache\\_cacache\\content-v2\\sha512\\aa\\package",
] {
let (cat, verdict, rule) = db.classify(std::path::Path::new(path));
assert_eq!(
cat,
Category::PackageManagerCache,
"{path} matched {rule:?}"
);
assert_eq!(verdict, Verdict::Safe, "{path} matched {rule:?}");
}
}

#[test]
fn npm_state_outside_the_download_cache_is_not_marked_safe() {
let db = RulesDb::embedded();
for path in [
"/home/u/.npmrc",
"/home/u/.npm/_logs/2026-09-12-debug.log",
"C:\\Users\\u\\AppData\\Roaming\\npm\\npmrc",
] {
let (cat, verdict, rule) = db.classify(std::path::Path::new(path));
assert_eq!(cat, Category::Unknown, "{path} matched {rule:?}");
assert_ne!(verdict, Verdict::Safe, "{path} matched {rule:?}");
}
}

/// An installed application's own repair binary is not a reclaimable
/// download. `unknown` is the right answer: report::build drops those,
/// so it never reaches the user as an actionable row.
Expand Down
Loading