Skip to content

Commit ba55e72

Browse files
committed
feat: add --download-threads arg to control download threads
1 parent 0829dbd commit ba55e72

File tree

11 files changed

+67
-23
lines changed

11 files changed

+67
-23
lines changed

src/main.rs

+3
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,9 @@ pub struct GlobalOptions {
123123
#[arg(long, global = true, env = "OMA_NO_BELL", value_parser = FalseyValueParser::new()
124124
)]
125125
no_bell: bool,
126+
/// Setup download threads (default as 4)
127+
#[arg(long, short = 't', global = true, env = "OMA_DOWNLOAD_THREADS")]
128+
download_threads: Option<usize>,
126129
}
127130

128131
fn main() {

src/subcommand/download.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ pub struct Download {
2727
/// Run oma in "dry-run" mode. Useful for testing changes and operations without making changes to the system
2828
#[arg(from_global)]
2929
dry_run: bool,
30+
/// Setup download threads (default as 4)
31+
#[arg(from_global)]
32+
download_threads: Option<usize>,
3033
}
3134

3235
impl CliExecuter for Download {
@@ -35,6 +38,7 @@ impl CliExecuter for Download {
3538
packages,
3639
path,
3740
dry_run,
41+
download_threads,
3842
} = self;
3943

4044
let path = path.canonicalize().map_err(|e| OutputError {
@@ -71,7 +75,7 @@ impl CliExecuter for Download {
7175
&HTTP_CLIENT,
7276
pkgs,
7377
DownloadConfig {
74-
network_thread: Some(config.network_thread()),
78+
network_thread: Some(download_threads.unwrap_or_else(|| config.network_thread())),
7579
download_dir: Some(&path),
7680
auth: auth_config("/").as_ref(),
7781
},

src/subcommand/fix_broken.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ pub struct FixBroken {
4444
/// Set apt options
4545
#[arg(from_global)]
4646
apt_options: Vec<String>,
47+
/// Setup download threads (default as 4)
48+
#[arg(from_global)]
49+
download_threads: Option<usize>,
4750
}
4851

4952
impl CliExecuter for FixBroken {
@@ -62,6 +65,7 @@ impl CliExecuter for FixBroken {
6265
sysroot,
6366
apt_options,
6467
no_fix_dpkg_status,
68+
download_threads,
6569
} = self;
6670

6771
let mut _fds = None;
@@ -97,7 +101,7 @@ impl CliExecuter for FixBroken {
97101
.autoremove(autoremove)
98102
.remove_config(remove_config)
99103
.maybe_auth_config(auth_config)
100-
.network_thread(config.network_thread())
104+
.network_thread(download_threads.unwrap_or_else(|| config.network_thread()))
101105
.build()
102106
.run()
103107
}

src/subcommand/history.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,9 @@ pub struct Undo {
103103
/// Set apt options
104104
#[arg(from_global)]
105105
apt_options: Vec<String>,
106+
/// Setup download threads (default as 4)
107+
#[arg(from_global)]
108+
download_threads: Option<usize>,
106109
}
107110

108111
impl CliExecuter for Undo {
@@ -122,6 +125,7 @@ impl CliExecuter for Undo {
122125
sysroot,
123126
apt_options,
124127
no_fix_dpkg_status,
128+
download_threads,
125129
} = self;
126130

127131
let _fds = if !no_check_dbus && !config.no_check_dbus() && !dry_run {
@@ -243,7 +247,7 @@ impl CliExecuter for Undo {
243247
.yes(false)
244248
.remove_config(remove_config)
245249
.autoremove(autoremove)
246-
.network_thread(config.network_thread())
250+
.network_thread(download_threads.unwrap_or_else(|| config.network_thread()))
247251
.maybe_auth_config(auth_config)
248252
.build()
249253
.run()?;

src/subcommand/install.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,9 @@ pub struct Install {
8989
/// Remove package(s) also remove configuration file(s), like apt purge
9090
#[arg(long, visible_alias = "purge")]
9191
remove_config: bool,
92+
/// Setup download threads (default as 4)
93+
#[arg(from_global)]
94+
download_threads: Option<usize>,
9295
}
9396

9497
impl CliExecuter for Install {
@@ -116,6 +119,7 @@ impl CliExecuter for Install {
116119
autoremove,
117120
remove_config,
118121
no_fix_dpkg_status,
122+
download_threads,
119123
} = self;
120124

121125
if !dry_run {
@@ -141,7 +145,7 @@ impl CliExecuter for Install {
141145
.client(&HTTP_CLIENT)
142146
.dry_run(dry_run)
143147
.no_progress(no_progress)
144-
.network_thread(config.network_thread())
148+
.network_thread(download_threads.unwrap_or_else(|| config.network_thread()))
145149
.sysroot(&sysroot)
146150
.config(&apt_config)
147151
.maybe_auth_config(auth_config);
@@ -216,7 +220,7 @@ impl CliExecuter for Install {
216220
.yes(yes)
217221
.remove_config(remove_config)
218222
.autoremove(autoremove)
219-
.network_thread(config.network_thread())
223+
.network_thread(download_threads.unwrap_or_else(|| config.network_thread()))
220224
.maybe_auth_config(auth_config)
221225
.fix_dpkg_status(!no_fix_dpkg_status)
222226
.build()

src/subcommand/mirror.rs

+10-6
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ pub struct CliMirror {
8282
/// Run oma in "dry-run" mode. Useful for testing changes and operations without making changes to the system
8383
#[arg(from_global)]
8484
dry_run: bool,
85+
/// Setup download threads (default as 4)
86+
#[arg(from_global)]
87+
download_threads: Option<usize>,
8588
}
8689

8790
#[derive(Debug, Subcommand)]
@@ -161,6 +164,7 @@ impl CliExecuter for CliMirror {
161164
no_refresh_topics,
162165
no_refresh,
163166
dry_run,
167+
download_threads,
164168
} = self;
165169

166170
if dry_run {
@@ -178,7 +182,7 @@ impl CliExecuter for CliMirror {
178182
} => operate(
179183
no_progress,
180184
!no_refresh_topics && !config.no_refresh_topics(),
181-
config.network_thread(),
185+
download_threads.unwrap_or_else(|| config.network_thread()),
182186
no_refresh,
183187
names.iter().map(|x| x.as_str()).collect::<Vec<_>>(),
184188
sysroot,
@@ -193,7 +197,7 @@ impl CliExecuter for CliMirror {
193197
no_progress,
194198
set_fastest,
195199
!no_refresh_topics && !config.no_refresh_topics(),
196-
config.network_thread(),
200+
download_threads.unwrap_or_else(|| config.network_thread()),
197201
no_refresh,
198202
),
199203
MirrorSubCmd::Add {
@@ -204,7 +208,7 @@ impl CliExecuter for CliMirror {
204208
} => operate(
205209
no_progress,
206210
!no_refresh_topics && !config.no_refresh_topics(),
207-
config.network_thread(),
211+
download_threads.unwrap_or_else(|| config.network_thread()),
208212
no_refresh,
209213
names.iter().map(|x| x.as_str()).collect::<Vec<_>>(),
210214
sysroot,
@@ -218,7 +222,7 @@ impl CliExecuter for CliMirror {
218222
} => operate(
219223
no_progress,
220224
!no_refresh_topics && !config.no_refresh_topics(),
221-
config.network_thread(),
225+
download_threads.unwrap_or_else(|| config.network_thread()),
222226
no_refresh,
223227
names.iter().map(|x| x.as_str()).collect::<Vec<_>>(),
224228
sysroot,
@@ -230,15 +234,15 @@ impl CliExecuter for CliMirror {
230234
} => set_order(
231235
no_progress,
232236
!no_refresh_topics && !config.no_refresh_topics(),
233-
config.network_thread(),
237+
download_threads.unwrap_or_else(|| config.network_thread()),
234238
no_refresh,
235239
),
236240
}
237241
} else {
238242
tui(
239243
no_progress,
240244
!no_refresh_topics && !config.no_refresh_topics(),
241-
config.network_thread(),
245+
download_threads.unwrap_or_else(|| config.network_thread()),
242246
no_refresh,
243247
)
244248
}

src/subcommand/pick.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ pub struct Pick {
6666
/// Set apt options
6767
#[arg(from_global)]
6868
apt_options: Vec<String>,
69+
/// Setup download threads (default as 4)
70+
#[arg(from_global)]
71+
download_threads: Option<usize>,
6972
}
7073

7174
impl CliExecuter for Pick {
@@ -86,6 +89,7 @@ impl CliExecuter for Pick {
8689
sysroot,
8790
apt_options,
8891
no_fix_dpkg_status,
92+
download_threads,
8993
} = self;
9094

9195
if !dry_run {
@@ -111,7 +115,7 @@ impl CliExecuter for Pick {
111115
.client(&HTTP_CLIENT)
112116
.dry_run(dry_run)
113117
.no_progress(no_progress)
114-
.network_thread(config.network_thread())
118+
.network_thread(download_threads.unwrap_or_else(|| config.network_thread()))
115119
.sysroot(&sysroot)
116120
.config(&apt_config)
117121
.maybe_auth_config(auth_config);
@@ -211,7 +215,7 @@ impl CliExecuter for Pick {
211215
.yes(false)
212216
.remove_config(remove_config)
213217
.autoremove(autoremove)
214-
.network_thread(config.network_thread())
218+
.network_thread(download_threads.unwrap_or_else(|| config.network_thread()))
215219
.maybe_auth_config(auth_config)
216220
.build()
217221
.run()

src/subcommand/refresh.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ pub struct Refresh {
2323
/// Run oma in "dry-run" mode. Useful for testing changes and operations without making changes to the system
2424
#[arg(from_global)]
2525
dry_run: bool,
26+
/// Setup download threads (default as 4)
27+
#[arg(from_global)]
28+
download_threads: Option<usize>,
2629
}
2730

2831
impl CliExecuter for Refresh {
@@ -32,6 +35,7 @@ impl CliExecuter for Refresh {
3235
no_refresh_topics,
3336
sysroot,
3437
dry_run,
38+
download_threads,
3539
} = self;
3640

3741
if dry_run {
@@ -50,7 +54,7 @@ impl CliExecuter for Refresh {
5054
.client(&HTTP_CLIENT)
5155
.dry_run(false)
5256
.no_progress(no_progress)
53-
.network_thread(config.network_thread())
57+
.network_thread(download_threads.unwrap_or_else(|| config.network_thread()))
5458
.sysroot(&sysroot_str)
5559
.config(&apt_config)
5660
.maybe_auth_config(auth_config);

src/subcommand/topics.rs

+9-5
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,9 @@ pub struct Topics {
8484
/// Always write status to atm file and sources.list
8585
#[arg(long)]
8686
always_write_status: bool,
87+
/// Setup download threads (default as 4)
88+
#[arg(from_global)]
89+
download_threads: Option<usize>,
8790
}
8891

8992
struct TopicChanged {
@@ -132,6 +135,7 @@ impl CliExecuter for Topics {
132135
all,
133136
no_fix_dpkg_status,
134137
always_write_status,
138+
download_threads,
135139
} = self;
136140

137141
if !dry_run {
@@ -181,7 +185,7 @@ impl CliExecuter for Topics {
181185

182186
let code = Ok(()).and_then(|_| -> Result<i32, OutputError> {
183187
refresh(
184-
config,
188+
download_threads.unwrap_or_else(|| config.network_thread()),
185189
no_progress,
186190
dry_run,
187191
&sysroot,
@@ -238,7 +242,7 @@ impl CliExecuter for Topics {
238242
.yes(false)
239243
.remove_config(remove_config)
240244
.autoremove(autoremove)
241-
.network_thread(config.network_thread())
245+
.network_thread(download_threads.unwrap_or_else(|| config.network_thread()))
242246
.maybe_auth_config(auth_config)
243247
.check_update(true)
244248
.topics_enabled(opt_in)
@@ -257,7 +261,7 @@ impl CliExecuter for Topics {
257261
revert_sources_list(&tm)?;
258262
RT.block_on(tm.write_enabled(true))?;
259263
refresh(
260-
config,
264+
download_threads.unwrap_or_else(|| config.network_thread()),
261265
no_progress,
262266
dry_run,
263267
&sysroot,
@@ -279,7 +283,7 @@ impl CliExecuter for Topics {
279283
}
280284

281285
fn refresh<'a>(
282-
config: &'a Config,
286+
network_threads: usize,
283287
no_progress: bool,
284288
dry_run: bool,
285289
sysroot: &'a Path,
@@ -290,7 +294,7 @@ fn refresh<'a>(
290294
.client(&HTTP_CLIENT)
291295
.dry_run(dry_run)
292296
.no_progress(no_progress)
293-
.network_thread(config.network_thread())
297+
.network_thread(network_threads)
294298
.sysroot(&sysroot.to_string_lossy())
295299
.refresh_topics(true)
296300
.config(apt_config)

src/subcommand/upgrade.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,9 @@ pub(crate) struct Upgrade {
8787
/// Set apt options
8888
#[arg(from_global)]
8989
apt_options: Vec<String>,
90+
/// Setup download threads (default as 4)
91+
#[arg(from_global)]
92+
download_threads: Option<usize>,
9093
}
9194

9295
impl CliExecuter for Upgrade {
@@ -110,6 +113,7 @@ impl CliExecuter for Upgrade {
110113
#[cfg(not(feature = "aosc"))]
111114
no_remove,
112115
no_fix_dpkg_status,
116+
download_threads,
113117
} = self;
114118

115119
if !dry_run {
@@ -134,7 +138,7 @@ impl CliExecuter for Upgrade {
134138
.client(&HTTP_CLIENT)
135139
.dry_run(dry_run)
136140
.no_progress(no_progress)
137-
.network_thread(config.network_thread())
141+
.network_thread(download_threads.unwrap_or_else(|| config.network_thread()))
138142
.sysroot(&sysroot)
139143
.config(&apt_config)
140144
.auth_config(&auth_config);
@@ -225,7 +229,7 @@ impl CliExecuter for Upgrade {
225229
.yes(yes)
226230
.remove_config(remove_config)
227231
.autoremove(autoremove)
228-
.network_thread(config.network_thread())
232+
.network_thread(download_threads.unwrap_or_else(|| config.network_thread()))
229233
.maybe_auth_config(Some(&auth_config))
230234
.fix_dpkg_status(!no_fix_dpkg_status)
231235
.build()

0 commit comments

Comments
 (0)