Skip to content

Commit

Permalink
utils/codesign: Limit files passed to signtool at once to 20
Browse files Browse the repository at this point in the history
  • Loading branch information
derrod committed Jan 29, 2024
1 parent a437748 commit c896b89
Showing 1 changed file with 22 additions and 12 deletions.
34 changes: 22 additions & 12 deletions src/utils/codesign.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#![allow(unused_variables)]

use std::ffi::OsString;
use std::io::Write;
use std::path::{Path, PathBuf};
Expand All @@ -13,6 +14,8 @@ use winreg::RegKey;

use crate::models::config::CodesignOptions;

const MAX_FILES: usize = 20;

#[cfg(windows)]
pub fn sign(files: Vec<PathBuf>, opts: &CodesignOptions) -> Result<()> {
let signtool = locate_signtool()?;
Expand Down Expand Up @@ -41,22 +44,29 @@ pub fn sign(files: Vec<PathBuf>, opts: &CodesignOptions) -> Result<()> {
args.push(kms_id.into());
}

for x in files {
args.push(x.to_owned().into_os_string())
}
let slices = (files.len() + MAX_FILES - 1) / MAX_FILES;
let mut ctr = 0;

for chunk in files.chunks(MAX_FILES) {
ctr += 1;
let mut chunk_args = args.to_owned();
for x in chunk {
chunk_args.push(x.to_owned().into_os_string())
}

info!(" => Running signtool...");
let output = Command::new(signtool).args(args).output()?;
info!(" => Running signtool ({ctr}/{slices})...");
let output = Command::new(&signtool).args(chunk_args).output()?;

if !output.status.success() {
error!("signtool returned non-success status: {}", output.status);
std::io::stdout().write_all(&output.stdout)?;
std::io::stderr().write_all(&output.stderr)?;
if !output.status.success() {
error!("signtool returned non-success status: {}", output.status);
std::io::stdout().write_all(&output.stdout)?;
std::io::stderr().write_all(&output.stderr)?;

Err(anyhow!("signtool failed (see stdout/stderr for details)"))
} else {
Ok(())
return Err(anyhow!("signtool failed (see stdout/stderr for details)"));
}
}

Ok(())
}

#[cfg(unix)]
Expand Down

0 comments on commit c896b89

Please sign in to comment.