Skip to content

Commit ec4cdb8

Browse files
committed
feat(oma-refresh): support custom Dir::Etc::SourceList
1 parent 7ee1013 commit ec4cdb8

File tree

2 files changed

+32
-5
lines changed

2 files changed

+32
-5
lines changed

oma-refresh/src/db.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,19 @@ impl<'a> OmaRefresh<'a> {
216216
let paths = if let Some(ref paths) = self.sources_lists_paths {
217217
paths.to_vec()
218218
} else {
219-
scan_sources_lists_paths_from_sysroot(&self.source)
219+
#[cfg(feature = "apt")]
220+
let list_file = self.apt_config.get("Dir::Etc::sourcelist").unwrap_or_else(|| "sources.list".to_string());
221+
222+
#[cfg(feature = "apt")]
223+
let list_dir = self.apt_config.get("Dir::Etc::sourceparts").unwrap_or_else(|| "sources.list.d".to_string());
224+
225+
#[cfg(not(feature = "apt"))]
226+
let list_file = "/etc/apt/sources.list";
227+
228+
#[cfg(not(feature = "apt"))]
229+
let list_dir = "/etc/apt/sources.list.d";
230+
231+
scan_sources_lists_paths_from_sysroot(&self.source, list_file, list_dir)
220232
.await
221233
.map_err(RefreshError::ScanSourceError)?
222234
};

oma-refresh/src/sourceslist.rs

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,17 +55,32 @@ impl Debug for OmaSourceEntry<'_> {
5555
}
5656

5757
pub(crate) async fn scan_sources_lists_paths_from_sysroot(
58-
sysroot: impl AsRef<Path>,
58+
dir: impl AsRef<Path>,
59+
list_file: impl AsRef<str>,
60+
list_dir: impl AsRef<str>,
5961
) -> Result<Vec<PathBuf>, SourcesListError> {
6062
let mut paths = vec![];
61-
let default = sysroot.as_ref().join("etc/apt/sources.list");
63+
let default = Path::new(list_file.as_ref());
64+
let list_dir = Path::new(list_dir.as_ref());
65+
66+
let default = if !default.is_absolute() {
67+
dir.as_ref().join("etc/apt").join(default)
68+
} else {
69+
dir.as_ref().join(default)
70+
};
6271

6372
if default.exists() {
6473
paths.push(default);
6574
}
6675

67-
if sysroot.as_ref().join("etc/apt/sources.list.d/").exists() {
68-
let mut dir = tokio::fs::read_dir(sysroot.as_ref().join("etc/apt/sources.list.d/")).await?;
76+
let list_dir = if !list_dir.is_absolute() {
77+
dir.as_ref().join("etc/apt").join(list_dir)
78+
} else {
79+
dir.as_ref().join(list_dir)
80+
};
81+
82+
if list_dir.exists() {
83+
let mut dir = tokio::fs::read_dir(list_dir).await?;
6984
while let Some(entry) = dir.next_entry().await? {
7085
let path = entry.path();
7186
if !path.is_file() {

0 commit comments

Comments
 (0)