From 8c12e4c6c4307dd21749d66680f400067c08a878 Mon Sep 17 00:00:00 2001 From: Trivernis Date: Mon, 18 Apr 2022 10:59:33 +0200 Subject: [PATCH] Add sudoloop feature that starts a second thread to loop sudo Signed-off-by: Trivernis --- src/args.rs | 8 ++++++-- src/internal/commands.rs | 4 ++++ src/internal/mod.rs | 2 ++ src/internal/sudoloop.rs | 16 ++++++++++++++++ src/main.rs | 6 +++++- src/operations/aur_install.rs | 2 +- 6 files changed, 34 insertions(+), 4 deletions(-) create mode 100644 src/internal/sudoloop.rs diff --git a/src/args.rs b/src/args.rs index 0f9ea84..0fba04e 100644 --- a/src/args.rs +++ b/src/args.rs @@ -13,6 +13,10 @@ pub struct Args { /// Complete operation without prompting user #[clap(long = "noconfirm")] pub no_confirm: bool, + + /// Loops sudo in the background to ensure it doesn't time out during long builds + #[clap(long = "sudoloop")] + pub sudoloop: bool, } #[derive(Debug, Clone, Subcommand)] @@ -76,10 +80,10 @@ pub struct SearchArgs { #[derive(Default, Debug, Clone, Parser)] pub struct QueryArgs { /// Lists AUR/foreign packages - #[clap(long, short)] + #[clap(long, short, from_global)] pub aur: bool, /// Lists repo/native packages - #[clap(long, short)] + #[clap(long, short, from_global)] pub repo: bool, } diff --git a/src/internal/commands.rs b/src/internal/commands.rs index 6020912..293b842 100644 --- a/src/internal/commands.rs +++ b/src/internal/commands.rs @@ -40,6 +40,10 @@ impl ShellCommand { Self::new("bash") } + pub fn sudo() -> Self { + Self::new("sudo") + } + fn new(command: S) -> Self { Self { command: command.to_string(), diff --git a/src/internal/mod.rs b/src/internal/mod.rs index 5f8be49..fdfd49b 100644 --- a/src/internal/mod.rs +++ b/src/internal/mod.rs @@ -7,12 +7,14 @@ pub mod rpc; mod sort; mod strings; pub mod structs; +mod sudoloop; pub use clean::*; pub use initialise::*; pub use sort::*; use std::env; pub use strings::*; +pub use sudoloop::*; #[macro_export] macro_rules! uwu { diff --git a/src/internal/sudoloop.rs b/src/internal/sudoloop.rs new file mode 100644 index 0000000..d2cddfc --- /dev/null +++ b/src/internal/sudoloop.rs @@ -0,0 +1,16 @@ +use crate::ShellCommand; +use std::thread; +use std::time::Duration; + +/// Loop sudo so it doesn't time out +pub fn start_sudoloop() { + prompt_sudo(); + std::thread::spawn(|| loop { + prompt_sudo(); + thread::sleep(Duration::from_secs(3 * 60)) + }); +} + +fn prompt_sudo() { + while let Err(_) = ShellCommand::sudo().arg("-v").wait_success() {} +} diff --git a/src/main.rs b/src/main.rs index a9742b5..e14263a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -6,7 +6,7 @@ use internal::commands::ShellCommand; use internal::error::SilentUnwrap; use crate::internal::exit_code::AppExitCode; -use crate::internal::{crash, info, init, log, sort, structs::Options}; +use crate::internal::{crash, info, init, log, sort, start_sudoloop, structs::Options}; #[global_allocator] static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc; @@ -34,6 +34,10 @@ fn main() { init(options); + if args.sudoloop { + start_sudoloop(); + } + match args.subcommand.unwrap_or_default() { Operation::Install(install_args) => cmd_install(install_args, options), Operation::Remove(remove_args) => cmd_remove(remove_args, options), diff --git a/src/operations/aur_install.rs b/src/operations/aur_install.rs index 9d1be84..054bcfb 100644 --- a/src/operations/aur_install.rs +++ b/src/operations/aur_install.rs @@ -148,7 +148,7 @@ pub fn aur_install(a: Vec, options: Options) { crate::operations::aur_install(md_sorted.aur, newopts); } - let mut makepkg_args = vec!["-rsic", "--skippgp"]; + let mut makepkg_args = vec!["-rsci", "--skippgp"]; if options.asdeps { makepkg_args.push("--asdeps") }