Skip to content

Commit

Permalink
refactor(oma-refresh): pre-check source is duplicate
Browse files Browse the repository at this point in the history
  • Loading branch information
eatradish committed Nov 1, 2024
1 parent 9e021f3 commit 35fc77d
Showing 1 changed file with 23 additions and 15 deletions.
38 changes: 23 additions & 15 deletions oma-refresh/src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,29 @@ impl<'a> OmaRefresh<'a> {
}
}

// 查看源配置中是否有重复的源
// 重复的源的定义:源地址相同 源类型相同 源 component 有重复项
// 比如:
// deb https://mirrors.bfsu.edu.cn/anthon/debs stable main
// deb https://mirrors.bfsu.edu.cn/anthon/debs stable main contrib
// 重复的项为:deb https://mirrors.bfsu.edu.cn/anthon/debs stable
for ose_list in map.values() {
let mut no_dups_components = HashSet::with_hasher(ahash::RandomState::new());

for ose in ose_list {
for c in ose.components() {
if !no_dups_components.contains(&(c, ose.is_source())) {
no_dups_components.insert((c, ose.is_source()));
} else {
return Err(RefreshError::DuplicateComponents(
ose.url().into(),
c.to_string(),
));
}
}
}
}

Ok((tasks, map))
}

Expand Down Expand Up @@ -639,21 +662,6 @@ impl<'a> OmaRefresh<'a> {
// 源数据确保是存在的,所以直接 unwrap
let ose_list = sources_map.get(&inrelease_summary.filename).unwrap();

let mut no_dups_components = HashSet::with_hasher(ahash::RandomState::new());

for i in ose_list {
for c in i.components() {
if !no_dups_components.contains(&(c, i.is_source())) {
no_dups_components.insert((c, i.is_source()));
} else {
return Err(RefreshError::DuplicateComponents(
i.url().into(),
c.to_string(),
));
}
}
}

for ose in ose_list {
debug!("Getted oma source entry: {:#?}", ose);
let inrelease_path = self.download_dir.join(&*inrelease_summary.filename);
Expand Down

0 comments on commit 35fc77d

Please sign in to comment.