Skip to content

Commit 1a44990

Browse files
authored
feat(oma-pm)!: add --download-only option (#586)
1 parent 6bc8bb4 commit 1a44990

File tree

12 files changed

+66
-12
lines changed

12 files changed

+66
-12
lines changed

i18n/en-US/oma.ftl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,3 +426,4 @@ clap-mark-hold = Lock package version(s), this will prevent the specified packag
426426
clap-mark-unhold = Unlock package version(s), this will undo the “hold” status on the specified package(s)
427427
clap-mark-manual = Mark package(s) as manually installed, this will prevent the specified package(s) from being removed when all reverse dependencies were removed
428428
clap-mark-auto = Mark package(s) as automatically installed, this will mark the specified package(s) for removal when all reverse dependencies were removed
429+
clap-download-only-help = Only download package(s) and dependency(ies) (without installing)

i18n/zh-CN/oma.ftl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,3 +417,4 @@ clap-mark-unhold = 解锁软件包版本,这将撤销指定软件包的 "保
417417
clap-mark-manual = 将软件包标记为手动安装、 这将防止指定软件包在所有逆向依赖关系被移除后被移除
418418
clap-mark-auto = 将软件包标记为自动安装,这将标记指定软件包在所有逆向依赖关系被移除后被移除
419419
yes-mode-conflict-ui = 在 UI 模式下 `--yes` 模式将不启用。
420+
clap-download-only-help = 只下载软件包和其依赖项,不安装

oma-pm/examples/install_fish.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use flume::unbounded;
55
use oma_apt::util::{get_apt_progress_string, terminal_height, terminal_width};
66
use oma_fetch::{Event, reqwest::ClientBuilder};
77
use oma_pm::{
8-
CommitNetworkConfig,
8+
CommitConfig,
99
apt::{AptConfig, InstallProgressOpt, OmaApt, OmaAptArgs, OmaAptError},
1010
matches::PackagesMatcher,
1111
progress::InstallProgressManager,
@@ -124,9 +124,10 @@ fn main() -> Result<(), OmaAptError> {
124124
InstallProgressOpt::TermLike(Box::new(MyInstallProgressManager)),
125125
&op,
126126
&client,
127-
CommitNetworkConfig {
127+
CommitConfig {
128128
network_thread: None,
129129
auth_config: Some(&AuthConfig::system("/").unwrap()),
130+
download_only: false,
130131
},
131132
None,
132133
async |event| {

oma-pm/src/apt.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ pub use oma_pm_operation_type::*;
3636
use zbus::Connection;
3737

3838
use crate::{
39-
commit::{CommitNetworkConfig, CustomDownloadMessage, DoInstall},
39+
commit::{CommitConfig, CustomDownloadMessage, DoInstall},
4040
dbus::create_session,
4141
download::download_pkgs,
4242
matches::MatcherError,
@@ -586,7 +586,7 @@ impl OmaApt {
586586
install_progress_manager: InstallProgressOpt,
587587
op: &OmaOperation,
588588
client: &Client,
589-
config: CommitNetworkConfig,
589+
config: CommitConfig,
590590
custom_download_message: Option<CustomDownloadMessage>,
591591
callback: impl AsyncFn(Event),
592592
) -> OmaAptResult<()> {

oma-pm/src/commit.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,17 @@ use crate::{
2121

2222
const TIME_FORMAT: &str = "%H:%M:%S on %Y-%m-%d";
2323

24-
pub struct CommitNetworkConfig<'a> {
24+
pub struct CommitConfig<'a> {
2525
pub network_thread: Option<usize>,
2626
pub auth_config: Option<&'a AuthConfig>,
27+
pub download_only: bool,
2728
}
2829

2930
pub struct DoInstall<'a> {
3031
apt: OmaApt,
3132
client: &'a Client,
3233
sysroot: &'a str,
33-
config: CommitNetworkConfig<'a>,
34+
config: CommitConfig<'a>,
3435
}
3536

3637
pub type CustomDownloadMessage = Box<dyn Fn(&InstallEntry) -> Cow<'static, str>>;
@@ -40,7 +41,7 @@ impl<'a> DoInstall<'a> {
4041
apt: OmaApt,
4142
client: &'a Client,
4243
sysroot: &'a str,
43-
config: CommitNetworkConfig<'a>,
44+
config: CommitConfig<'a>,
4445
) -> Result<Self, OmaAptError> {
4546
Ok(Self {
4647
apt,
@@ -63,7 +64,9 @@ impl<'a> DoInstall<'a> {
6364
return Err(OmaAptError::FailedToDownload(summary.failed.len()));
6465
}
6566

66-
self.do_install(install_progress_manager, op)?;
67+
if !self.config.download_only {
68+
self.do_install(install_progress_manager, op)?;
69+
}
6770

6871
Ok(())
6972
}

oma-pm/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ mod commit;
3939
mod dbus;
4040
mod download;
4141
pub mod utils;
42-
pub use commit::CommitNetworkConfig;
42+
pub use commit::CommitConfig;
4343
pub mod sort;
4444
pub use apt_auth_config;
4545
pub use commit::CustomDownloadMessage;

src/subcommand/history.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,9 @@ pub struct Undo {
9595
/// Remove package(s) also remove configuration file(s), like apt purge
9696
#[arg(long, visible_alias = "purge", help = fl!("clap-remove-config-help"))]
9797
remove_config: bool,
98+
/// Only download dependencies, not install
99+
#[arg(long, short, help = fl!("clap-download-only-help"))]
100+
download_only: bool,
98101
/// Run oma in "dry-run" mode. Useful for testing changes and operations without making changes to the system
99102
#[arg(from_global, help = fl!("clap-dry-run-help"), long_help = fl!("clap-dry-run-long-help"))]
100103
dry_run: bool,
@@ -147,6 +150,7 @@ impl CliExecuter for Undo {
147150
no_refresh_topics,
148151
no_check_battery,
149152
no_take_wake_lock,
153+
download_only,
150154
} = self;
151155

152156
lock_oma(&sysroot)?;
@@ -303,6 +307,7 @@ impl CliExecuter for Undo {
303307
.autoremove(autoremove)
304308
.network_thread(download_threads.unwrap_or_else(|| config.network_thread()))
305309
.maybe_auth_config(auth_config.as_ref())
310+
.download_only(download_only)
306311
.build()
307312
.run()?;
308313

src/subcommand/install.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,9 @@ pub struct Install {
9797
/// Auto remove unnecessary package(s)
9898
#[arg(long, help = fl!("clap-autoremove-help"))]
9999
autoremove: bool,
100+
/// Only download dependencies, not install
101+
#[arg(long, short, help = fl!("clap-download-only-help"))]
102+
download_only: bool,
100103
/// Remove package(s) also remove configuration file(s), like apt purge
101104
#[arg(long, visible_alias = "purge", help = fl!("clap-remove-config-help"))]
102105
remove_config: bool,
@@ -139,6 +142,7 @@ impl CliExecuter for Install {
139142
download_threads,
140143
no_check_battery,
141144
no_take_wake_lock,
145+
download_only,
142146
} = self;
143147

144148
if !dry_run {
@@ -245,6 +249,7 @@ impl CliExecuter for Install {
245249
.network_thread(download_threads.unwrap_or_else(|| config.network_thread()))
246250
.maybe_auth_config(auth_config)
247251
.fix_dpkg_status(!no_fix_dpkg_status)
252+
.download_only(download_only)
248253
.build()
249254
.run()
250255
}

src/subcommand/pick.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ pub struct Pick {
5757
/// Remove package(s) also remove configuration file(s), like apt purge
5858
#[arg(long, visible_alias = "purge", help = fl!("clap-remove-config-help"))]
5959
remove_config: bool,
60+
/// Only download dependencies, not install
61+
#[arg(long, short, help = fl!("clap-download-only-help"))]
62+
download_only: bool,
6063
/// Run oma in "dry-run" mode. Useful for testing changes and operations without making changes to the system
6164
#[arg(from_global, help = fl!("clap-dry-run-help"), long_help = fl!("clap-dry-run-long-help"))]
6265
dry_run: bool,
@@ -101,6 +104,7 @@ impl CliExecuter for Pick {
101104
download_threads,
102105
no_check_battery,
103106
no_take_wake_lock,
107+
download_only,
104108
} = self;
105109

106110
if !dry_run {
@@ -231,6 +235,7 @@ impl CliExecuter for Pick {
231235
.autoremove(autoremove)
232236
.network_thread(download_threads.unwrap_or_else(|| config.network_thread()))
233237
.maybe_auth_config(auth_config)
238+
.download_only(download_only)
234239
.build()
235240
.run()
236241
}

src/subcommand/topics.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ pub struct Topics {
8282
/// Remove package(s) also remove configuration file(s), like apt purge
8383
#[arg(long, visible_alias = "purge", help = fl!("clap-remove-config-help"))]
8484
remove_config: bool,
85+
/// Only download dependencies, not install
86+
#[arg(long, short, help = fl!("clap-download-only-help"))]
87+
download_only: bool,
8588
/// Run oma in "dry-run" mode. Useful for testing changes and operations without making changes to the system
8689
#[arg(from_global, help = fl!("clap-dry-run-help"), long_help = fl!("clap-dry-run-long-help"))]
8790
dry_run: bool,
@@ -167,6 +170,7 @@ impl CliExecuter for Topics {
167170
no_take_wake_lock,
168171
only_apply_sources_list,
169172
yes,
173+
download_only,
170174
} = self;
171175

172176
if !dry_run {
@@ -348,6 +352,7 @@ impl CliExecuter for Topics {
348352
.check_tum(true)
349353
.topics_enabled(opt_in)
350354
.topics_disabled(opt_out)
355+
.download_only(download_only)
351356
.build()
352357
.run()?;
353358

@@ -379,7 +384,7 @@ impl CliExecuter for Topics {
379384
}
380385
}
381386
Err(e) => {
382-
if !always_write_status {
387+
if !always_write_status && !download_only {
383388
error!("{}", fl!("topics-unchanged"));
384389
revert_sources_list(&tm)?;
385390
RT.block_on(tm.write_enabled(true))?;

0 commit comments

Comments
 (0)