创建目录
@param $fd
@param $cmd
760594
function cmd_MKD($fd, $cmd)
    {
        $user = $this->getUser($fd);
        $path = $this->getAbsDir($user).$cmd[1];

        if (!is_dir(dirname($path)))
        {
            $this->send($fd, "550 Can't create directory: No such file or directory");
        }
        elseif(file_exists($path))
        {
            $this->send($fd, "550 Can't create directory: File exists");
        }
        else
        {
            if (mkdir($path))
            {
                $this->send($fd, "257 \"" . $cmd[1] . "\" : The directory was successfully created");
            }
            else
            {
                $this->send($fd, "550 Can't create directory: Permission denied");
            }
        }
    }
824274
public function setCmd(?array $cmd)
    {
        $this->cmd = $cmd;

        $this->raw = array_merge($this->raw, ['Cmd' => $cmd]);

        return $this;
    }
857313
public static function detectCmdLocationInPath(string $cmd, string $path) : string
    {
        $command = $path . DIRECTORY_SEPARATOR . $cmd;
        $bin     = self::getExecutable($command);
        if (empty($bin)) {
            throw new RuntimeException(sprintf('wrong path specified for \'%s\': %s', $cmd, $path));
        }
        return $bin;
    }
666237
public function mustRun($cmd, $error = null)
    {
        return $this->helper->mustRun($this->output, $cmd, $error);
    }
535220
public function exec($cmd, $args)
    {
        if (!$this->loaded) {
            return array('error' => $this->error(self::ERROR_CONF, self::ERROR_CONF_NO_VOL));
        }

        if (!$this->commandExists($cmd)) {
            return array('error' => $this->error(self::ERROR_UNKNOWN_CMD));
        }

        if (!empty($args['mimes']) && is_array($args['mimes'])) {
            foreach ($this->volumes as $id => $v) {
                $this->volumes[$id]->setMimesFilter($args['mimes']);
            }
        }

        $result = $this->$cmd($args);

        if (isset($result['removed'])) {
            foreach ($this->volumes as $volume) {
                $result['removed'] = array_merge($result['removed'], $volume->removed());
                $volume->resetRemoved();
            }
        }

        // call handlers for this command
        if (!empty($this->listeners[$cmd])) {
            foreach ($this->listeners[$cmd] as $handler) {
                if ((is_array($handler) && $handler[0]->{$handler[1]}($cmd, $result, $args, $this))
                ||  (!is_array($handler) && $handler($cmd, $result, $args, $this))) {
                    // handler return true to force sync client after command completed
                    $result['sync'] = true;
                }
            }
        }

        // replace removed files info with removed files hashes
        if (!empty($result['removed'])) {
            $removed = array();
            foreach ($result['removed'] as $file) {
                $removed[] = $file['hash'];
            }
            $result['removed'] = array_unique($removed);
        }
        // remove hidden files and filter files by mimetypes
        if (!empty($result['added'])) {
            $result['added'] = $this->filter($result['added']);
        }
        // remove hidden files and filter files by mimetypes
        if (!empty($result['changed'])) {
            $result['changed'] = $this->filter($result['changed']);
        }

        if ($this->debug || !empty($args['debug'])) {
            $result['debug'] = array(
                'connector' => 'php',
                'phpver'    => PHP_VERSION,
                'time'      => $this->utime() - $this->time,
                'memory'    => (function_exists('memory_get_peak_usage') ? ceil(memory_get_peak_usage()/1024).'Kb / ' : '').ceil(memory_get_usage()/1024).'Kb / '.ini_get('memory_limit'),
                'upload'    => $this->uploadDebug,
                'volumes'   => array(),
                'mountErrors' => $this->mountErrors
                );

            foreach ($this->volumes as $id => $volume) {
                $result['debug']['volumes'][] = $volume->debug();
            }
        }

        foreach ($this->volumes as $volume) {
            $volume->umount();
        }

        return $result;
    }
83856
protected static function exec($cmd, $args)
    {
        $command = self::which($cmd) . ' ' . join(' ', array_map('escapeshellarg', $args));
        
        $descriptorspec = array(
           1 => array("pipe", "w"),  // stdout
           2 => array("pipe", "w")   // stderr
        );

        $handle = proc_open($command, $descriptorspec, $pipes);
        if (!$handle) throw new \Exception("Failed to run sox command");
        
        $out = stream_get_contents($pipes[1]);
        $err = stream_get_contents($pipes[2]);
        
        $ret = proc_close($handle);
        if ($ret != 0) throw new \Exception("$cmd command failed. " . trim($err));

        return $out ?: $err;
    }
