Skip to content

Commit f95b089

Browse files
committed
fix(oma-topics)!: make oma topics enabled pkgs operation atomic
1 parent e8eb6d2 commit f95b089

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed

oma-topics/src/lib.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ impl<'a> TopicManager<'a> {
207207
}
208208

209209
/// Enable select topic
210-
pub fn add(&mut self, topic: &str) -> Result<()> {
210+
pub fn add(&mut self, topic: &str) -> Result<Option<Topic>> {
211211
debug!("oma will opt_in: {}", topic);
212212

213213
let index = self
@@ -220,11 +220,14 @@ impl<'a> TopicManager<'a> {
220220
debug!("Enabled: {enabled_names:?}");
221221

222222
if let Some(index) = index {
223+
let ic = index.clone();
224+
let icc = index.clone();
223225
if !enabled_names.contains(&&index.name) {
224-
self.enabled.push(index.clone());
226+
self.enabled.push(ic);
227+
return Ok(Some(icc));
228+
} else {
229+
return Ok(None);
225230
}
226-
227-
return Ok(());
228231
}
229232

230233
debug!("index: {index:?} does not exist");

src/subcommand/topics.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -450,8 +450,13 @@ async fn topics_inner(
450450
.unwrap()?;
451451
}
452452

453+
let mut enabled_pkgs = vec![];
454+
453455
for i in opt_in {
454-
tm.add(i)?;
456+
let Some(t) = tm.add(i)? else {
457+
continue;
458+
};
459+
enabled_pkgs.extend(t.packages);
455460
}
456461

457462
let mut downgrade_pkgs = vec![];
@@ -460,12 +465,6 @@ async fn topics_inner(
460465
downgrade_pkgs.extend(removed_topic.packages);
461466
}
462467

463-
let enabled_pkgs = tm
464-
.enabled_topics()
465-
.iter()
466-
.flat_map(|x| x.packages.clone())
467-
.collect::<Vec<_>>();
468-
469468
Ok(TopicChanged {
470469
enabled_pkgs,
471470
downgrade_pkgs,

0 commit comments

Comments
 (0)