Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 1 addition & 39 deletions oma-pm/src/apt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
Expand Down Expand Up @@ -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/"))
})
}

Expand Down
1 change: 1 addition & 0 deletions oma-refresh/examples/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
35 changes: 34 additions & 1 deletion oma-refresh/src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ pub struct OmaRefresh<'a> {
topic_msg: &'a str,
auth_config: Option<&'a AuthConfig>,
sources_lists_paths: Option<Vec<PathBuf>>,
#[builder(default)]
another_apt_options: Vec<String>,
}

/// Create `apt update` file lock
Expand Down Expand Up @@ -213,10 +215,30 @@ 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 {
scan_sources_lists_paths_from_sysroot(&self.source)
#[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)?
};
Expand Down Expand Up @@ -301,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),
Expand Down
14 changes: 8 additions & 6 deletions oma-refresh/src/sourceslist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,24 +55,26 @@ impl Debug for OmaSourceEntry<'_> {
}

pub(crate) async fn scan_sources_lists_paths_from_sysroot(
sysroot: impl AsRef<Path>,
list_file: impl AsRef<str>,
list_dir: impl AsRef<str>,
) -> Result<Vec<PathBuf>, 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());
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/subcommand/history.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/subcommand/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down
29 changes: 23 additions & 6 deletions src/subcommand/mirror.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<usize>,
/// Set apt options
#[arg(from_global, help = fl!("clap-apt-options-help"))]
apt_options: Vec<String>,
}

#[derive(Debug, Subcommand)]
Expand Down Expand Up @@ -190,6 +193,7 @@ impl CliExecuter for CliMirror {
no_refresh,
dry_run,
download_threads,
apt_options,
} = self;

if dry_run {
Expand All @@ -212,6 +216,7 @@ impl CliExecuter for CliMirror {
names.iter().map(|x| x.as_str()).collect::<Vec<_>>(),
sysroot,
Operate::Set,
apt_options,
),
MirrorSubCmd::Speedtest {
set_fastest,
Expand All @@ -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,
Expand All @@ -238,6 +244,7 @@ impl CliExecuter for CliMirror {
names.iter().map(|x| x.as_str()).collect::<Vec<_>>(),
sysroot,
Operate::Add,
apt_options,
),
MirrorSubCmd::Remove {
names,
Expand All @@ -252,6 +259,7 @@ impl CliExecuter for CliMirror {
names.iter().map(|x| x.as_str()).collect::<Vec<_>>(),
sysroot,
Operate::Remove,
apt_options,
),
MirrorSubCmd::SortMirrors {
no_refresh_topics,
Expand All @@ -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 {
Expand All @@ -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,
)
}
}
Expand All @@ -279,6 +289,7 @@ pub fn tui(
refresh_topic: bool,
network_threads: usize,
no_refresh: bool,
apt_options: Vec<String>,
) -> Result<i32, OutputError> {
root()?;

Expand Down Expand Up @@ -347,26 +358,28 @@ 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)
}

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,
no_refresh: bool,
args: Vec<&str>,
sysroot: PathBuf,
subcmd: Operate,
apt_options: Vec<String>,
) -> Result<i32, OutputError> {
root()?;

Expand All @@ -392,7 +405,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)
Expand All @@ -403,6 +416,7 @@ pub fn set_order(
refresh_topic: bool,
network_threads: usize,
no_refresh: bool,
apt_options: Vec<String>,
) -> Result<i32, OutputError> {
root()?;

Expand All @@ -428,7 +442,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)
Expand All @@ -446,6 +460,7 @@ pub fn speedtest(
refresh_topic: bool,
network_threads: usize,
no_refresh: bool,
apt_options: Vec<String>,
) -> Result<i32, OutputError> {
if set_fastest {
root()?;
Expand Down Expand Up @@ -570,7 +585,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)?;
}
}

Expand All @@ -581,6 +596,7 @@ fn refresh(
no_progress: bool,
network_threads: usize,
refresh_topic: bool,
apt_options: Vec<String>,
) -> Result<(), OutputError> {
let auth_config = auth_config("/");
let auth_config = auth_config.as_ref();
Expand All @@ -593,6 +609,7 @@ fn refresh(
.refresh_topics(refresh_topic)
.config(&AptConfig::new())
.maybe_auth_config(auth_config)
.apt_options(apt_options.clone())
.build()
.run()?;

Expand Down
1 change: 1 addition & 0 deletions src/subcommand/pick.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down
5 changes: 5 additions & 0 deletions src/subcommand/refresh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<usize>,
/// Set apt options
#[arg(from_global, help = fl!("clap-apt-options-help"))]
apt_options: Vec<String>,
}

impl CliExecuter for Refresh {
Expand All @@ -36,6 +39,7 @@ impl CliExecuter for Refresh {
sysroot,
dry_run,
download_threads,
apt_options,
} = self;

if dry_run {
Expand All @@ -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")]
Expand Down
Loading
Loading