Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add parameters to specify target filename #49

Merged
merged 1 commit into from
Jan 18, 2024
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
21 changes: 19 additions & 2 deletions src/bin/download_sysext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,15 +268,15 @@ where
})
}

fn do_download_verify(pkg: &mut Package<'_>, output_dir: &Path, unverified_dir: &Path, pubkey_file: &str, client: &Client, print_progress: bool) -> Result<()> {
fn do_download_verify(pkg: &mut Package<'_>, output_filename: Option<String>, output_dir: &Path, unverified_dir: &Path, pubkey_file: &str, client: &Client, print_progress: bool) -> Result<()> {
pkg.check_download(unverified_dir)?;

pkg.download(unverified_dir, client, print_progress).context(format!("unable to download \"{:?}\"", pkg.name))?;

// Unverified payload is stored in e.g. "output_dir/.unverified/oem.gz".
// Verified payload is stored in e.g. "output_dir/oem.raw".
let pkg_unverified = unverified_dir.join(&*pkg.name);
let pkg_verified = output_dir.join(pkg_unverified.with_extension("raw").file_name().unwrap_or_default());
let pkg_verified = output_dir.join(output_filename.as_ref().map(OsStr::new).unwrap_or(pkg_unverified.with_extension("raw").file_name().unwrap_or_default()));

let datablobspath = pkg.verify_signature_on_disk(&pkg_unverified, pubkey_file).context(format!("unable to verify signature \"{}\"", pkg.name))?;

Expand All @@ -295,6 +295,10 @@ struct Args {
#[argh(option, short = 'o')]
output_dir: String,

/// target filename in directory, requires --payload-url or --take-first-match
#[argh(option, short = 'n')]
target_filename: Option<String>,

/// path to the Omaha XML file, or - to read from stdin
#[argh(option, short = 'i')]
input_xml: Option<String>,
Expand All @@ -312,6 +316,10 @@ struct Args {
#[argh(option, short = 'm')]
image_match: Vec<String>,

/// only take the first matching entry
#[argh(switch, short = 't')]
take_first_match: bool,

/// report download progress
#[argh(switch, short = 'v')]
print_progress: bool,
Expand All @@ -338,6 +346,10 @@ fn main() -> Result<(), Box<dyn Error>> {
let args: Args = argh::from_env();
println!("{:?}", args);

if args.payload_url.is_none() && !args.take_first_match && args.target_filename.is_some() {
return Err("--target-filename can only be specified with --take-first-match".into());
}

let glob_set = args.image_match_glob_set()?;

let output_dir = Path::new(&*args.output_dir);
Expand Down Expand Up @@ -391,6 +403,7 @@ fn main() -> Result<(), Box<dyn Error>> {
)?;
do_download_verify(
&mut pkg_fake,
args.target_filename.clone(),
output_dir,
unverified_dir.as_path(),
args.pubkey_file.as_str(),
Expand Down Expand Up @@ -424,12 +437,16 @@ fn main() -> Result<(), Box<dyn Error>> {
for pkg in pkgs_to_dl.iter_mut() {
do_download_verify(
pkg,
args.target_filename.clone(),
output_dir,
unverified_dir.as_path(),
args.pubkey_file.as_str(),
&client,
args.print_progress,
)?;
if args.take_first_match {
break;
}
}

// clean up data
Expand Down
Loading