Skip to content

Commit

Permalink
disable app_id generation, add custom timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
QaidVoid committed Jan 6, 2025
1 parent 9f14133 commit 2ddf03b
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 53 deletions.
4 changes: 0 additions & 4 deletions sbuild-linter/src/build_config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,6 @@ impl BuildConfig {
}
if let Some(val) = values.get("app_id") {
config.app_id = val.as_str().map(String::from);
} else {
config.app_id = Some(get_pkg_id(
&to_string_vec(values.get("src_url").unwrap()).unwrap()[0],
));
}
if let Some(val) = values.get("build_util") {
config.build_util = to_string_vec(val);
Expand Down
7 changes: 4 additions & 3 deletions sbuild-linter/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,12 @@ pub struct BuildAsset {

pub struct Linter {
logger: Logger,
timeout: Duration,
}

impl Linter {
pub fn new(logger: Logger) -> Self {
Linter { logger }
pub fn new(logger: Logger, timeout: Duration) -> Self {
Linter { logger, timeout }
}

pub fn lint(
Expand Down Expand Up @@ -212,7 +213,7 @@ impl Linter {
let _ = tx.send(cmd);
});

match rx.recv_timeout(Duration::from_secs(30)) {
match rx.recv_timeout(self.timeout) {
Ok(cmd_result) => {
match cmd_result {
Ok(cmd) => {
Expand Down
92 changes: 46 additions & 46 deletions sbuild-linter/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use std::{
Arc, LazyLock,
},
thread,
time::Instant,
time::{Duration, Instant},
};

use colored::Colorize;
Expand All @@ -35,6 +35,7 @@ Options:
--inplace, -i Replace the original file on success
--success <PATH> File to store successful packages list
--fail <PATH> File to store failed packages list
--timeout <DURATION> Timeout duration after which the pkgver check exits
--help, -h Show this help message
Arguments:
Expand All @@ -52,6 +53,7 @@ fn main() {
let mut inplace = false;
let mut success_path = None;
let mut fail_path = None;
let mut timeout = 30;

let mut iter = args.iter().skip(1);
while let Some(arg) = iter.next() {
Expand Down Expand Up @@ -106,6 +108,18 @@ fn main() {
parallel = Some(4);
}
}
"--timeout" => {
if let Some(next) = iter.next() {
match next.parse::<usize>() {
Ok(duration) => timeout = duration,
Err(_) => {
eprintln!("Invalid duration: '{}'", next);
eprintln!("{}", usage());
std::process::exit(1);
}
};
}
}
"--help" | "-h" => {
println!("{}", usage());
return;
Expand Down Expand Up @@ -194,60 +208,46 @@ fn main() {
}
});

if let Some(par) = parallel {
let semaphore = Arc::new(Semaphore::new(par));
let mut handles = Vec::new();
let files = files.clone();

for file_path in files {
let semaphore = Arc::clone(&semaphore);
let success = Arc::clone(&success);
let logger = logger.clone();
let fail = Arc::clone(&fail);
let success_store = success_store.clone();
let fail_store = fail_store.clone();
let semaphore = Arc::new(Semaphore::new(parallel.unwrap_or(1)));
let mut handles = Vec::new();

semaphore.acquire();
let handle = thread::spawn(move || {
let linter = Linter::new(logger);
if linter
.lint(&file_path, inplace, disable_shellcheck, pkgver)
.is_some()
{
if let Some(mut success_store) = success_store {
let fp = format!("{}\n", file_path);
let _ = success_store.write_all(fp.as_bytes());
}
success.fetch_add(1, Ordering::SeqCst);
} else {
if let Some(mut fail_store) = fail_store {
let fp = format!("{}\n", file_path);
let _ = fail_store.write_all(fp.as_bytes());
}
fail.fetch_add(1, Ordering::SeqCst);
}
for file_path in &files {
let file_path = file_path.clone();
let semaphore = Arc::clone(&semaphore);
let success = Arc::clone(&success);
let logger = logger.clone();
let fail = Arc::clone(&fail);
let success_store = success_store.clone();
let fail_store = fail_store.clone();

semaphore.release();
});

handles.push(handle);
}

for handle in handles {
handle.join().unwrap();
}
} else {
for file_path in &files {
let linter = Linter::new(logger.clone());
semaphore.acquire();
let handle = thread::spawn(move || {
let linter = Linter::new(logger, Duration::from_secs(timeout as u64));
if linter
.lint(file_path, inplace, disable_shellcheck, pkgver)
.lint(&file_path, inplace, disable_shellcheck, pkgver)
.is_some()
{
if let Some(mut success_store) = success_store {
let fp = format!("{}\n", file_path);
let _ = success_store.write_all(fp.as_bytes());
}
success.fetch_add(1, Ordering::SeqCst);
} else {
if let Some(mut fail_store) = fail_store {
let fp = format!("{}\n", file_path);
let _ = fail_store.write_all(fp.as_bytes());
}
fail.fetch_add(1, Ordering::SeqCst);
}
}

semaphore.release();
});

handles.push(handle);
}

for handle in handles {
handle.join().unwrap();
}

logger.done();
Expand Down

0 comments on commit 2ddf03b

Please sign in to comment.