31807
public static function detectCmdLocationInPaths($cmd, array $paths) : string
    {
        foreach ($paths as $path) {
            $command = $path . DIRECTORY_SEPARATOR . $cmd;
            $bin     = self::getExecutable($command);
            if (null !== $bin) {
                return $bin;
            }
        }
        return '';
    }
1346585
public function run(string $cmd, array $acceptableExitCodes = [0]) : Result
    {
        $old            = error_reporting(0);
        $descriptorSpec = [
            ['pipe', 'r'],
            ['pipe', 'w'],
            ['pipe', 'w'],
        ];

        $process = proc_open($cmd, $descriptorSpec, $pipes);
        if (!is_resource($process)) {
            throw new RuntimeException('can\'t execute \'proc_open\'');
        }

        $stdOut = stream_get_contents($pipes[1]);
        fclose($pipes[1]);

        $stdErr = stream_get_contents($pipes[2]);
        fclose($pipes[2]);

        $code = proc_close($process);
        error_reporting($old);

        return new Result($cmd, $code, $stdOut, $stdErr, '', $acceptableExitCodes);
    }
1120392
private function send_req($cmd, $params) {
        $req = [$cmd];
        foreach ($params as $p) {
            if (is_array($p)) {
                $req = array_merge($req, $p);
            } else {
                $req[] = $p;
            }
        }

        return $this->send($req);
    }
1222946
public function set_cwd( $cwd ) {

		$file = $this->get_file( $cwd );

		if ( false === $file || 'dir' !== $file->type ) {
			return false;
		}

		$this->cwd = $this->normalize_path( $cwd );

		if ( empty( $this->cwd ) ) {
			$this->cwd = '/';
		}

		return true;
	}
1118376
function mkdir($path, $owner = null, $mode = 0755)
    {
        mkdir($path, $mode, true);

        if ($owner) {
            $this->chown($path, $owner);
        }
    }
734998
public function cmd($cmd, array $args = array(), $selector = null)
    {
        if (!$this->matched) {
            $this->matched = true;
            return $this;
        }

        $selector = Phery::coalesce($selector, $this->last_selector);

        if ($selector === null) {
            $this->data['0' . ($this->internal_cmd_count++)] = array(
                'c' => $cmd,
                'a' => $args
            );
        } else {
            if (!isset($this->data[$selector])) {
                $this->data[$selector] = array();
            }
            $this->data[$selector][] = array(
                'c' => $cmd,
                'a' => $args
            );
        }

        if ($this->restore !== null) {
            $this->last_selector = $this->restore;
            $this->restore = null;
        }

        return $this;
    }
523757
public function run($cmd, $error = null)
    {
        return $this->helper->run($this->output, $cmd, $error);
    }
551734
public static function init(Event $event, ScriptInterface $cmd)
    {
        if (!self::$_inited) {
            try {
                self::$_event   = $event;
                self::$_cmd     = $cmd;
                if (false===@class_exists('\WebDocBook\Filesystem\Helper')) {
                    include_once    __DIR__.'/../Filesystem/Helper.php';
                }
                if (false===@class_exists('\WebDocBook\Kernel')) {
                    include_once    __DIR__.'/../Kernel.php';
                }
                self::parseArguments();
                if (!defined(\WebDocBook\Kernel::BASEDIR_CONSTNAME)) {
                    self::parseExtra();
                }
                \WebDocBook\Kernel::boot(true);
            } catch (\Exception $e) {
                self::error($e);
            }
            self::$_inited = true;
        }
    }
1316587
public static function detectCmdLocationWithWhich($cmd) : string
    {
        $bin = '';
        // on nx systems use 'which' command.
        if (!defined('PHP_WINDOWS_VERSION_BUILD')) {
            $command = trim(`which $cmd`);
            $bin     = self::getExecutable($command);
        }
        return $bin;

    }
93384
public static function execInBackground(string $cmd): void
    {
        if (self::isWindows()) {
            \pclose(\popen('start /B ' . $cmd, 'r'));
        } else {
            \exec($cmd . ' > /dev/null &');
        }
    }
508604
protected function createProcess(string $cmd, string $cwd): Process
    {
        $process = $this->processFactory->getProcess(
            $cmd,
            $cwd,
            $this->discoverSystemEnvironment()
        );
        $process->setTimeout(null);

        return $process;
    }