Skip to content

Commit 7eb1aa2

Browse files
shi2wei3claude
andcommitted
cache_metadata: Fix parent directory handling for bare filenames
When a bare filename like "disk.img" is passed to bcvk to-disk, path.parent() returns Some("") (empty string) instead of None. This caused Dir::open_ambient_dir() to fail with "No such file or directory" when trying to open an empty path. The fix filters out empty parent paths and defaults to "." (current directory) for bare filenames, while preserving existing behavior for relative and absolute paths. Fixes both check_cached_disk() and read_image_digest_from_path(). 🤖 Generated with [Claude Code](https://claude.com/claude-code) Assisted-by: Claude Code (Sonnet 4.5) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent b5c86ee commit 7eb1aa2

1 file changed

Lines changed: 4 additions & 6 deletions

File tree

crates/kit/src/cache_metadata.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,8 @@ impl DiskImageMetadata {
123123
}
124124

125125
// Get the parent directory and file name
126-
let parent = path
127-
.parent()
128-
.ok_or_else(|| color_eyre::eyre::eyre!("Path has no parent directory"))?;
126+
// Use current directory if parent is empty (for bare filenames like "disk.img")
127+
let parent = path.parent().filter(|p| !p.as_os_str().is_empty()).unwrap_or(Path::new("."));
129128
let file_name = path
130129
.file_name()
131130
.ok_or_else(|| color_eyre::eyre::eyre!("Path has no file name"))?;
@@ -191,9 +190,8 @@ pub fn check_cached_disk(
191190
let expected_hash = expected_meta.compute_cache_hash();
192191

193192
// Read the cache hash from the disk image
194-
let parent = path
195-
.parent()
196-
.ok_or_else(|| color_eyre::eyre::eyre!("Path has no parent directory"))?;
193+
// Use current directory if parent is empty (for bare filenames like "disk.img")
194+
let parent = path.parent().filter(|p| !p.as_os_str().is_empty()).unwrap_or(Path::new("."));
197195
let file_name = path
198196
.file_name()
199197
.ok_or_else(|| color_eyre::eyre::eyre!("Path has no file name"))?;

0 commit comments

Comments
 (0)