Skip to content

Commit d933282

Browse files
shi2wei3claude
authored 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 <[email protected]> Signed-off-by: Wei Shi <[email protected]>
1 parent 7022bd9 commit d933282

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

crates/kit/src/cache_metadata.rs

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

125125
// Get the parent directory and file name
126+
// Use current directory if parent is empty (for bare filenames like "disk.img")
126127
let parent = path
127128
.parent()
128-
.ok_or_else(|| color_eyre::eyre::eyre!("Path has no parent directory"))?;
129+
.filter(|p| !p.as_os_str().is_empty())
130+
.unwrap_or(Path::new("."));
129131
let file_name = path
130132
.file_name()
131133
.ok_or_else(|| color_eyre::eyre::eyre!("Path has no file name"))?;
@@ -191,9 +193,11 @@ pub fn check_cached_disk(
191193
let expected_hash = expected_meta.compute_cache_hash();
192194

193195
// Read the cache hash from the disk image
196+
// Use current directory if parent is empty (for bare filenames like "disk.img")
194197
let parent = path
195198
.parent()
196-
.ok_or_else(|| color_eyre::eyre::eyre!("Path has no parent directory"))?;
199+
.filter(|p| !p.as_os_str().is_empty())
200+
.unwrap_or(Path::new("."));
197201
let file_name = path
198202
.file_name()
199203
.ok_or_else(|| color_eyre::eyre::eyre!("Path has no file name"))?;

0 commit comments

Comments
 (0)