Skip to content
Closed
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
9 changes: 8 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ openssl-setup = ["sequoia-openssl-backend", "openssl", "oma-refresh/apt"]
default = ["aosc", "nice-setup", "mirror"]

[workspace]
members = ["oma-contents", "oma-console", "oma-topics", "oma-fetch", "oma-refresh", "oma-utils", "oma-pm", "oma-history", "oma-pm-operation-type", "oma-repo-verify", "oma-mirror", "apt-auth-config", "oma-tum"]
members = ["oma-contents", "oma-console", "oma-topics", "oma-fetch", "oma-refresh", "oma-utils", "oma-pm", "oma-history", "oma-pm-operation-type", "oma-repo-verify", "oma-mirror", "apt-auth-config", "oma-tum", "oma-apt-config"]

[package.metadata.deb]
copyright = "2025, AOSC Dev <[email protected]>"
Expand Down
9 changes: 9 additions & 0 deletions oma-apt-config/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[package]
name = "oma-apt-config"
version = "0.1.0"
edition = "2024"
description = "APT config handler library"
license = "GPL-3.0-or-later"

[dependencies]
oma-apt = "0.9"
56 changes: 56 additions & 0 deletions oma-apt-config/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
use std::collections::HashMap;

pub use oma_apt::config::Config;
use oma_apt::config::ConfigTree;

fn modify_result(
tree: ConfigTree,
res: &mut HashMap<String, HashMap<String, String>>,
root_path: String,
) {
use std::collections::VecDeque;
let mut stack = VecDeque::new();
stack.push_back((tree, root_path));

let mut first = true;

while let Some((node, tree_path)) = stack.pop_back() {
// 跳过要遍历根节点的相邻节点
if !first && let Some(entry) = node.sibling() {
stack.push_back((entry, tree_path.clone()));
}

let Some(tag) = node.tag() else {
continue;
};

if let Some(entry) = node.child() {
stack.push_back((entry, format!("{tree_path}::{tag}")));
}

if let Some((k, v)) = node.tag().zip(node.value()) {
res.entry(tree_path).or_default().insert(k, v);
}

first = false;
}
}

