Add sudoloop feature that starts a second thread to loop sudo

Signed-off-by: Trivernis <trivernis@protonmail.com>
i18n
Trivernis 2 years ago
parent c2bbe77b89
commit 8c12e4c6c4

@ -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,
}

@ -40,6 +40,10 @@ impl ShellCommand {
Self::new("bash")
}
pub fn sudo() -> Self {
Self::new("sudo")
}
fn new<S: ToString>(command: S) -> Self {
Self {
command: command.to_string(),

@ -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 {

@ -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() {}
}

@ -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),

@ -148,7 +148,7 @@ pub fn aur_install(a: Vec<String>, 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")
}

Loading…
Cancel
Save