Skip to content

fix: create parent directories before injecting file into ext4 image - #55

Merged
gitctrlx merged 2 commits into
qntx:mainfrom
JingMox:fix/54-inject-file-parent-directorie
Aug 12, 2026
Merged

fix: create parent directories before injecting file into ext4 image#55
gitctrlx merged 2 commits into
qntx:mainfrom
JingMox:fix/54-inject-file-parent-directorie

Conversation

@JingMox

@JingMox JingMox commented Aug 12, 2026

Copy link
Copy Markdown
Member

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_file now creates all missing parent directories before writing the file.

Changes

  • Add Filesystem::mkdir_p in crates/bux-e2fs/src/ext4.rs, which creates a directory and all missing intermediate directories, ignoring EXT2_ET_DIR_EXISTS errors
  • Update inject_file to call mkdir_p on the parent path before writing the file
  • Fixes bug: inject_file does not create parent directories #54

@gitctrlx gitctrlx left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks correct. Fixes #54. Main gap is missing coverage for nested inject.

if let Some(parent) = Path::new(guest_path).parent()
&& !parent.as_os_str().is_empty()
{
fs.mkdir_p(&parent.to_string_lossy())?;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no test for nested guest_path — this will regress silently

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread crates/bux-e2fs/src/ext4.rs Outdated
@@ -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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: this base already lives in error.rs — share it, and map 79 there

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@gitctrlx
gitctrlx merged commit 8fc26ee into qntx:main Aug 12, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: inject_file does not create parent directories

2 participants