本文整理汇总了PHP中Filesystem::resolveBinary方法的典型用法代码示例。如果您正苦于以下问题:PHP Filesystem::resolveBinary方法的具体用法?PHP Filesystem::resolveBinary怎么用?PHP Filesystem::resolveBinary使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Filesystem
的用法示例。
在下文中一共展示了Filesystem::resolveBinary方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: sudoCommandAsDaemonUser
/**
* Format a command so it executes as the daemon user, if a daemon user is
* defined. This wraps the provided command in `sudo -u ...`, roughly.
*
* @param PhutilCommandString Command to execute.
* @return PhutilCommandString `sudo` version of the command.
*/
public static function sudoCommandAsDaemonUser($command)
{
$user = PhabricatorEnv::getEnvConfig('phd.user');
if (!$user) {
// No daemon user is set, so just run this as ourselves.
return $command;
}
// We may reach this method while already running as the daemon user: for
// example, active and passive synchronization of clustered repositories
// run the same commands through the same code, but as different users.
// By default, `sudo` won't let you sudo to yourself, so we can get into
// trouble if we're already running as the daemon user unless the host has
// been configured to let the daemon user run commands as itself.
// Since this is silly and more complicated than doing this check, don't
// use `sudo` if we're already running as the correct user.
if (function_exists('posix_getuid')) {
$uid = posix_getuid();
$info = posix_getpwuid($uid);
if ($info && $info['name'] == $user) {
return $command;
}
}
// Get the absolute path so we're safe against the caller wiping out
// PATH.
$sudo = Filesystem::resolveBinary('sudo');
if (!$sudo) {
throw new Exception(pht("Unable to find 'sudo'!"));
}
// Flags here are:
//
// -E: Preserve the environment.
// -n: Non-interactive. Exit with an error instead of prompting.
// -u: Which user to sudo to.
return csprintf('%s -E -n -u %s -- %C', $sudo, $user, $command);
}
示例2: assertCanGenerateKeypair
public static function assertCanGenerateKeypair()
{
$binary = 'ssh-keygen';
if (!Filesystem::resolveBinary($binary)) {
throw new Exception(pht('Can not generate keys: unable to find "%s" in PATH!', $binary));
}
}
示例3: testResolveBinary
public function testResolveBinary()
{
// Test to make sure resolveBinary() returns the full path to the `which`
// and `where` binaries.
if (phutil_is_windows()) {
$binary = 'where';
} else {
$binary = 'which';
}
$path = Filesystem::resolveBinary($binary);
$this->assertFalse(null === $path);
$this->assertTrue(file_exists($path));
$this->assertFalse(is_dir($path));
$this->assertEqual(null, Filesystem::resolveBinary('halting-problem-decider'));
}
示例4: execPassthru
public function execPassthru($pattern)
{
$args = func_get_args();
static $git = null;
if ($git === null) {
if (phutil_is_windows()) {
// NOTE: On Windows, phutil_passthru() uses 'bypass_shell' because
// everything goes to hell if we don't. We must provide an absolute
// path to Git for this to work properly.
$git = Filesystem::resolveBinary('git');
$git = csprintf('%s', $git);
} else {
$git = 'git';
}
}
$args[0] = $git . ' ' . $args[0];
return call_user_func_array('phutil_passthru', $args);
}
示例5: loadEnvironment
/**
* Determines what executables and test paths to use. Between platforms this
* also changes whether the test engine is run under .NET or Mono. It also
* ensures that all of the required binaries are available for the tests to
* run successfully.
*
* @return void
*/
protected function loadEnvironment()
{
$this->projectRoot = $this->getWorkingCopy()->getProjectRoot();
// Determine build engine.
if (Filesystem::binaryExists('msbuild')) {
$this->buildEngine = 'msbuild';
} else {
if (Filesystem::binaryExists('xbuild')) {
$this->buildEngine = 'xbuild';
} else {
throw new Exception('Unable to find msbuild or xbuild in PATH!');
}
}
// Determine runtime engine (.NET or Mono).
if (phutil_is_windows()) {
$this->runtimeEngine = '';
} else {
if (Filesystem::binaryExists('mono')) {
$this->runtimeEngine = Filesystem::resolveBinary('mono');
} else {
throw new Exception('Unable to find Mono and you are not on Windows!');
}
}
// Read the discovery rules.
$this->discoveryRules = $this->getConfigurationManager()->getConfigFromAnySource('unit.csharp.discovery');
if ($this->discoveryRules === null) {
throw new Exception('You must configure discovery rules to map C# files ' . 'back to test projects (`unit.csharp.discovery` in .arcconfig).');
}
// Determine xUnit test runner path.
if ($this->xunitHintPath === null) {
$this->xunitHintPath = $this->getConfigurationManager()->getConfigFromAnySource('unit.csharp.xunit.binary');
}
$xunit = $this->projectRoot . DIRECTORY_SEPARATOR . $this->xunitHintPath;
if (file_exists($xunit) && $this->xunitHintPath !== null) {
$this->testEngine = Filesystem::resolvePath($xunit);
} else {
if (Filesystem::binaryExists('xunit.console.clr4.exe')) {
$this->testEngine = 'xunit.console.clr4.exe';
} else {
throw new Exception("Unable to locate xUnit console runner. Configure " . "it with the `unit.csharp.xunit.binary' option in .arcconfig");
}
}
}
示例6: sudoCommandAsDaemonUser
/**
* Format a command so it executes as the daemon user, if a daemon user is
* defined. This wraps the provided command in `sudo -u ...`, roughly.
*
* @param PhutilCommandString Command to execute.
* @return PhutilCommandString `sudo` version of the command.
*/
public static function sudoCommandAsDaemonUser($command)
{
$user = PhabricatorEnv::getEnvConfig('phd.user');
if (!$user) {
// No daemon user is set, so just run this as ourselves.
return $command;
}
// Get the absolute path so we're safe against the caller wiping out
// PATH.
$sudo = Filesystem::resolveBinary('sudo');
if (!$sudo) {
throw new Exception(pht("Unable to find 'sudo'!"));
}
// Flags here are:
//
// -E: Preserve the environment.
// -n: Non-interactive. Exit with an error instead of prompting.
// -u: Which user to sudo to.
return csprintf('%s -E -n -u %s -- %C', $sudo, $user, $command);
}
示例7: serveMercurialRequest
private function serveMercurialRequest(PhabricatorRepository $repository, PhabricatorUser $viewer)
{
$request = $this->getRequest();
$bin = Filesystem::resolveBinary('hg');
if (!$bin) {
throw new Exception(pht('Unable to find `%s` in %s!', 'hg', '$PATH'));
}
$env = $this->getCommonEnvironment($viewer);
$input = PhabricatorStartup::getRawInput();
$cmd = $request->getStr('cmd');
$args = $this->getMercurialArguments();
$args = $this->formatMercurialArguments($cmd, $args);
if (strlen($input)) {
$input = strlen($input) . "\n" . $input . "0\n";
}
$command = csprintf('%s serve --stdio', $bin);
$command = PhabricatorDaemon::sudoCommandAsDaemonUser($command);
list($err, $stdout, $stderr) = id(new ExecFuture('%C', $command))->setEnv($env, true)->setCWD($repository->getLocalPath())->write("{$cmd}\n{$args}{$input}")->resolve();
if ($err) {
return new PhabricatorVCSResponse(500, pht('Error %d: %s', $err, $stderr));
}
if ($cmd == 'getbundle' || $cmd == 'changegroup' || $cmd == 'changegroupsubset') {
// We're not completely sure that "changegroup" and "changegroupsubset"
// actually work, they're for very old Mercurial.
$body = gzcompress($stdout);
} else {
if ($cmd == 'unbundle') {
// This includes diagnostic information and anything echoed by commit
// hooks. We ignore `stdout` since it just has protocol garbage, and
// substitute `stderr`.
$body = strlen($stderr) . "\n" . $stderr;
} else {
list($length, $body) = explode("\n", $stdout, 2);
if ($cmd == 'capabilities') {
$body = DiffusionMercurialWireProtocol::filterBundle2Capability($body);
}
}
}
return id(new DiffusionMercurialResponse())->setContent($body);
}
示例8: buildRepositoryStatus
private function buildRepositoryStatus(PhabricatorRepository $repository)
{
$viewer = $this->getRequest()->getUser();
$is_cluster = $repository->getAlmanacServicePHID();
$view = new PHUIStatusListView();
$messages = id(new PhabricatorRepositoryStatusMessage())->loadAllWhere('repositoryID = %d', $repository->getID());
$messages = mpull($messages, null, 'getStatusType');
if ($repository->isTracked()) {
$view->addItem(id(new PHUIStatusItemView())->setIcon(PHUIStatusItemView::ICON_ACCEPT, 'green')->setTarget(pht('Repository Active')));
} else {
$view->addItem(id(new PHUIStatusItemView())->setIcon(PHUIStatusItemView::ICON_WARNING, 'bluegrey')->setTarget(pht('Repository Inactive'))->setNote(pht('Activate this repository to begin or resume import.')));
return $view;
}
$binaries = array();
$svnlook_check = false;
switch ($repository->getVersionControlSystem()) {
case PhabricatorRepositoryType::REPOSITORY_TYPE_GIT:
$binaries[] = 'git';
break;
case PhabricatorRepositoryType::REPOSITORY_TYPE_SVN:
$binaries[] = 'svn';
break;
case PhabricatorRepositoryType::REPOSITORY_TYPE_MERCURIAL:
$binaries[] = 'hg';
break;
}
if ($repository->isHosted()) {
if ($repository->getServeOverHTTP() != PhabricatorRepository::SERVE_OFF) {
switch ($repository->getVersionControlSystem()) {
case PhabricatorRepositoryType::REPOSITORY_TYPE_GIT:
$binaries[] = 'git-http-backend';
break;
case PhabricatorRepositoryType::REPOSITORY_TYPE_SVN:
$binaries[] = 'svnserve';
$binaries[] = 'svnadmin';
$binaries[] = 'svnlook';
$svnlook_check = true;
break;
case PhabricatorRepositoryType::REPOSITORY_TYPE_MERCURIAL:
$binaries[] = 'hg';
break;
}
}
if ($repository->getServeOverSSH() != PhabricatorRepository::SERVE_OFF) {
switch ($repository->getVersionControlSystem()) {
case PhabricatorRepositoryType::REPOSITORY_TYPE_GIT:
$binaries[] = 'git-receive-pack';
$binaries[] = 'git-upload-pack';
break;
case PhabricatorRepositoryType::REPOSITORY_TYPE_SVN:
$binaries[] = 'svnserve';
$binaries[] = 'svnadmin';
$binaries[] = 'svnlook';
$svnlook_check = true;
break;
case PhabricatorRepositoryType::REPOSITORY_TYPE_MERCURIAL:
$binaries[] = 'hg';
break;
}
}
}
$binaries = array_unique($binaries);
if (!$is_cluster) {
// We're only checking for binaries if we aren't running with a cluster
// configuration. In theory, we could check for binaries on the
// repository host machine, but we'd need to make this more complicated
// to do that.
foreach ($binaries as $binary) {
$where = Filesystem::resolveBinary($binary);
if (!$where) {
$view->addItem(id(new PHUIStatusItemView())->setIcon(PHUIStatusItemView::ICON_WARNING, 'red')->setTarget(pht('Missing Binary %s', phutil_tag('tt', array(), $binary)))->setNote(pht("Unable to find this binary in the webserver's PATH. You may " . "need to configure %s.", $this->getEnvConfigLink())));
} else {
$view->addItem(id(new PHUIStatusItemView())->setIcon(PHUIStatusItemView::ICON_ACCEPT, 'green')->setTarget(pht('Found Binary %s', phutil_tag('tt', array(), $binary)))->setNote(phutil_tag('tt', array(), $where)));
}
}
// This gets checked generically above. However, for svn commit hooks, we
// need this to be in environment.append-paths because subversion strips
// PATH.
if ($svnlook_check) {
$where = Filesystem::resolveBinary('svnlook');
if ($where) {
$path = substr($where, 0, strlen($where) - strlen('svnlook'));
$dirs = PhabricatorEnv::getEnvConfig('environment.append-paths');
$in_path = false;
foreach ($dirs as $dir) {
if (Filesystem::isDescendant($path, $dir)) {
$in_path = true;
break;
}
}
if (!$in_path) {
$view->addItem(id(new PHUIStatusItemView())->setIcon(PHUIStatusItemView::ICON_WARNING, 'red')->setTarget(pht('Missing Binary %s', phutil_tag('tt', array(), $binary)))->setNote(pht('Unable to find this binary in `%s`. ' . 'You need to configure %s and include %s.', 'environment.append-paths', $this->getEnvConfigLink(), $path)));
}
}
}
}
$doc_href = PhabricatorEnv::getDocLink('Managing Daemons with phd');
$daemon_instructions = pht('Use %s to start daemons. See %s.', phutil_tag('tt', array(), 'bin/phd start'), phutil_tag('a', array('href' => $doc_href), pht('Managing Daemons with phd')));
$pull_daemon = id(new PhabricatorDaemonLogQuery())->setViewer(PhabricatorUser::getOmnipotentUser())->withStatus(PhabricatorDaemonLogQuery::STATUS_ALIVE)->withDaemonClasses(array('PhabricatorRepositoryPullLocalDaemon'))->setLimit(1)->execute();
if ($pull_daemon) {
//.........这里部分代码省略.........
示例9: installHook
private function installHook($path)
{
$this->log('%s', pht('Installing commit hook to "%s"...', $path));
$repository = $this->getRepository();
$identifier = $this->getHookContextIdentifier($repository);
$root = dirname(phutil_get_library_root('phabricator'));
$bin = $root . '/bin/commit-hook';
$full_php_path = Filesystem::resolveBinary('php');
$cmd = csprintf('exec %s -f %s -- %s "$@"', $full_php_path, $bin, $identifier);
$hook = "#!/bin/sh\nexport TERM=dumb\n{$cmd}\n";
Filesystem::writeFile($path, $hook);
Filesystem::changePermissions($path, 0755);
}