Skip to content

Commit c08390a

Browse files
authored
Merge pull request #101 from AOSC-Dev/refactor-normal-commit
refactor: refactor `normal_commit` and `refresh` function
2 parents e2b02d2 + 19c7c19 commit c08390a

File tree

10 files changed

+207
-215
lines changed

10 files changed

+207
-215
lines changed

src/subcommand/fix_broken.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use crate::{
88
OmaArgs,
99
};
1010

11-
use super::utils::{lock_oma, no_check_dbus_warn, normal_commit, NormalCommitArgs};
11+
use super::utils::{lock_oma, no_check_dbus_warn, CommitRequest};
1212

1313
pub fn execute(oma_args: OmaArgs, sysroot: String, client: Client) -> Result<i32, OutputError> {
1414
root()?;
@@ -34,7 +34,7 @@ pub fn execute(oma_args: OmaArgs, sysroot: String, client: Client) -> Result<i32
3434
let oma_apt_args = OmaAptArgs::builder().sysroot(sysroot.clone()).build();
3535
let apt = OmaApt::new(vec![], oma_apt_args, dry_run, AptConfig::new())?;
3636

37-
let args = NormalCommitArgs {
37+
let request = CommitRequest {
3838
apt,
3939
dry_run,
4040
typ: SummaryType::FixBroken,
@@ -45,9 +45,10 @@ pub fn execute(oma_args: OmaArgs, sysroot: String, client: Client) -> Result<i32
4545
sysroot,
4646
fix_dpkg_status: false,
4747
protect_essential,
48+
client: &client,
4849
};
4950

50-
let code = normal_commit(args, &client)?;
51+
let code = request.run()?;
5152

5253
drop(fds);
5354

src/subcommand/history.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,7 @@ use crate::{
2323
ALLOWCTRLC,
2424
};
2525

26-
use super::utils::{
27-
handle_no_result, lock_oma, no_check_dbus_warn, normal_commit, NormalCommitArgs,
28-
};
26+
use super::utils::{handle_no_result, lock_oma, no_check_dbus_warn, CommitRequest};
2927

3028
pub fn execute_history(sysroot: String) -> Result<i32, OutputError> {
3129
let conn = connect_db(Path::new(&sysroot).join(DATABASE_PATH), false)?;
@@ -151,7 +149,7 @@ pub fn execute_undo(
151149

152150
apt.install(&install, false)?;
153151

154-
let args = NormalCommitArgs {
152+
let request = CommitRequest {
155153
apt,
156154
dry_run: false,
157155
typ: SummaryType::Undo,
@@ -162,9 +160,10 @@ pub fn execute_undo(
162160
sysroot,
163161
fix_dpkg_status: true,
164162
protect_essential,
163+
client,
165164
};
166165

167-
let code = normal_commit(args, client)?;
166+
let code = request.run()?;
168167

169168
drop(fds);
170169

src/subcommand/install.rs

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@ use crate::OmaArgs;
1818
use super::utils::handle_no_result;
1919
use super::utils::lock_oma;
2020
use super::utils::no_check_dbus_warn;
21-
use super::utils::normal_commit;
22-
use super::utils::refresh;
23-
use super::utils::NormalCommitArgs;
21+
use super::utils::CommitRequest;
2422
use super::utils::RefreshRequest;
2523

2624
pub fn execute(
@@ -51,18 +49,17 @@ pub fn execute(
5149

5250
let apt_config = AptConfig::new();
5351

54-
let req = RefreshRequest {
55-
client: &client,
56-
dry_run,
57-
no_progress,
58-
limit: network_thread,
59-
sysroot: &args.sysroot,
60-
_refresh_topics: !args.no_refresh_topic,
61-
config: &apt_config,
62-
};
63-
6452
if !args.no_refresh {
65-
refresh(req)?;
53+
RefreshRequest {
54+
client: &client,
55+
dry_run,
56+
no_progress,
57+
limit: network_thread,
58+
sysroot: &args.sysroot,
59+
_refresh_topics: !args.no_refresh_topic,
60+
config: &apt_config,
61+
}
62+
.run()?;
6663
}
6764

6865
if args.yes {
@@ -108,7 +105,7 @@ pub fn execute(
108105
.no_progress(no_progress)
109106
.build();
110107

111-
let args = NormalCommitArgs {
108+
let request = CommitRequest {
112109
apt,
113110
dry_run,
114111
typ: SummaryType::Install(
@@ -123,9 +120,10 @@ pub fn execute(
123120
sysroot: args.sysroot,
124121
fix_dpkg_status: true,
125122
protect_essential,
123+
client: &client,
126124
};
127125

128-
let code = normal_commit(args, &client)?;
126+
let code = request.run()?;
129127

130128
drop(fds);
131129

src/subcommand/pick.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@ use crate::{
1313
use crate::{fl, OmaArgs};
1414
use anyhow::anyhow;
1515

16-
use super::utils::{
17-
lock_oma, no_check_dbus_warn, normal_commit, refresh, NormalCommitArgs, RefreshRequest,
18-
};
16+
use super::utils::{lock_oma, no_check_dbus_warn, CommitRequest, RefreshRequest};
1917

2018
pub fn execute(
2119
pkg_str: &str,
@@ -48,17 +46,16 @@ pub fn execute(
4846
let apt_config = AptConfig::new();
4947

5048
if !no_refresh {
51-
let req = RefreshRequest {
49+
RefreshRequest {
5250
client: &client,
5351
dry_run,
5452
no_progress,
5553
limit: network_thread,
5654
sysroot: &sysroot,
5755
_refresh_topics: !no_refresh_topic,
5856
config: &apt_config,
59-
};
60-
61-
refresh(req)?;
57+
}
58+
.run()?;
6259
}
6360

6461
let oma_apt_args = OmaAptArgs::builder().sysroot(sysroot.clone()).build();
@@ -123,7 +120,7 @@ pub fn execute(
123120

124121
apt.install(&pkgs, false)?;
125122

126-
let args = NormalCommitArgs {
123+
let request = CommitRequest {
127124
apt,
128125
dry_run,
129126
typ: SummaryType::Install(
@@ -138,9 +135,10 @@ pub fn execute(
138135
sysroot,
139136
fix_dpkg_status: true,
140137
protect_essential,
138+
client: &client,
141139
};
142140

143-
let exit = normal_commit(args, &client)?;
141+
let exit = request.run()?;
144142

145143
drop(fds);
146144

src/subcommand/refresh.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use reqwest::Client;
77
use crate::{error::OutputError, utils::root};
88
use crate::{fl, OmaArgs};
99

10-
use super::utils::{refresh, RefreshRequest};
10+
use super::utils::RefreshRequest;
1111

1212
pub fn execute(
1313
oma_args: OmaArgs,
@@ -26,17 +26,16 @@ pub fn execute(
2626

2727
let apt_config = AptConfig::new();
2828

29-
let req = RefreshRequest {
29+
RefreshRequest {
3030
client: &client,
3131
dry_run: false,
3232
no_progress,
3333
limit: network_thread,
3434
sysroot: &sysroot,
3535
_refresh_topics: !no_refresh_topics,
3636
config: &apt_config,
37-
};
38-
39-
refresh(req)?;
37+
}
38+
.run()?;
4039

4140
let oma_apt_args = OmaAptArgs::builder().sysroot(sysroot).build();
4241
let apt = OmaApt::new(vec![], oma_apt_args, false, apt_config)?;

src/subcommand/remove.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,7 @@ use crate::{
1414
};
1515
use crate::{fl, OmaArgs};
1616

17-
use super::utils::{
18-
handle_no_result, lock_oma, no_check_dbus_warn, normal_commit, NormalCommitArgs,
19-
};
17+
use super::utils::{handle_no_result, lock_oma, no_check_dbus_warn, CommitRequest};
2018

2119
pub fn execute(
2220
pkgs: Vec<&str>,
@@ -60,7 +58,7 @@ pub fn execute(
6058
}
6159
}
6260

63-
let args = NormalCommitArgs {
61+
let request = CommitRequest {
6462
apt,
6563
dry_run,
6664
typ: SummaryType::Remove(
@@ -79,9 +77,10 @@ pub fn execute(
7977
sysroot: args.sysroot,
8078
fix_dpkg_status: true,
8179
protect_essential: protect,
80+
client: &client,
8281
};
8382

84-
let code = normal_commit(args, &client)?;
83+
let code = request.run()?;
8584

8685
drop(fds);
8786

src/subcommand/topics.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,7 @@ use crate::{
2222
OmaArgs,
2323
};
2424

25-
use super::utils::{
26-
lock_oma, no_check_dbus_warn, normal_commit, refresh, NormalCommitArgs, RefreshRequest,
27-
};
25+
use super::utils::{lock_oma, no_check_dbus_warn, CommitRequest, RefreshRequest};
2826
use crate::fl;
2927
use anyhow::anyhow;
3028
use oma_topics::{scan_closed_topic, TopicManager};
@@ -88,17 +86,16 @@ pub fn execute(args: TopicArgs, client: Client, oma_args: OmaArgs) -> Result<i32
8886

8987
let apt_config = AptConfig::new();
9088

91-
let req = RefreshRequest {
89+
RefreshRequest {
9290
client: &client,
9391
dry_run,
9492
no_progress,
9593
limit: network_thread,
9694
sysroot: &sysroot,
9795
_refresh_topics: true,
9896
config: &apt_config,
99-
};
100-
101-
refresh(req)?;
97+
}
98+
.run()?;
10299

103100
let oma_apt_args = OmaAptArgs::builder().sysroot(sysroot.clone()).build();
104101

@@ -129,7 +126,7 @@ pub fn execute(args: TopicArgs, client: Client, oma_args: OmaArgs) -> Result<i32
129126
apt.install(&pkgs, false)?;
130127
apt.upgrade()?;
131128

132-
let args = NormalCommitArgs {
129+
let request = CommitRequest {
133130
apt,
134131
dry_run,
135132
typ: SummaryType::TopicsChanged {
@@ -143,9 +140,10 @@ pub fn execute(args: TopicArgs, client: Client, oma_args: OmaArgs) -> Result<i32
143140
sysroot,
144141
fix_dpkg_status: true,
145142
protect_essential: oma_args.protect_essentials,
143+
client: &client,
146144
};
147145

148-
let code = normal_commit(args, &client)?;
146+
let code = request.run()?;
149147

150148
drop(fds);
151149

src/subcommand/tui.rs

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,7 @@ use ratatui::{
4444
use crate::{error::OutputError, utils::root};
4545
use std::fmt::Display;
4646

47-
use super::utils::{
48-
lock_oma, no_check_dbus_warn, normal_commit, refresh, NormalCommitArgs, RefreshRequest,
49-
};
47+
use super::utils::{lock_oma, no_check_dbus_warn, CommitRequest, RefreshRequest};
5048

5149
const VERSION: &str = env!("CARGO_PKG_VERSION");
5250

@@ -231,17 +229,16 @@ pub fn execute(tui: Tui) -> Result<i32, OutputError> {
231229

232230
let apt_config = AptConfig::new();
233231

234-
let req = RefreshRequest {
232+
RefreshRequest {
235233
client: &client,
236234
dry_run,
237235
no_progress,
238236
limit: network_thread,
239237
sysroot: &sysroot,
240238
_refresh_topics: true,
241239
config: &apt_config,
242-
};
243-
244-
refresh(req)?;
240+
}
241+
.run()?;
245242

246243
let oma_apt_args = OmaAptArgs::builder().sysroot(sysroot.clone()).build();
247244

@@ -753,21 +750,20 @@ pub fn execute(tui: Tui) -> Result<i32, OutputError> {
753750

754751
let apt_args = AptArgs::builder().no_progress(no_progress).build();
755752

756-
code = normal_commit(
757-
NormalCommitArgs {
758-
apt,
759-
dry_run,
760-
typ: SummaryType::Changes,
761-
apt_args,
762-
no_fixbroken: false,
763-
network_thread,
764-
no_progress,
765-
sysroot,
766-
fix_dpkg_status: true,
767-
protect_essential: true,
768-
},
769-
&client,
770-
)?;
753+
code = CommitRequest {
754+
apt,
755+
dry_run,
756+
typ: SummaryType::Changes,
757+
apt_args,
758+
no_fixbroken: false,
759+
network_thread,
760+
no_progress,
761+
sysroot,
762+
fix_dpkg_status: true,
763+
protect_essential: true,
764+
client: &client,
765+
}
766+
.run()?;
771767
}
772768

773769
drop(fds);

0 commit comments

Comments
 (0)