Skip to content

Commit b63afa4

Browse files
committed
Refactor
1 parent 712257f commit b63afa4

2 files changed

Lines changed: 19 additions & 62 deletions

File tree

src/core/builtins/job_commands.rs

Lines changed: 0 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -333,64 +333,3 @@ fn wait_arg_job(
333333

334334
Ok((127, false))
335335
}
336-
337-
fn wait_all(core: &mut ShellCore) -> Result<i32, ExecError> {
338-
let mut exit_status = 0;
339-
let mut remove_list = vec![];
340-
for pos in 0..core.job_table.len() {
341-
let result = core.job_table[pos].nonblock_wait(&core.sigint)?;
342-
exit_status = result.0;
343-
if result.1 {
344-
remove_list.push(pos);
345-
}
346-
}
347-
348-
for pos in remove_list.into_iter().rev() {
349-
remove(core, pos);
350-
}
351-
352-
Ok(exit_status)
353-
}
354-
355-
/*
356-
fn wait_n(
357-
core: &mut ShellCore,
358-
args: &mut Vec<String>,
359-
var_name: &Option<String>,
360-
f_opt: bool,
361-
) -> Result<i32, ExecError> {
362-
let mut jobs = arg::consume_with_subsequents("-n", args);
363-
jobs.remove(0);
364-
if jobs.is_empty() {
365-
return Ok(wait_next(core, &[], var_name, f_opt)?.0);
366-
}
367-
368-
let mut ids = vec![];
369-
for j in &jobs {
370-
if j.starts_with("%") {
371-
ids.append(&mut jobspec_to_array_poss(core, j));
372-
} else {
373-
for (i, job) in core.job_table.iter_mut().enumerate() {
374-
if job.pids[0].to_string() == *j {
375-
ids.push(i);
376-
}
377-
}
378-
}
379-
}
380-
ids.sort();
381-
ids.dedup();
382-
let mut ans = -1;
383-
384-
for _ in 0..ids.len() {
385-
let tmp = match ans {
386-
-1 => wait_next(core, &ids, var_name, f_opt)?,
387-
_ => wait_next(core, &ids, &None, f_opt)?,
388-
};
389-
390-
if tmp.1 && ans == -1 {
391-
ans = tmp.0;
392-
}
393-
}
394-
Ok(ans)
395-
}
396-
*/

src/core/builtins/job_commands/wait.rs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ pub fn wait(core: &mut ShellCore, args: &[String]) -> i32 {
1313
}
1414

1515
if args.len() <= 1 {
16-
match super::wait_all(core) {
16+
match wait_all(core) {
1717
Ok(n) => return n,
1818
Err(e) => {
1919
e.print(core);
@@ -88,3 +88,21 @@ fn wait_n(
8888
}
8989
Ok(ans)
9090
}
91+
92+
fn wait_all(core: &mut ShellCore) -> Result<i32, ExecError> {
93+
let mut exit_status = 0;
94+
let mut remove_list = vec![];
95+
for pos in 0..core.job_table.len() {
96+
let result = core.job_table[pos].nonblock_wait(&core.sigint)?;
97+
exit_status = result.0;
98+
if result.1 {
99+
remove_list.push(pos);
100+
}
101+
}
102+
103+
for pos in remove_list.into_iter().rev() {
104+
super::remove(core, pos);
105+
}
106+
107+
Ok(exit_status)
108+
}

0 commit comments

Comments
 (0)