Skip to content

Commit 889ac35

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

File tree

2 files changed

+26
-7
lines changed

2 files changed

+26
-7
lines changed

oma-refresh/src/db.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,24 @@ 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+
self.apt_config.set("Dir", &self.source.to_string_lossy());
221+
222+
#[cfg(feature = "apt")]
223+
let list_file = self.apt_config.file("Dir::Etc::sourcelist", "sources.list");
224+
225+
#[cfg(feature = "apt")]
226+
let list_dir = self
227+
.apt_config
228+
.dir("Dir::Etc::sourceparts", "sources.list.d");
229+
230+
#[cfg(not(feature = "apt"))]
231+
let list_file = self.source.join("etc/apt/sources.list");
232+
233+
#[cfg(not(feature = "apt"))]
234+
let list_dir = self.source.join("etc/apt/sources.list.d");
235+
236+
scan_sources_lists_paths_from_sysroot(list_file, list_dir)
220237
.await
221238
.map_err(RefreshError::ScanSourceError)?
222239
};

oma-refresh/src/sourceslist.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,24 +55,26 @@ impl Debug for OmaSourceEntry<'_> {
5555
}
5656

5757
pub(crate) async fn scan_sources_lists_paths_from_sysroot(
58-
sysroot: impl AsRef<Path>,
58+
list_file: impl AsRef<str>,
59+
list_dir: impl AsRef<str>,
5960
) -> Result<Vec<PathBuf>, SourcesListError> {
6061
let mut paths = vec![];
61-
let default = sysroot.as_ref().join("etc/apt/sources.list");
62+
let default = Path::new(list_file.as_ref());
63+
let list_dir_path = Path::new(list_dir.as_ref());
6264

6365
if default.exists() {
64-
paths.push(default);
66+
paths.push(default.to_path_buf());
6567
}
6668

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?;
69+
if list_dir_path.exists() {
70+
let mut dir = tokio::fs::read_dir(list_dir_path).await?;
6971
while let Some(entry) = dir.next_entry().await? {
7072
let path = entry.path();
7173
if !path.is_file() {
7274
continue;
7375
}
7476

75-
paths.push(path);
77+
paths.push(path.to_path_buf());
7678
}
7779
}
7880

0 commit comments

Comments
 (0)