diff --git a/src/exec.rs b/src/exec.rs index 097acff51..431e35cf3 100644 --- a/src/exec.rs +++ b/src/exec.rs @@ -983,13 +983,15 @@ fn get_performer_for_process( let job_group = job.group.clone(); let io_chain = io_chain.clone(); - if p.is_block_node() { - Some(Box::new(move |parser: &Parser, p: &Process, _out, _err| { - let node = p.block_node.as_ref().expect("Process is missing node info"); - parser - .eval_node(node, &io_chain, job_group.as_ref(), BlockType::top) - .status - })) + if let ProcessType::BlockNode(node) = &p.typ { + let node = node.clone(); + Some(Box::new( + move |parser: &Parser, _p: &Process, _out, _err| { + parser + .eval_node(&node, &io_chain, job_group.as_ref(), BlockType::top) + .status + }, + )) } else { assert!(p.is_function()); let Some(props) = function::get_props(p.argv0().unwrap()) else { @@ -1255,7 +1257,7 @@ fn exec_process_in_job( process_net_io_chain.push(Arc::new(IoClose::new(afd.as_raw_fd()))); } - if !matches!(p.typ, ProcessType::BlockNode) { + if !p.is_block_node() { // A simple `begin ... end` should not be considered an execution of a command. parser.libdata_mut().exec_count += 1; } @@ -1291,7 +1293,7 @@ fn exec_process_in_job( // Execute the process. p.check_generations_before_launch(); match p.typ { - ProcessType::Function | ProcessType::BlockNode => exec_block_or_func_process( + ProcessType::Function | ProcessType::BlockNode(_) => exec_block_or_func_process( parser, j, p, diff --git a/src/parse_execution.rs b/src/parse_execution.rs index 133264f60..5f14f692b 100644 --- a/src/parse_execution.rs +++ b/src/parse_execution.rs @@ -831,8 +831,7 @@ fn populate_block_process( let mut redirections = RedirectionSpecList::new(); let reason = self.determine_redirections(ctx, args_or_redirs, &mut redirections); if reason == EndExecutionReason::ok { - proc.typ = ProcessType::BlockNode; - proc.block_node = Some(NodeRef::new(Arc::clone(self.pstree()), statement)); + proc.typ = ProcessType::BlockNode(NodeRef::new(Arc::clone(self.pstree()), statement)); proc.set_redirection_specs(redirections); } reason diff --git a/src/proc.rs b/src/proc.rs index a92e2cb7e..15e18530c 100644 --- a/src/proc.rs +++ b/src/proc.rs @@ -56,7 +56,8 @@ pub enum ProcessType { /// A shellscript function. Function, /// A block of commands, represented as a node. - BlockNode, + /// This is always either block, ifs, or switchs, never boolean or decorated. + BlockNode(NodeRef), /// The exec builtin. Exec, } @@ -599,10 +600,6 @@ pub struct Process { /// Type of process. pub typ: ProcessType, - /// For internal block processes only, the node of the statement. - /// This is always either block, ifs, or switchs, never boolean or decorated. - pub block_node: Option>, - /// The expanded variable assignments for this process, as specified by the `a=b cmd` syntax. pub variable_assignments: Vec, @@ -741,7 +738,7 @@ pub fn mark_aborted_before_launch(&self) { /// Return whether this process type is internal (block, function, or builtin). pub fn is_internal(&self) -> bool { match self.typ { - ProcessType::Builtin | ProcessType::Function | ProcessType::BlockNode => true, + ProcessType::Builtin | ProcessType::Function | ProcessType::BlockNode(_) => true, ProcessType::External | ProcessType::Exec => false, } } @@ -754,7 +751,7 @@ pub fn is_function(&self) -> bool { matches!(self.typ, ProcessType::Function) } pub fn is_block_node(&self) -> bool { - matches!(self.typ, ProcessType::BlockNode) + matches!(self.typ, ProcessType::BlockNode(_)) } pub fn is_external(&self) -> bool { matches!(self.typ, ProcessType::External)