Skip to content

Commit 080a737

Browse files
authored
Merge pull request #569 from AOSC-Dev/allow-set-dir-state
Allow set apt option `Dir::State::lists`
2 parents 8021afb + 5afada5 commit 080a737

File tree

16 files changed

+51
-23
lines changed

16 files changed

+51
-23
lines changed

oma-tum/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,10 +140,10 @@ pub enum TumError {
140140
ReadFile { path: PathBuf, source: io::Error },
141141
}
142142

143-
pub fn get_tum(sysroot: &Path) -> Result<Vec<TopicUpdateManifest>, TumError> {
143+
pub fn get_tum(list_dir: impl AsRef<Path>) -> Result<Vec<TopicUpdateManifest>, TumError> {
144144
let mut entries = vec![];
145145

146-
for i in read_dir(sysroot.join("var/lib/apt/lists")).context(ReadAptListDirSnafu)? {
146+
for i in read_dir(list_dir).context(ReadAptListDirSnafu)? {
147147
let i = i.context(ReadDirEntrySnafu)?;
148148

149149
if i.path()

src/error.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,14 @@ impl From<OmaDbusError> for OutputError {
262262
#[cfg(feature = "aosc")]
263263
impl From<TumError> for OutputError {
264264
fn from(value: TumError) -> Self {
265-
let p1 = "/var/lib/apt/lists".to_string();
265+
use oma_pm::apt::AptConfig;
266+
267+
use crate::utils::get_lists_dir;
268+
269+
let p1 = get_lists_dir(&AptConfig::new())
270+
.to_string_lossy()
271+
.to_string();
272+
266273
match value {
267274
TumError::ReadAptListDir { source } => Self {
268275
description: fl!("failed-to-operate-path", p = p1),

src/main.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ use lang::LANGUAGE_LOADER;
3232
use oma_console::OmaLayer;
3333
use oma_console::print::{OmaColorFormat, termbg};
3434
use oma_console::writer::{MessageType, Writer, writeln_inner};
35+
use oma_pm::apt::AptConfig;
3536
use oma_utils::OsRelease;
3637
use oma_utils::dbus::{create_dbus_connection, get_another_oma_status};
3738
use reqwest::Client;
@@ -210,6 +211,8 @@ fn main() {
210211
}
211212
}
212213

214+
init_apt_config(&oma);
215+
213216
let code = match try_main(oma, config, matches) {
214217
Ok(exit_code) => {
215218
unlock_oma().ok();
@@ -233,6 +236,17 @@ fn main() {
233236
exit(code);
234237
}
235238

239+
fn init_apt_config(oma: &OhManagerAilurus) {
240+
let apt_config = AptConfig::new();
241+
apt_config.set("Dir", &oma.global.sysroot.to_string_lossy());
242+
243+
for kv in &oma.global.apt_options {
244+
let (k, v) = kv.split_once('=').unwrap_or((kv.as_str(), ""));
245+
debug!("Set apt option: {k}={v}");
246+
apt_config.set(k, v);
247+
}
248+
}
249+
236250
fn parse_args() -> (ArgMatches, OhManagerAilurus) {
237251
let matches = match OhManagerAilurus::command().try_get_matches() {
238252
Ok(m) => m,

src/subcommand/command_not_found.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ use tracing::error;
1212
use crate::config::Config;
1313
use crate::error::OutputError;
1414
use crate::table::PagerPrinter;
15+
use crate::utils::get_lists_dir;
1516
use crate::{color_formatter, due_to, fl};
1617

1718
use crate::args::CliExecuter;
1819

1920
const FILTER_JARO_NUM: u8 = 204;
20-
const APT_LIST_PATH: &str = "/var/lib/apt/lists";
2121

2222
type IndexSet<T> = indexmap::IndexSet<T, ahash::RandomState>;
2323

@@ -40,7 +40,12 @@ impl CliExecuter for CommandNotFound {
4040
}
4141
};
4242

43-
let search_res = search(APT_LIST_PATH, Mode::BinProvides, &keyword, cb);
43+
let search_res = search(
44+
get_lists_dir(&AptConfig::new()),
45+
Mode::BinProvides,
46+
&keyword,
47+
cb,
48+
);
4449

4550
match search_res {
4651
Ok(()) if res.is_empty() => {

src/subcommand/depends.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ impl CliExecuter for Depends {
6464
let (pkgs, no_result) =
6565
matcher.match_pkgs_and_versions(packages.iter().map(|x| x.as_str()))?;
6666

67-
handle_no_result(&sysroot, no_result, no_progress)?;
67+
handle_no_result(no_result, no_progress)?;
6868

6969
if !json {
7070
for pkg in pkgs {

src/subcommand/download.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ impl CliExecuter for Download {
6161

6262
let (pkgs, no_result) =
6363
matcher.match_pkgs_and_versions(packages.iter().map(|x| x.as_str()))?;
64-
handle_no_result("/", no_result, no_progress)?;
64+
handle_no_result(no_result, no_progress)?;
6565

6666
let (tx, rx) = unbounded();
6767

src/subcommand/history.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ impl CliExecuter for Undo {
256256
}
257257
}
258258

259-
handle_no_result(&sysroot, no_result, no_progress)?;
259+
handle_no_result(no_result, no_progress)?;
260260

261261
apt.remove(delete, false, true)?;
262262

src/subcommand/install.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ impl CliExecuter for Install {
219219

220220
let (pkgs, no_result) = matcher.match_pkgs_and_versions(pkgs_unparse)?;
221221

222-
handle_no_result(&sysroot, no_result, no_progress)?;
222+
handle_no_result(no_result, no_progress)?;
223223

224224
let no_marked_install = apt.install(&pkgs, reinstall)?;
225225

src/subcommand/mark.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ impl CliExecuter for Mark {
9898
let (pkgs, no_result) =
9999
matcher.match_pkgs_and_versions(packages.iter().map(|x| x.as_str()))?;
100100

101-
handle_no_result(&sysroot, no_result, no_progress)?;
101+
handle_no_result(no_result, no_progress)?;
102102

103103
apt.mark_install_status(pkgs, action == MarkAction::Auto, dry_run)?
104104
.into_iter()

src/subcommand/rdepends.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ impl CliExecuter for Rdepends {
6060
let (pkgs, no_result) =
6161
matcher.match_pkgs_and_versions(packages.iter().map(|x| x.as_str()))?;
6262

63-
handle_no_result(&sysroot, no_result, no_progress)?;
63+
handle_no_result(no_result, no_progress)?;
6464

6565
if !json {
6666
for pkg in pkgs {

0 commit comments

Comments
 (0)