Skip to content

Commit

Permalink
feat: not allow write history kill process
Browse files Browse the repository at this point in the history
  • Loading branch information
eatradish committed Feb 13, 2025
1 parent fee567f commit 919f330
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 13 deletions.
10 changes: 5 additions & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ use crate::egg::ailurus;
use crate::error::Chain;
use crate::subcommand::*;

static ALLOWCTRLC: AtomicBool = AtomicBool::new(false);
static NOT_DISPLAY_ABORT: AtomicBool = AtomicBool::new(false);
static LOCKED: AtomicBool = AtomicBool::new(false);
static SPAWN_NEW_OMA: AtomicBool = AtomicBool::new(false);
static NOT_ALLOW_CTRLC: AtomicBool = AtomicBool::new(false);
static APP_USER_AGENT: &str = concat!("oma/", env!("CARGO_PKG_VERSION"));
static COLOR_FORMATTER: OnceLock<OmaColorFormat> = OnceLock::new();
static RT: LazyLock<Runtime> = LazyLock::new(|| {
Expand Down Expand Up @@ -444,11 +444,11 @@ async fn find_another_oma_inner() -> Result<(), OutputError> {
}

fn single_handler() {
if SPAWN_NEW_OMA.load(Ordering::Relaxed) {
if NOT_ALLOW_CTRLC.load(Ordering::Relaxed) {
return;
}

let allow_ctrlc = ALLOWCTRLC.load(Ordering::Relaxed);
let not_display_abort = NOT_DISPLAY_ABORT.load(Ordering::Relaxed);

// Dealing with lock
if LOCKED.load(Ordering::Relaxed) {
Expand All @@ -459,7 +459,7 @@ fn single_handler() {
// This is not a big deal so we won't panic on this.
let _ = WRITER.show_cursor();

if !allow_ctrlc {
if !not_display_abort {
info!("{}", fl!("user-aborted-op"));
}

Expand Down
4 changes: 2 additions & 2 deletions src/subcommand/history.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use crate::{
error::OutputError,
table::table_for_history_pending,
utils::{dbus_check, root},
ALLOWCTRLC,
NOT_DISPLAY_ABORT,
};

use super::utils::{
Expand All @@ -47,7 +47,7 @@ impl CliExecuter for History {
.map(|x| x.0)
.collect::<Vec<_>>();

ALLOWCTRLC.store(true, Ordering::Relaxed);
NOT_DISPLAY_ABORT.store(true, Ordering::Relaxed);

let mut old_selected = 0;

Expand Down
4 changes: 2 additions & 2 deletions src/subcommand/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use oma_pm::{
use tracing::info;

use crate::{color_formatter, config::Config, error::OutputError, table::PagerPrinter};
use crate::{fl, ALLOWCTRLC};
use crate::{fl, NOT_DISPLAY_ABORT};
use anyhow::anyhow;
use smallvec::{smallvec, SmallVec};

Expand Down Expand Up @@ -108,7 +108,7 @@ impl CliExecuter for List {
};

let mut printer = PagerPrinter::new(stdout());
ALLOWCTRLC.store(true, Ordering::Relaxed);
NOT_DISPLAY_ABORT.store(true, Ordering::Relaxed);

let mut display_tips = (false, 0);

Expand Down
6 changes: 6 additions & 0 deletions src/subcommand/upgrade.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::fs;
use std::fs::read_dir;
use std::path::Path;
use std::sync::atomic::Ordering;
use std::thread;

use crate::pb::RenderDownloadProgress;
Expand All @@ -9,6 +10,7 @@ use crate::subcommand::utils::display_suggest_tips;
use crate::subcommand::utils::history_success_tips;
use crate::subcommand::utils::undo_tips;
use crate::subcommand::utils::write_oma_installed_status;
use crate::NOT_ALLOW_CTRLC;
use ahash::HashMap;
use ahash::HashSet;
use flume::unbounded;
Expand Down Expand Up @@ -345,6 +347,8 @@ impl CliExecuter for Upgrade {
},
) {
Ok(()) => {
NOT_ALLOW_CTRLC.store(true, Ordering::Relaxed);

write_oma_installed_status()?;
autoremovable_tips(ar_count, ar_size)?;

Expand Down Expand Up @@ -376,6 +380,8 @@ impl CliExecuter for Upgrade {
| OmaAptError::AptError(_)
| OmaAptError::AptCxxException(_) => {
if retry_times == 3 {
NOT_ALLOW_CTRLC.store(true, Ordering::Relaxed);

write_history_entry(
{
let db = create_db_file(sysroot)?;
Expand Down
3 changes: 3 additions & 0 deletions src/subcommand/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ use crate::success;
use crate::table::table_for_install_pending;
use crate::upgrade::get_matches_tum;
use crate::upgrade::get_tum;
use crate::NOT_ALLOW_CTRLC;
use crate::HTTP_CLIENT;
use crate::LOCKED;
use crate::RT;
Expand Down Expand Up @@ -452,6 +453,7 @@ impl CommitChanges<'_> {

match res {
Ok(_) => {
NOT_ALLOW_CTRLC.store(true, Ordering::Relaxed);
write_oma_installed_status()?;
autoremovable_tips(ar_count, ar_size)?;

Expand All @@ -478,6 +480,7 @@ impl CommitChanges<'_> {
Ok(0)
}
Err(e) => {
NOT_ALLOW_CTRLC.store(true, Ordering::Relaxed);
undo_tips();
write_history_entry(
{
Expand Down
4 changes: 2 additions & 2 deletions src/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use std::sync::LazyLock;
use crate::console::style;
use crate::error::OutputError;
use crate::upgrade::TopicUpdateEntryRef;
use crate::{color_formatter, fl, ALLOWCTRLC, WRITER};
use crate::{color_formatter, fl, NOT_DISPLAY_ABORT, WRITER};
use ahash::HashMap;
use ahash::HashSet;
use oma_console::indicatif::HumanBytes;
Expand Down Expand Up @@ -204,7 +204,7 @@ pub fn oma_display_with_normal_output(
len: usize,
) -> Result<Pager<'static>, OutputError> {
if !is_question {
ALLOWCTRLC.store(true, Ordering::Relaxed);
NOT_DISPLAY_ABORT.store(true, Ordering::Relaxed);
}

let pager = if len < WRITER.get_height().into() {
Expand Down
4 changes: 2 additions & 2 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use std::{
};

use crate::{color_formatter, fl, RT, WRITER};
use crate::{error::OutputError, SPAWN_NEW_OMA};
use crate::{error::OutputError, NOT_ALLOW_CTRLC};
use anyhow::anyhow;
use dialoguer::{console::style, theme::ColorfulTheme, Confirm};
use oma_console::{
Expand Down Expand Up @@ -41,7 +41,7 @@ pub fn root() -> Result<()> {
info!("{}", fl!("pkexec-tips-1"));
info!("{}", fl!("pkexec-tips-2"));

SPAWN_NEW_OMA.store(true, Ordering::Relaxed);
NOT_ALLOW_CTRLC.store(true, Ordering::Relaxed);

let out = Command::new("pkexec")
.args(args)
Expand Down

0 comments on commit 919f330

Please sign in to comment.