Skip to content
Draft
Show file tree
Hide file tree
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
49 changes: 1 addition & 48 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ authors = ["eatradish <[email protected]>"]
# Cli
clap = { version = "4.5.19", features = ["cargo", "wrap_help", "color", "derive", "env", "string"] }
anyhow = "1.0.89"
ctrlc = "3.5"
dialoguer = "0.12.0"
tabled = { version = "0.20", features = ["ansi"] }
tokio = "1.46.0"
Expand Down Expand Up @@ -52,6 +51,7 @@ once_cell = "1.21"
itertools = "0.14.0"
clap-i18n-richformatter = "0.1.0"
debversion = "0.5"
signal-hook = "0.3.18"

# oma crates
oma-utils = { path = "./oma-utils", features = ["dbus", "human-bytes"] }
Expand Down
77 changes: 40 additions & 37 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,26 +1,7 @@
use std::env::{self, args};
use std::ffi::CString;
use std::fs::{create_dir_all, read_dir, remove_file};
use std::io::{self, IsTerminal, stderr, stdin};
use std::path::{Path, PathBuf};

use std::process::{Command, exit};
use std::sync::{LazyLock, OnceLock};
use std::thread;
use std::time::{Duration, SystemTime, UNIX_EPOCH};

mod args;
mod config;
mod error;
mod install_progress;
mod lang;
mod path_completions;
mod pb;
mod subcommand;
mod table;
mod tui;
mod utils;

use crate::config::Config;
use crate::error::Chain;
use crate::install_progress::osc94_progress;
use crate::subcommand::*;
use args::{CliExecuter, OhManagerAilurus};
use clap::builder::FalseyValueParser;
use clap::{ArgAction, ArgMatches, Args, ColorChoice, CommandFactory, FromArgMatches, arg};
Expand All @@ -29,14 +10,27 @@
use error::OutputError;
use i18n_embed::{DesktopLanguageRequester, Localizer};
use lang::LANGUAGE_LOADER;
use libc::{SIGHUP, SIGQUIT};
use oma_console::OmaLayer;
use oma_console::console;
use oma_console::print::{OmaColorFormat, termbg};
use oma_console::writer::{MessageType, Writer, writeln_inner};
use oma_pm::apt::AptConfig;
use oma_utils::dbus::{create_dbus_connection, get_another_oma_status};
use oma_utils::{OsRelease, is_termux};
use reqwest::Client;
use rustix::stdio::stdout;
use signal_hook::consts::{SIGINT, SIGTERM};
use signal_hook::iterator::Signals;
use std::env::{self, args};
use std::ffi::CString;
use std::fs::{create_dir_all, read_dir, remove_file};
use std::io::{self, IsTerminal, stderr, stdin, stdout};
use std::path::{Path, PathBuf};
use std::process::{Command, exit};
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::{LazyLock, OnceLock};
use std::thread;
use std::time::{Duration, SystemTime, UNIX_EPOCH};
use subcommand::utils::{LockError, is_terminal};
use tokio::runtime::Runtime;
use tracing::{debug, error, info, warn};
Expand All @@ -47,14 +41,17 @@
use tui::Tui;
use utils::{is_root, is_ssh_from_loginctl};

use std::sync::atomic::{AtomicBool, Ordering};

use oma_console::console;

use crate::config::Config;
use crate::error::Chain;
use crate::install_progress::osc94_progress;
use crate::subcommand::*;
mod args;
mod config;
mod error;
mod install_progress;
mod lang;
mod path_completions;
mod pb;
mod subcommand;
mod table;
mod tui;
mod utils;

static NOT_DISPLAY_ABORT: AtomicBool = AtomicBool::new(false);
static LOCKED: AtomicBool = AtomicBool::new(false);
Expand Down Expand Up @@ -172,7 +169,15 @@
.completer("oma")
.complete();

ctrlc::set_handler(signal_handler).expect("oma could not initialize SIGINT handler.");
thread::spawn(|| {
let mut sigs =
Signals::new([SIGTERM, SIGINT, SIGHUP, SIGQUIT]).expect("Failed to set signal handler");

for signal in &mut sigs {
signal_handler(signal == SIGINT);
std::process::exit(128 + signal);
}

Check failure on line 179 in src/main.rs

View workflow job for this annotation

GitHub Actions / clippy

this loop never actually loops

error: this loop never actually loops --> src/main.rs:176:9 | 176 | / for signal in &mut sigs { 177 | | signal_handler(signal == SIGINT); 178 | | std::process::exit(128 + signal); 179 | | } | |_________^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.91.0/index.html#never_loop = note: `#[deny(clippy::never_loop)]` on by default help: if you need the first element of the iterator, try writing | 176 - for signal in &mut sigs { 176 + if let Some(signal) = (&mut sigs).into_iter().next() { |
});

// 要适配额外的插件子命令,所以这里要保留 matches
let (matches, oma) = parse_args();
Expand Down Expand Up @@ -681,8 +686,8 @@
}
}

fn signal_handler() {
if NOT_ALLOW_CTRLC.load(Ordering::Relaxed) {
fn signal_handler(is_ctrlc: bool) {
if is_ctrlc && NOT_ALLOW_CTRLC.load(Ordering::Relaxed) {
return;
}

Expand All @@ -703,6 +708,4 @@
if !not_display_abort {
info!("{}", fl!("user-aborted-op"));
}

std::process::exit(130);
}
Loading