fix: create parent directories before injecting file into ext4 image - #55
Conversation
| if let Some(parent) = Path::new(guest_path).parent() | ||
| && !parent.as_os_str().is_empty() | ||
| { | ||
| fs.mkdir_p(&parent.to_string_lossy())?; |
There was a problem hiding this comment.
no test for nested guest_path — this will regress silently
There was a problem hiding this comment.
Agreed, but the test can't pass yet — Filesystem::open never loads the bitmaps, so mkdir_p fails with EXT2_ET_NO_INODE_BITMAP on any reopened image. I'll open a separate issue for that and add the nested + idempotency coverage here once it's fixed.
| @@ -589,6 +615,11 @@ pub fn create_from_dir(source_dir: &Path, output: &Path, size_bytes: u64) -> Res | |||
| /// Returns an error if the image cannot be opened or the write fails. | |||
There was a problem hiding this comment.
docs still say this is plain debugfs write; it now does mkdir -p on parents
| /// Returns an error if a directory cannot be created for a reason other | ||
| /// than it already existing. | ||
| pub fn mkdir_p(&mut self, name: &str) -> Result<()> { | ||
| const EXT2_ET_DIR_EXISTS: i64 = 2_133_571_328 + 79; |
There was a problem hiding this comment.
nit: this base already lives in error.rs — share it, and map 79 there
There was a problem hiding this comment.
This issue involves a large-scale modification of error.rs, and the error types in error.rs are not exposed externally. The scope of changes exceeds this issue, so I suggest opening a separate issue to address it.
Description
Fixes an issue where injecting a file into an ext4 image fails if the target path's parent directories do not exist in the image.
inject_filenow creates all missing parent directories before writing the file.Changes
Filesystem::mkdir_pincrates/bux-e2fs/src/ext4.rs, which creates a directory and all missing intermediate directories, ignoringEXT2_ET_DIR_EXISTSerrorsinject_fileto callmkdir_pon the parent path before writing the file