Skip to content

Commit c0616d6

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

File tree

2 files changed

+9
-10
lines changed

2 files changed

+9
-10
lines changed

oma-topics/src/lib.rs

Lines changed: 5 additions & 3 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<Topic> {
211211
debug!("oma will opt_in: {}", topic);
212212

213213
let index = self
@@ -220,11 +220,13 @@ 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);
225227
}
226228

227-
return Ok(());
229+
return Ok(icc);
228230
}
229231

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

src/subcommand/topics.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -450,8 +450,11 @@ 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 t = tm.add(i)?;
457+
enabled_pkgs.extend(t.packages);
455458
}
456459

457460
let mut downgrade_pkgs = vec![];
@@ -460,12 +463,6 @@ async fn topics_inner(
460463
downgrade_pkgs.extend(removed_topic.packages);
461464
}
462465

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

0 commit comments

Comments
 (0)