From 86f4e394906ff093dacd2a6c56c0c349814138a5 Mon Sep 17 00:00:00 2001 From: eatradish Date: Mon, 22 Sep 2025 17:30:45 +0800 Subject: [PATCH 1/4] feat(oma-refresh): support custom `Dir::Etc::SourceList` --- oma-refresh/examples/update.rs | 1 + oma-refresh/src/db.rs | 31 ++++++++++++++++++++++++++++++- oma-refresh/src/sourceslist.rs | 14 ++++++++------ src/subcommand/history.rs | 3 ++- src/subcommand/install.rs | 1 + src/subcommand/mirror.rs | 24 ++++++++++++++++++++---- src/subcommand/pick.rs | 1 + src/subcommand/refresh.rs | 5 +++++ src/subcommand/topics.rs | 6 +++++- src/subcommand/upgrade.rs | 1 + src/subcommand/utils.rs | 3 +++ src/tui/mod.rs | 1 + 12 files changed, 78 insertions(+), 13 deletions(-) diff --git a/oma-refresh/examples/update.rs b/oma-refresh/examples/update.rs index c8af781ca..a6bec62f8 100644 --- a/oma-refresh/examples/update.rs +++ b/oma-refresh/examples/update.rs @@ -27,6 +27,7 @@ async fn main() -> Result<(), RefreshError> { .topic_msg("test") .refresh_topics(false) .auth_config(&auth) + .another_apt_options(vec![]) .build(); tokio::spawn(async move { diff --git a/oma-refresh/src/db.rs b/oma-refresh/src/db.rs index 93167ede9..fcb6893e6 100644 --- a/oma-refresh/src/db.rs +++ b/oma-refresh/src/db.rs @@ -128,6 +128,8 @@ pub struct OmaRefresh<'a> { topic_msg: &'a str, auth_config: Option<&'a AuthConfig>, sources_lists_paths: Option>, + #[builder(default)] + another_apt_options: Vec, } /// Create `apt update` file lock @@ -216,7 +218,34 @@ impl<'a> OmaRefresh<'a> { let paths = if let Some(ref paths) = self.sources_lists_paths { paths.to_vec() } else { - scan_sources_lists_paths_from_sysroot(&self.source) + #[cfg(feature = "apt")] + self.apt_config.set("Dir", &self.source.to_string_lossy()); + + #[cfg(feature = "apt")] + for i in &self.another_apt_options { + let (k, v) = i.split_once('=').unwrap_or((i.as_str(), "")); + debug!("Setting apt opt: {k}={v}"); + self.apt_config.set(k, v); + } + + #[cfg(feature = "apt")] + let list_file = self.apt_config.file("Dir::Etc::sourcelist", "sources.list"); + + #[cfg(feature = "apt")] + let list_dir = self + .apt_config + .dir("Dir::Etc::sourceparts", "sources.list.d"); + + #[cfg(not(feature = "apt"))] + let list_file = self.source.join("etc/apt/sources.list"); + + #[cfg(not(feature = "apt"))] + let list_dir = self.source.join("etc/apt/sources.list.d"); + + debug!("sources.list is: {list_file}"); + debug!("sources.list.d is: {list_dir}"); + + scan_sources_lists_paths_from_sysroot(list_file, list_dir) .await .map_err(RefreshError::ScanSourceError)? }; diff --git a/oma-refresh/src/sourceslist.rs b/oma-refresh/src/sourceslist.rs index 02092a661..884c7eabd 100644 --- a/oma-refresh/src/sourceslist.rs +++ b/oma-refresh/src/sourceslist.rs @@ -55,24 +55,26 @@ impl Debug for OmaSourceEntry<'_> { } pub(crate) async fn scan_sources_lists_paths_from_sysroot( - sysroot: impl AsRef, + list_file: impl AsRef, + list_dir: impl AsRef, ) -> Result, SourcesListError> { let mut paths = vec![]; - let default = sysroot.as_ref().join("etc/apt/sources.list"); + let default = Path::new(list_file.as_ref()); + let list_dir_path = Path::new(list_dir.as_ref()); if default.exists() { - paths.push(default); + paths.push(default.to_path_buf()); } - if sysroot.as_ref().join("etc/apt/sources.list.d/").exists() { - let mut dir = tokio::fs::read_dir(sysroot.as_ref().join("etc/apt/sources.list.d/")).await?; + if list_dir_path.exists() { + let mut dir = tokio::fs::read_dir(list_dir_path).await?; while let Some(entry) = dir.next_entry().await? { let path = entry.path(); if !path.is_file() { continue; } - paths.push(path); + paths.push(path.to_path_buf()); } } diff --git a/src/subcommand/history.rs b/src/subcommand/history.rs index ca3fdeb08..323716105 100644 --- a/src/subcommand/history.rs +++ b/src/subcommand/history.rs @@ -194,7 +194,8 @@ impl CliExecuter for Undo { .network_thread(download_threads.unwrap_or_else(|| config.network_thread())) .sysroot(&sysroot) .config(&apt_config) - .maybe_auth_config(auth_config.as_ref()); + .maybe_auth_config(auth_config.as_ref()) + .apt_options(apt_options.clone()); #[cfg(feature = "aosc")] let refresh = builder diff --git a/src/subcommand/install.rs b/src/subcommand/install.rs index 739dba4a6..c7218dda2 100644 --- a/src/subcommand/install.rs +++ b/src/subcommand/install.rs @@ -169,6 +169,7 @@ impl CliExecuter for Install { .network_thread(download_threads.unwrap_or_else(|| config.network_thread())) .sysroot(&sysroot) .config(&apt_config) + .apt_options(apt_options.clone()) .maybe_auth_config(auth_config); #[cfg(feature = "aosc")] diff --git a/src/subcommand/mirror.rs b/src/subcommand/mirror.rs index ba20dae1e..2e5a41ee0 100644 --- a/src/subcommand/mirror.rs +++ b/src/subcommand/mirror.rs @@ -94,6 +94,9 @@ pub struct CliMirror { /// Setup download threads (default as 4) #[arg(from_global, help = fl!("clap-download-threads-help"))] download_threads: Option, + /// Set apt options + #[arg(from_global, help = fl!("clap-apt-options-help"))] + apt_options: Vec, } #[derive(Debug, Subcommand)] @@ -190,6 +193,7 @@ impl CliExecuter for CliMirror { no_refresh, dry_run, download_threads, + apt_options, } = self; if dry_run { @@ -212,6 +216,7 @@ impl CliExecuter for CliMirror { names.iter().map(|x| x.as_str()).collect::>(), sysroot, Operate::Set, + apt_options, ), MirrorSubCmd::Speedtest { set_fastest, @@ -224,6 +229,7 @@ impl CliExecuter for CliMirror { !no_refresh_topics && !config.no_refresh_topics(), download_threads.unwrap_or_else(|| config.network_thread()), no_refresh, + apt_options, ), MirrorSubCmd::Add { names, @@ -238,6 +244,7 @@ impl CliExecuter for CliMirror { names.iter().map(|x| x.as_str()).collect::>(), sysroot, Operate::Add, + apt_options, ), MirrorSubCmd::Remove { names, @@ -252,6 +259,7 @@ impl CliExecuter for CliMirror { names.iter().map(|x| x.as_str()).collect::>(), sysroot, Operate::Remove, + apt_options, ), MirrorSubCmd::SortMirrors { no_refresh_topics, @@ -261,6 +269,7 @@ impl CliExecuter for CliMirror { !no_refresh_topics && !config.no_refresh_topics(), download_threads.unwrap_or_else(|| config.network_thread()), no_refresh, + apt_options, ), } } else { @@ -269,6 +278,7 @@ impl CliExecuter for CliMirror { !no_refresh_topics && !config.no_refresh_topics(), download_threads.unwrap_or_else(|| config.network_thread()), no_refresh, + apt_options, ) } } @@ -279,6 +289,7 @@ pub fn tui( refresh_topic: bool, network_threads: usize, no_refresh: bool, + apt_options: Vec, ) -> Result { root()?; @@ -347,7 +358,7 @@ pub fn tui( if !no_refresh { refresh_enabled_topics_sources_list(no_progress)?; - refresh(no_progress, network_threads, refresh_topic)?; + refresh(no_progress, network_threads, refresh_topic, apt_options)?; } Ok(0) @@ -367,6 +378,7 @@ pub fn operate( args: Vec<&str>, sysroot: PathBuf, subcmd: Operate, + apt_options: Vec, ) -> Result { root()?; @@ -392,7 +404,7 @@ pub fn operate( if !no_refresh { refresh_enabled_topics_sources_list(no_progress)?; - refresh(no_progress, network_threads, refresh_topic)?; + refresh(no_progress, network_threads, refresh_topic, apt_options)?; } Ok(0) @@ -403,6 +415,7 @@ pub fn set_order( refresh_topic: bool, network_threads: usize, no_refresh: bool, + apt_options: Vec, ) -> Result { root()?; @@ -428,7 +441,7 @@ pub fn set_order( if !no_refresh { refresh_enabled_topics_sources_list(no_progress)?; - refresh(no_progress, network_threads, refresh_topic)?; + refresh(no_progress, network_threads, refresh_topic, apt_options)?; } Ok(0) @@ -446,6 +459,7 @@ pub fn speedtest( refresh_topic: bool, network_threads: usize, no_refresh: bool, + apt_options: Vec, ) -> Result { if set_fastest { root()?; @@ -570,7 +584,7 @@ pub fn speedtest( if !no_refresh { refresh_enabled_topics_sources_list(no_progress)?; - refresh(no_progress, network_threads, refresh_topic)?; + refresh(no_progress, network_threads, refresh_topic, apt_options)?; } } @@ -581,6 +595,7 @@ fn refresh( no_progress: bool, network_threads: usize, refresh_topic: bool, + apt_options: Vec, ) -> Result<(), OutputError> { let auth_config = auth_config("/"); let auth_config = auth_config.as_ref(); @@ -593,6 +608,7 @@ fn refresh( .refresh_topics(refresh_topic) .config(&AptConfig::new()) .maybe_auth_config(auth_config) + .apt_options(apt_options.clone()) .build() .run()?; diff --git a/src/subcommand/pick.rs b/src/subcommand/pick.rs index 9abc433bd..1b0668842 100644 --- a/src/subcommand/pick.rs +++ b/src/subcommand/pick.rs @@ -131,6 +131,7 @@ impl CliExecuter for Pick { .network_thread(download_threads.unwrap_or_else(|| config.network_thread())) .sysroot(&sysroot) .config(&apt_config) + .apt_options(apt_options.clone()) .maybe_auth_config(auth_config); #[cfg(feature = "aosc")] diff --git a/src/subcommand/refresh.rs b/src/subcommand/refresh.rs index de156d1ae..b9a609d7d 100644 --- a/src/subcommand/refresh.rs +++ b/src/subcommand/refresh.rs @@ -26,6 +26,9 @@ pub struct Refresh { /// Setup download threads (default as 4) #[arg(from_global, help = fl!("clap-download-threads-help"))] download_threads: Option, + /// Set apt options + #[arg(from_global, help = fl!("clap-apt-options-help"))] + apt_options: Vec, } impl CliExecuter for Refresh { @@ -36,6 +39,7 @@ impl CliExecuter for Refresh { sysroot, dry_run, download_threads, + apt_options, } = self; if dry_run { @@ -57,6 +61,7 @@ impl CliExecuter for Refresh { .network_thread(download_threads.unwrap_or_else(|| config.network_thread())) .sysroot(&sysroot_str) .config(&apt_config) + .apt_options(apt_options) .maybe_auth_config(auth_config); #[cfg(feature = "aosc")] diff --git a/src/subcommand/topics.rs b/src/subcommand/topics.rs index 6c43347d9..a1ff2b829 100644 --- a/src/subcommand/topics.rs +++ b/src/subcommand/topics.rs @@ -227,6 +227,7 @@ impl CliExecuter for Topics { &sysroot, &apt_config, auth_config, + apt_options.clone(), )?; if only_apply_sources_list { @@ -235,7 +236,7 @@ impl CliExecuter for Topics { let oma_apt_args = OmaAptArgs::builder() .sysroot(sysroot.to_string_lossy().to_string()) - .another_apt_options(apt_options) + .another_apt_options(apt_options.clone()) .dpkg_force_unsafe_io(force_unsafe_io) .dpkg_force_confnew(force_confnew) .force_yes(force_yes) @@ -373,6 +374,7 @@ impl CliExecuter for Topics { &sysroot, &AptConfig::new(), auth_config, + apt_options, )?; } } @@ -397,6 +399,7 @@ fn refresh<'a>( sysroot: &'a Path, apt_config: &'a AptConfig, auth_config: Option<&'a apt_auth_config::AuthConfig>, + apt_options: Vec, ) -> Result<(), OutputError> { Refresh::builder() .client(&HTTP_CLIENT) @@ -407,6 +410,7 @@ fn refresh<'a>( .refresh_topics(true) .config(apt_config) .maybe_auth_config(auth_config) + .apt_options(apt_options) .build() .run() } diff --git a/src/subcommand/upgrade.rs b/src/subcommand/upgrade.rs index de709ae30..7a4dbf229 100644 --- a/src/subcommand/upgrade.rs +++ b/src/subcommand/upgrade.rs @@ -149,6 +149,7 @@ impl CliExecuter for Upgrade { .network_thread(download_threads.unwrap_or_else(|| config.network_thread())) .sysroot(&sysroot) .config(&apt_config) + .apt_options(apt_options.clone()) .auth_config(&auth_config); #[cfg(feature = "aosc")] diff --git a/src/subcommand/utils.rs b/src/subcommand/utils.rs index e8cc4306d..530b78f62 100644 --- a/src/subcommand/utils.rs +++ b/src/subcommand/utils.rs @@ -206,6 +206,7 @@ pub struct Refresh<'a> { refresh_topics: bool, config: &'a AptConfig, auth_config: Option<&'a AuthConfig>, + apt_options: Vec, } impl Refresh<'_> { @@ -219,6 +220,7 @@ impl Refresh<'_> { refresh_topics, config, auth_config, + apt_options, } = self; #[cfg(not(feature = "aosc"))] @@ -241,6 +243,7 @@ impl Refresh<'_> { .arch(arch) .apt_config(config) .client(client) + .another_apt_options(apt_options) .maybe_auth_config(auth_config); #[cfg(feature = "aosc")] diff --git a/src/tui/mod.rs b/src/tui/mod.rs index 4d71e0551..77c929964 100644 --- a/src/tui/mod.rs +++ b/src/tui/mod.rs @@ -189,6 +189,7 @@ impl CliExecuter for Tui { .network_thread(download_threads.unwrap_or_else(|| config.network_thread())) .sysroot(&sysroot) .config(&apt_config) + .apt_options(apt_options.clone()) .maybe_auth_config(auth_config); #[cfg(feature = "aosc")] From a814e634c69f030d620b07090a5fb67c15415fd3 Mon Sep 17 00:00:00 2001 From: eatradish Date: Mon, 22 Sep 2025 18:01:37 +0800 Subject: [PATCH 2/4] refactor(oma-pm): use `AptConfig::dir` to get archives dir --- oma-pm/src/apt.rs | 40 +--------------------------------------- oma-refresh/src/db.rs | 24 ++++++++++++++---------- 2 files changed, 15 insertions(+), 49 deletions(-) diff --git a/oma-pm/src/apt.rs b/oma-pm/src/apt.rs index d5267adbc..849d3467e 100644 --- a/oma-pm/src/apt.rs +++ b/oma-pm/src/apt.rs @@ -247,10 +247,6 @@ impl OmaApt { })?; config.set("Dir", &sysroot.display().to_string()); - config.set( - "Dir::State::status", - &sysroot.join("var/lib/dpkg/status").display().to_string(), - ); } debug!("Dir is: {:?}", config.get("Dir")); @@ -768,41 +764,7 @@ impl OmaApt { return PathBuf::from("/data/data/com.termux/cache/apt/archives/"); } - let archives_dir = self - .config - .get("Dir::Cache::Archives") - .unwrap_or_else(|| "archives/".to_string()); - - let cache = self - .config - .get("Dir::Cache") - .unwrap_or_else(|| "var/cache/apt".to_string()); - - let dir = self.config.get("Dir").unwrap_or_else(|| "/".to_string()); - - let archive_dir_p = PathBuf::from(archives_dir); - if archive_dir_p.is_absolute() { - return archive_dir_p; - } - - debug!("archive_dir_p is: {}", archive_dir_p.display()); - - let cache_dir_p = PathBuf::from(cache); - if cache_dir_p.is_absolute() { - return cache_dir_p.join(archive_dir_p); - } - - debug!("cache_dir_p is: {}", cache_dir_p.display()); - - let dir_p = PathBuf::from(dir); - - debug!("dir_p is: {}", dir_p.display()); - - let res = dir_p.join(cache_dir_p).join(archive_dir_p); - - debug!("get_archive_dir is: {}", res.display()); - - res + PathBuf::from(&self.config.dir("Dir::Cache::Archives", "archives/")) }) } diff --git a/oma-refresh/src/db.rs b/oma-refresh/src/db.rs index fcb6893e6..e815f83b5 100644 --- a/oma-refresh/src/db.rs +++ b/oma-refresh/src/db.rs @@ -215,19 +215,12 @@ impl<'a> OmaRefresh<'a> { return Err(RefreshError::WrongThreadCount(self.threads)); } + #[cfg(feature = "apt")] + self.init_apt_options(); + let paths = if let Some(ref paths) = self.sources_lists_paths { paths.to_vec() } else { - #[cfg(feature = "apt")] - self.apt_config.set("Dir", &self.source.to_string_lossy()); - - #[cfg(feature = "apt")] - for i in &self.another_apt_options { - let (k, v) = i.split_once('=').unwrap_or((i.as_str(), "")); - debug!("Setting apt opt: {k}={v}"); - self.apt_config.set(k, v); - } - #[cfg(feature = "apt")] let list_file = self.apt_config.file("Dir::Etc::sourcelist", "sources.list"); @@ -330,6 +323,17 @@ impl<'a> OmaRefresh<'a> { Ok(res.success) } + #[cfg(feature = "apt")] + fn init_apt_options(&self) { + self.apt_config.set("Dir", &self.source.to_string_lossy()); + + for i in &self.another_apt_options { + let (k, v) = i.split_once('=').unwrap_or((i.as_str(), "")); + debug!("Setting apt opt: {k}={v}"); + self.apt_config.set(k, v); + } + } + async fn download_release_data( &self, callback: &impl AsyncFn(Event), From 28731ade2d933d38b9ddf49f83b179002e677227 Mon Sep 17 00:00:00 2001 From: eatradish Date: Tue, 23 Sep 2025 11:37:18 +0800 Subject: [PATCH 3/4] clippy --- src/subcommand/mirror.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/subcommand/mirror.rs b/src/subcommand/mirror.rs index 2e5a41ee0..857d36adc 100644 --- a/src/subcommand/mirror.rs +++ b/src/subcommand/mirror.rs @@ -364,13 +364,14 @@ pub fn tui( Ok(0) } -pub enum Operate { +enum Operate { Set, Add, Remove, } -pub fn operate( +#[allow(clippy::too_many_arguments)] +fn operate( no_progress: bool, refresh_topic: bool, network_threads: usize, From ea02cbe1fac0a27ffaef6d641035c719975736c3 Mon Sep 17 00:00:00 2001 From: eatradish Date: Tue, 23 Sep 2025 12:46:07 +0800 Subject: [PATCH 4/4] fmt --- oma-refresh/src/db.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/oma-refresh/src/db.rs b/oma-refresh/src/db.rs index e815f83b5..5d09088eb 100644 --- a/oma-refresh/src/db.rs +++ b/oma-refresh/src/db.rs @@ -326,7 +326,7 @@ impl<'a> OmaRefresh<'a> { #[cfg(feature = "apt")] fn init_apt_options(&self) { self.apt_config.set("Dir", &self.source.to_string_lossy()); - + for i in &self.another_apt_options { let (k, v) = i.split_once('=').unwrap_or((i.as_str(), "")); debug!("Setting apt opt: {k}={v}");