pub fn get_tree(config: &Config, key: &str) -> Vec<(String, HashMap<String, String>)> {
let mut res = HashMap::new();
let tree = config.tree(key);

let Some(tree) = tree else {
return vec![];
};

modify_result(
tree,
&mut res,
key.rsplit_once("::")
.map(|x| x.0.to_string())
.unwrap_or_else(|| key.to_string()),
);

res.into_iter().collect::<Vec<_>>()
}
4 changes: 2 additions & 2 deletions oma-refresh/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ oma-topics = { version = "^0.25.0", path = "../oma-topics", optional = true, def
tracing ="0.1"
oma-repo-verify = { version = "^0.9.0", path = "../oma-repo-verify", default-features = false }
ahash = "0.8.11"
oma-apt = { version = "0.9.0", optional = true }
oma-apt-config = { version = "0.1.0", path = "../oma-apt-config", optional = true }
aho-corasick = "1.1.3"
# https://github.com/bytecodealliance/rustix/pull/1077
# rustix = { version = "0.38", features = ["fs"] }
Expand All @@ -39,7 +39,7 @@ sequoia-openssl-backend = ["oma-repo-verify/sequoia-openssl-backend"]
sequoia-nettle-backend = ["oma-repo-verify/sequoia-nettle-backend"]
rustls = ["oma-fetch/rustls", "oma-topics/rustls"]
native-tls = ["oma-fetch/native-tls", "oma-topics/native-tls"]
apt = ["dep:oma-apt"]
apt = ["dep:oma-apt-config"]
blocking = ["tokio/rt", "tokio/rt-multi-thread"]
default = ["aosc", "sequoia-nettle-backend", "rustls", "apt"]

Expand Down
2 changes: 1 addition & 1 deletion oma-refresh/examples/update.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::{path::Path, result::Result};

use apt_auth_config::AuthConfig;
use oma_apt::config::Config;
use oma_apt_config::Config;
use oma_fetch::reqwest::ClientBuilder;
use oma_refresh::db::{Event, OmaRefresh, RefreshError};
use oma_utils::dpkg::dpkg_arch;
Expand Down
60 changes: 4 additions & 56 deletions oma-refresh/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,66 +3,12 @@ use std::{borrow::Cow, collections::HashMap, path::Path};
use ahash::AHashMap;
use aho_corasick::AhoCorasick;
#[cfg(feature = "apt")]
use oma_apt::config::{Config, ConfigTree};
use oma_apt_config::Config;
use oma_fetch::CompressFile;
use tracing::debug;

use crate::{db::RefreshError, inrelease::ChecksumItem};

#[cfg(feature = "apt")]
fn modify_result(
tree: ConfigTree,
res: &mut HashMap<String, HashMap<String, String>>,
root_path: String,
) {
use std::collections::VecDeque;
let mut stack = VecDeque::new();
stack.push_back((tree, root_path));

let mut first = true;

while let Some((node, tree_path)) = stack.pop_back() {
// 跳过要遍历根节点的相邻节点
if !first && let Some(entry) = node.sibling() {
stack.push_back((entry, tree_path.clone()));
}

let Some(tag) = node.tag() else {
continue;
};

if let Some(entry) = node.child() {
stack.push_back((entry, format!("{tree_path}::{tag}")));
}

if let Some((k, v)) = node.tag().zip(node.value()) {
res.entry(tree_path).or_default().insert(k, v);
}

first = false;
}
}

#[cfg(feature = "apt")]
pub fn get_tree(config: &Config, key: &str) -> Vec<(String, HashMap<String, String>)> {
let mut res = HashMap::new();
let tree = config.tree(key);

let Some(tree) = tree else {
return vec![];
};

modify_result(
tree,
&mut res,
key.rsplit_once("::")
.map(|x| x.0.to_string())
.unwrap_or_else(|| key.to_string()),
);

res.into_iter().collect::<Vec<_>>()
}

pub struct IndexTargetConfig<'a> {
deb: Vec<HashMap<String, String>>,
deb_src: Vec<HashMap<String, String>>,
Expand Down Expand Up @@ -243,7 +189,7 @@ fn uncompress_file_name(target: &str) -> Cow<'_, str> {

#[cfg(feature = "apt")]
fn get_index_target_tree(config: &Config, key: &str) -> Vec<HashMap<String, String>> {
get_tree(config, key)
oma_apt_config::get_tree(config, key)
.into_iter()
.map(|x| x.1)
.filter(|x| {
Expand Down Expand Up @@ -314,6 +260,8 @@ fn test_get_matches_language() {
#[cfg(feature = "apt")]
#[test]
fn test_get_tree() {
use oma_apt_config::get_tree;

let t = get_tree(&Config::new(), "Acquire::IndexTargets::deb");
assert!(t.iter().any(|x| x.0.contains("::deb::")));
assert!(t.iter().all(|x| !x.0.contains("::deb-src::")))
Expand Down
2 changes: 1 addition & 1 deletion oma-refresh/src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use nix::{
unistd::close,
};
#[cfg(feature = "apt")]
use oma_apt::config::Config;
use oma_apt_config::Config;
use oma_apt_sources_lists::SourcesListError;
use oma_fetch::{
CompressFile, DownloadEntry, DownloadManager, DownloadSource, DownloadSourceType,
Expand Down
2 changes: 1 addition & 1 deletion oma-refresh/src/sourceslist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ pub(crate) async fn scan_sources_lists_paths_from_sysroot(
}

#[cfg(feature = "apt")]
pub fn ignores(config: &oma_apt::config::Config) -> Vec<Regex> {
pub fn ignores(config: &oma_apt_config::Config) -> Vec<Regex> {
use tracing::warn;

config.find_vector("Dir::Ignore-Files-Silently")
Expand Down
Loading