modifs.mineures sans commentaires

This commit is contained in:
Jephté Clain 2024-06-13 17:32:44 +04:00
parent a09f3a0a2b
commit 5c4a2e83ad
3 changed files with 6 additions and 19 deletions

View File

@ -175,7 +175,7 @@ abstract class AbstractCmd implements ICmd {
} }
} }
abstract function getCmd(?string $sep=null): string; abstract function getCmd(?string $sep=null, bool $exec=false): string;
function passthru(int &$retcode=null): bool { function passthru(int &$retcode=null): bool {
passthru($this->getCmd(), $retcode); passthru($this->getCmd(), $retcode);
@ -193,21 +193,8 @@ abstract class AbstractCmd implements ICmd {
return $retcode == 0; return $retcode == 0;
} }
/**
* retourner true s'il faut utiliser `exec` avec {@link fork_exec()}
*
* ne pas utiliser `exec` si des variables sont définies ou si c'est une
* composition de plusieurs commandes
*/
protected function useExec(): bool {
return $this->sources === null
&& $this->vars === null
&& count($this->cmds) == 1;
}
function fork_exec(int &$retcode=null): bool { function fork_exec(int &$retcode=null): bool {
$cmd = $this->getCmd(); $cmd = $this->getCmd(null, true);
if ($this->useExec()) $cmd = "exec $cmd";
sh::_fork_exec($cmd, $retcode); sh::_fork_exec($cmd, $retcode);
return $retcode == 0; return $retcode == 0;
} }

View File

@ -31,7 +31,7 @@ abstract class AbstractCmdList extends AbstractCmd {
return $this; return $this;
} }
function getCmd(?string $sep=null): string { function getCmd(?string $sep=null, bool $exec=false): string {
if ($sep === null) $sep = "\n"; if ($sep === null) $sep = "\n";
$actualCmd = []; $actualCmd = [];
@ -45,8 +45,8 @@ abstract class AbstractCmdList extends AbstractCmd {
} }
$parts[] = $cmd; $parts[] = $cmd;
} }
$psep = $this->sep ?? $sep; if (count($parts) == 1 && $exec) $parts[0] = "exec $parts[0]";
$actualCmd[] = implode($psep, $parts); $actualCmd[] = implode($this->sep ?? $sep, $parts);
return implode($sep, $actualCmd); return implode($sep, $actualCmd);
} }

View File

@ -49,7 +49,7 @@ class CmdPipe extends AbstractCmd {
return $this; return $this;
} }
function getCmd(?string $sep=null): string { function getCmd(?string $sep=null, bool $exec=false): string {
if ($sep === null) $sep = "\n"; if ($sep === null) $sep = "\n";
$actualCmd = []; $actualCmd = [];