Skip to content
Merged
Show file tree
Hide file tree
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
18 changes: 8 additions & 10 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ rust-version = "1.91" # if this changes, edit ci.yaml as well!
# `git`-based deps
gimlet-inspector-protocol = { git = "https://github.com/oxidecomputer/gimlet-inspector-protocol" }
hif = { git = "https://github.com/oxidecomputer/hif" }
hubtools = { git = "https://github.com/oxidecomputer/hubtools.git" }
hubtools = { git = "https://github.com/oxidecomputer/hubtools.git", version = "0.4.9" }
humpty = { git = "https://github.com/oxidecomputer/humpty", version = "0.1.5" }
idol = { git = "https://github.com/oxidecomputer/idolatry.git" }
idt8a3xxxx = { git = "https://github.com/oxidecomputer/idt8a3xxxx" }
Expand Down
1 change: 0 additions & 1 deletion cmd/dump/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ lzss.workspace = true
num-traits.workspace = true
parse_int.workspace = true
zerocopy.workspace = true
zip.workspace = true

humility.workspace = true
humility-cli.workspace = true
Expand Down
1 change: 0 additions & 1 deletion cmd/extract/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ description = "extract all or part of a Hubris archive"
[dependencies]
anyhow.workspace = true
clap.workspace = true
zip.workspace = true

humility-cli.workspace = true
humility-log.workspace = true
30 changes: 9 additions & 21 deletions cmd/extract/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,7 @@ use clap::Parser;
use humility_cli::{ExecutionContext, humility_cmd};
use humility_log::info;
use std::fs::File;
use std::io::Cursor;
use std::io::{self, Read, Write};
use std::io::{self, Write};

#[derive(Parser, Debug)]
#[clap(name = "extract", about = env!("CARGO_PKG_DESCRIPTION"))]
Expand All @@ -157,32 +156,24 @@ fn extract(subargs: ExtractArgs, context: &mut ExecutionContext) -> Result<()> {
let log = context.log();

if subargs.list {
// We convert the archive data back into a `ZipArchive` instead of using
// `RawHubrisArchive` functions for speed; the `ZipArchive` can report
// file size without uncompressing.
let cursor = Cursor::new(archive.zip);
let mut archive = zip::ZipArchive::new(cursor)?;

println!("{:>12} NAME", "SIZE");

for i in 0..archive.len() {
let file = archive.by_index(i)?;
println!("{:12} {}", file.size(), file.name());
for i in 0..archive.file_count()? {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

It seems like we might want a file iterator for this, not sure if this is something we do or if it's a dependency thing yet, will check.

edit: nope, it's a zip::ZipArchive thing, and doing it by index is actually how they recommend doing it in their example. Boo.

let file = archive.file_metadata_by_index(i)?;
println!("{:12} {}", file.size, file.name);
}

return Ok(());
}

let buffer = if let Some(ref filename) = subargs.file {
let cursor = Cursor::new(archive.zip);
let mut archive = zip::ZipArchive::new(cursor)?;
let mut found = vec![];

for i in 0..archive.len() {
let file = archive.by_index(i)?;
for i in 0..archive.file_count()? {
let file = archive.file_metadata_by_index(i)?;

if file.name().contains(filename) {
found.push((i, file.name().to_string()));
if file.name.contains(filename) {
found.push((i, file.name));
}
}

Expand All @@ -207,10 +198,7 @@ fn extract(subargs: ExtractArgs, context: &mut ExecutionContext) -> Result<()> {

info!(log, "extracting {} to stdout", found[0].1);

let mut file = archive.by_index(found[0].0)?;

let mut buffer = Vec::new();
file.read_to_end(&mut buffer)?;
let (_, buffer) = archive.extract_file_by_index(found[0].0)?;
buffer
} else {
archive.zip.to_vec()
Expand Down
10 changes: 4 additions & 6 deletions humility-core/src/hubris.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1504,10 +1504,8 @@ impl HubrisArchive {
let mut objects = (0..hubris.file_count()?)
.into_par_iter()
.map(|i| -> Result<Option<(usize, String, Vec<u8>)>> {
// TODO(matt) once hubtools#65 is merged, this can be made more
// efficient; right now, it extracts every file.
let (name, data) = hubris.extract_file_by_index(i)?;
let path = Path::new(&name);
let meta = hubris.file_metadata_by_index(i)?;
let path = Path::new(&meta.name);
let pieces = path.iter().collect::<Vec<_>>();

//
Expand All @@ -1518,10 +1516,10 @@ impl HubrisArchive {
return Ok(None);
}

let filename = Path::new(&name);
let (_, data) = hubris.extract_file_by_index(i)?;
Ok(Some((
i,
filename.file_name().unwrap().to_str().unwrap().to_owned(),
path.file_name().unwrap().to_str().unwrap().to_owned(),
data,
)))
})
Expand Down
Loading