Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/bin/subbub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -727,12 +727,14 @@ fn write_to_output(output: &Path, files: &Vec<(&Path, Vec<u8>)>) -> Result<()> {
return Err(anyhow!("no files to write to output"));
} else if files.len() == 1 {
// if there's only one file, write it directly to the output path
create_parent_directory(output)?;
let mut file = fs::File::create(output).context("could not create output file")?;
file.write_all(&files[0].1)
.context("could not write to output file")?;
return Ok(());
} else {
// if there are multiple files, write them to the output directory
std::fs::create_dir_all(output)?;
for (original_file, bytes) in files {
let destination_file =
output.join(original_file.file_name().context("file has no name")?);
Expand All @@ -744,3 +746,15 @@ fn write_to_output(output: &Path, files: &Vec<(&Path, Vec<u8>)>) -> Result<()> {
}
Ok(())
}

fn create_parent_directory(output: &Path) -> Result<()> {
match output.parent() {
Some(parent) => std::fs::create_dir_all(parent)
.context("could not create parent directory for output file"),
None => {
return Err(anyhow!(
"output path has no parent, cannot create parent directory"
));
}
}
}