From c1acbf284511be1254018aefb669b1e9466c775c Mon Sep 17 00:00:00 2001 From: Mahmoud Al-Qudsi Date: Thu, 14 Nov 2024 13:24:55 -0600 Subject: [PATCH] Deduplicate jobs passed to `disown` builtin I'm guessing this was missed in the port because there were comments referencing using a hash set to perform the deduplication but there was no hashset. (The TODO was added later.) --- src/builtins/disown.rs | 6 +++++- src/job_group.rs | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/builtins/disown.rs b/src/builtins/disown.rs index 41c4ef939..8c6408041 100644 --- a/src/builtins/disown.rs +++ b/src/builtins/disown.rs @@ -80,7 +80,6 @@ pub fn disown(parser: &Parser, streams: &mut IoStreams, args: &mut [&wstr]) -> O retval = STATUS_CMD_ERROR; } } else { - // TODO: This is supposed to be deduplicated or a hash set per comments below! let mut jobs = vec![]; retval = STATUS_CMD_OK; @@ -116,6 +115,11 @@ pub fn disown(parser: &Parser, streams: &mut IoStreams, args: &mut [&wstr]) -> O return retval; } + // One PID/JID may be repeated or multiple PIDs may refer to the same job; + // include the job only once. + jobs.sort_unstable_by_key(|job| job.job_id()); + jobs.dedup_by_key(|job| job.job_id()); + // Disown all target jobs. for j in jobs { disown_job(cmd, streams, &j); diff --git a/src/job_group.rs b/src/job_group.rs index 9bb9ed432..709482154 100644 --- a/src/job_group.rs +++ b/src/job_group.rs @@ -12,7 +12,7 @@ use std::sync::{Arc, Mutex}; #[repr(transparent)] pub struct JobId(NonZeroU32); -#[derive(Clone, Copy, Debug, Eq, PartialEq)] +#[derive(Clone, Copy, Debug, Eq, PartialEq, PartialOrd, Ord)] pub struct MaybeJobId(pub Option); impl std::ops::Deref for MaybeJobId {