Skip to content

Commit cbfe284

Browse files
Fix cache directory creation in per_file_cache
Ensure parent directories exist before writing cache files. This fixes a test failure where cache writes would fail if the cache directory structure didn't already exist. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent 8387c3b commit cbfe284

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/packs/caching/per_file_cache.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,17 @@ impl Cache for PerFileCache {
5353

5454
let cache_data = serde_json::to_string(&cache_entry)
5555
.context("Failed to serialize references")?;
56+
57+
// Ensure parent directory exists
58+
if let Some(parent) = empty_cache_entry.cache_file_path.parent() {
59+
std::fs::create_dir_all(parent).map_err(|e| {
60+
anyhow::Error::new(e).context(format!(
61+
"Failed to create cache directory {:?}",
62+
parent
63+
))
64+
})?;
65+
}
66+
5667
let mut file = File::create(&empty_cache_entry.cache_file_path)
5768
.map_err(|e| {
5869
anyhow::Error::new(e).context(format!(

tests/gitignore_test.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ fn test_check_ignores_violations_in_gitignored_files(
5151

5252
/// Test that list-included-files respects gitignore patterns.
5353
#[test]
54-
fn test_list_included_files_excludes_gitignored() -> Result<(), Box<dyn Error>> {
54+
fn test_list_included_files_excludes_gitignored() -> Result<(), Box<dyn Error>>
55+
{
5556
let output = Command::cargo_bin("pks")?
5657
.arg("--project-root")
5758
.arg("tests/fixtures/app_with_gitignore")

0 commit comments

Comments
 (0)