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.)
This commit is contained in:
Mahmoud Al-Qudsi 2024-11-14 13:24:55 -06:00
parent 366c1b7210
commit c1acbf2845
2 changed files with 6 additions and 2 deletions

View File

@ -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);

View File

@ -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<JobId>);
impl std::ops::Deref for MaybeJobId {