/**
  * Deletes the file from local disk, if it exists.
  * @task impl
  */
 public function deleteFile($handle)
 {
     $path = $this->getLocalDiskFileStorageFullPath($handle);
     if (Filesystem::pathExists($path)) {
         Filesystem::remove($path);
     }
 }
 public function execute(PhutilArgumentParser $args)
 {
     $console = PhutilConsole::getConsole();
     $public_keyfile = $args->getArg('public');
     if (!strlen($public_keyfile)) {
         throw new PhutilArgumentUsageException(pht('You must specify the path to a public keyfile with %s.', '--public'));
     }
     if (!Filesystem::pathExists($public_keyfile)) {
         throw new PhutilArgumentUsageException(pht('Specified public keyfile "%s" does not exist!', $public_keyfile));
     }
     $public_key = Filesystem::readFile($public_keyfile);
     $pkcs8_keyfile = $args->getArg('pkcs8');
     if (!strlen($pkcs8_keyfile)) {
         throw new PhutilArgumentUsageException(pht('You must specify the path to a pkcs8 keyfile with %s.', '--pkc8s'));
     }
     if (!Filesystem::pathExists($pkcs8_keyfile)) {
         throw new PhutilArgumentUsageException(pht('Specified pkcs8 keyfile "%s" does not exist!', $pkcs8_keyfile));
     }
     $pkcs8_key = Filesystem::readFile($pkcs8_keyfile);
     $warning = pht('Adding a PKCS8 keyfile to the cache can be very dangerous. If the ' . 'PKCS8 file really encodes a different public key than the one ' . 'specified, an attacker could use it to gain unauthorized access.' . "\n\n" . 'Generally, you should use this option only in a development ' . 'environment where ssh-keygen is broken and it is inconvenient to ' . 'fix it, and only if you are certain you understand the risks. You ' . 'should never cache a PKCS8 file you did not generate yourself.');
     $console->writeOut("%s\n", phutil_console_wrap($warning));
     $prompt = pht('Really trust this PKCS8 keyfile?');
     if (!phutil_console_confirm($prompt)) {
         throw new PhutilArgumentUsageException(pht('Aborted workflow.'));
     }
     $key = PhabricatorAuthSSHPublicKey::newFromRawKey($public_key);
     $key->forcePopulatePKCS8Cache($pkcs8_key);
     $console->writeOut("%s\n", pht('Cached PKCS8 key for public key.'));
     return 0;
 }
Exemplo n.º 3
0
 public function run()
 {
     $roots = array();
     $roots['libphutil'] = dirname(phutil_get_library_root('phutil'));
     $roots['arcanist'] = dirname(phutil_get_library_root('arcanist'));
     foreach ($roots as $lib => $root) {
         echo "Upgrading {$lib}...\n";
         if (!Filesystem::pathExists($root . '/.git')) {
             throw new ArcanistUsageException("{$lib} must be in its git working copy to be automatically " . "upgraded. This copy of {$lib} (in '{$root}') is not in a git " . "working copy.");
         }
         $working_copy = ArcanistWorkingCopyIdentity::newFromPath($root);
         $repository_api = ArcanistRepositoryAPI::newAPIFromWorkingCopyIdentity($working_copy);
         // Force the range to HEAD^..HEAD, which is meaningless but keeps us
         // from triggering "base" rules or other commit range resolution rules
         // that might prompt the user when we pull the working copy status.
         $repository_api->setRelativeCommit('HEAD^');
         $this->setRepositoryAPI($repository_api);
         // Require no local changes.
         $this->requireCleanWorkingCopy();
         // Require the library be on master.
         $branch_name = $repository_api->getBranchName();
         if ($branch_name != 'master') {
             throw new ArcanistUsageException("{$lib} must be on branch 'master' to be automatically upgraded. " . "This copy of {$lib} (in '{$root}') is on branch '{$branch_name}'.");
         }
         chdir($root);
         try {
             phutil_passthru('git pull --rebase');
         } catch (Exception $ex) {
             phutil_passthru('git rebase --abort');
             throw $ex;
         }
     }
     echo phutil_console_wrap(phutil_console_format("**Updated!** Your copy of arc is now up to date.\n"));
     return 0;
 }
Exemplo n.º 4
0
function phabricator_read_config_file($original_config)
{
    $root = dirname(dirname(__FILE__));
    // Accept either "myconfig" (preferred) or "myconfig.conf.php".
    $config = preg_replace('/\\.conf\\.php$/', '', $original_config);
    $full_config_path = $root . '/conf/' . $config . '.conf.php';
    // Make sure config file errors are reported.
    $old_error_level = error_reporting(E_ALL | E_STRICT);
    $old_display_errors = ini_get('display_errors');
    ini_set('display_errors', 1);
    ob_start();
    $conf = (include $full_config_path);
    $errors = ob_get_clean();
    error_reporting($old_error_level);
    ini_set('display_errors', $old_display_errors);
    if ($conf === false) {
        if (!Filesystem::pathExists($full_config_path)) {
            $files = id(new FileFinder($root . '/conf/'))->withType('f')->withSuffix('conf.php')->withFollowSymlinks(true)->find();
            foreach ($files as $key => $file) {
                $file = trim($file, './');
                $files[$key] = preg_replace('/\\.conf\\.php$/', '', $file);
            }
            $files = "    " . implode("\n    ", $files);
            throw new Exception("CONFIGURATION ERROR\n" . "Config file '{$original_config}' does not exist. Valid config files " . "are:\n\n" . $files);
        }
        throw new Exception("Failed to read config file '{$config}': {$errors}");
    }
    return $conf;
}
 /**
  * @phutil-external-symbol class PhabricatorStartup
  */
 protected function executeChecks()
 {
     $upload_limit = PhabricatorEnv::getEnvConfig('storage.upload-size-limit');
     if (!$upload_limit) {
         $message = pht('The Phabricator file upload limit is not configured. You may only ' . 'be able to upload very small files until you configure it, because ' . 'some PHP default limits are very low (as low as 2MB).');
         $this->newIssue('config.storage.upload-size-limit')->setShortName(pht('Upload Limit'))->setName(pht('Upload Limit Not Yet Configured'))->setMessage($message)->addPhabricatorConfig('storage.upload-size-limit');
     } else {
         $memory_limit = PhabricatorStartup::getOldMemoryLimit();
         if ($memory_limit && (int) $memory_limit > 0) {
             $memory_limit_bytes = phutil_parse_bytes($memory_limit);
             $memory_usage_bytes = memory_get_usage();
             $upload_limit_bytes = phutil_parse_bytes($upload_limit);
             $available_bytes = $memory_limit_bytes - $memory_usage_bytes;
             if ($upload_limit_bytes > $available_bytes) {
                 $summary = pht('Your PHP memory limit is configured in a way that may prevent ' . 'you from uploading large files.');
                 $message = pht('When you upload a file via drag-and-drop or the API, the entire ' . 'file is buffered into memory before being written to permanent ' . 'storage. Phabricator needs memory available to store these ' . 'files while they are uploaded, but PHP is currently configured ' . 'to limit the available memory.' . "\n\n" . 'Your Phabricator %s is currently set to a larger value (%s) than ' . 'the amount of available memory (%s) that a PHP process has ' . 'available to use, so uploads via drag-and-drop and the API will ' . 'hit the memory limit before they hit other limits.' . "\n\n" . '(Note that the application itself must also fit in available ' . 'memory, so not all of the memory under the memory limit is ' . 'available for buffering file uploads.)' . "\n\n" . "The easiest way to resolve this issue is to set %s to %s in your " . "PHP configuration, to disable the memory limit. There is " . "usually little or no value to using this option to limit " . "Phabricator process memory." . "\n\n" . "You can also increase the limit, or decrease %s, or ignore this " . "issue and accept that these upload mechanisms will be limited " . "in the size of files they can handle.", phutil_tag('tt', array(), 'storage.upload-size-limit'), phutil_format_bytes($upload_limit_bytes), phutil_format_bytes($available_bytes), phutil_tag('tt', array(), 'memory_limit'), phutil_tag('tt', array(), '-1'), phutil_tag('tt', array(), 'storage.upload-size-limit'));
                 $this->newIssue('php.memory_limit.upload')->setName(pht('Memory Limit Restricts File Uploads'))->setSummary($summary)->setMessage($message)->addPHPConfig('memory_limit')->addPHPConfigOriginalValue('memory_limit', $memory_limit)->addPhabricatorConfig('storage.upload-size-limit');
             }
         }
     }
     $local_path = PhabricatorEnv::getEnvConfig('storage.local-disk.path');
     if (!$local_path) {
         return;
     }
     if (!Filesystem::pathExists($local_path) || !is_readable($local_path) || !is_writable($local_path)) {
         $message = pht('Configured location for storing uploaded files on disk ("%s") does ' . 'not exist, or is not readable or writable. Verify the directory ' . 'exists and is readable and writable by the webserver.', $local_path);
         $this->newIssue('config.storage.local-disk.path')->setShortName(pht('Local Disk Storage'))->setName(pht('Local Disk Storage Not Readable/Writable'))->setMessage($message)->addPhabricatorConfig('storage.local-disk.path');
     }
 }
 protected function executeChecks()
 {
     $adapter = PhabricatorEnv::getEnvConfig('metamta.mail-adapter');
     switch ($adapter) {
         case 'PhabricatorMailImplementationPHPMailerLiteAdapter':
             if (!Filesystem::pathExists('/usr/bin/sendmail') && !Filesystem::pathExists('/usr/sbin/sendmail')) {
                 $message = pht('Mail is configured to send via sendmail, but this system has ' . 'no sendmail binary. Install sendmail or choose a different ' . 'mail adapter.');
                 $this->newIssue('config.metamta.mail-adapter')->setShortName(pht('Missing Sendmail'))->setName(pht('No Sendmail Binary Found'))->setMessage($message)->addRelatedPhabricatorConfig('metamta.mail-adapter');
             }
             break;
         case 'PhabricatorMailImplementationAmazonSESAdapter':
             if (PhabricatorEnv::getEnvConfig('metamta.can-send-as-user')) {
                 $message = pht('Amazon SES does not support sending email as users. Disable ' . 'send as user, or choose a different mail adapter.');
                 $this->newIssue('config.can-send-as-user')->setName(pht("SES Can't Send As User"))->setMessage($message)->addRelatedPhabricatorConfig('metamta.mail-adapter')->addPhabricatorConfig('metamta.can-send-as-user');
             }
             if (!PhabricatorEnv::getEnvConfig('amazon-ses.access-key')) {
                 $message = pht('Amazon SES is selected as the mail adapter, but no SES access ' . 'key is configured. Provide an SES access key, or choose a ' . 'different mail adapter.');
                 $this->newIssue('config.amazon-ses.access-key')->setName(pht('Amazon SES Access Key Not Set'))->setMessage($message)->addRelatedPhabricatorConfig('metamta.mail-adapter')->addPhabricatorConfig('amazon-ses.access-key');
             }
             if (!PhabricatorEnv::getEnvConfig('amazon-ses.secret-key')) {
                 $message = pht('Amazon SES is selected as the mail adapter, but no SES secret ' . 'key is configured. Provide an SES secret key, or choose a ' . 'different mail adapter.');
                 $this->newIssue('config.amazon-ses.secret-key')->setName(pht('Amazon SES Secret Key Not Set'))->setMessage($message)->addRelatedPhabricatorConfig('metamta.mail-adapter')->addPhabricatorConfig('amazon-ses.secret-key');
             }
             $address_key = 'metamta.default-address';
             $options = PhabricatorApplicationConfigOptions::loadAllOptions();
             $default = $options[$address_key]->getDefault();
             $value = PhabricatorEnv::getEnvConfig($address_key);
             if ($default === $value) {
                 $message = pht('Amazon SES requires verification of the "From" address, but ' . 'you have not configured a "From" address. Configure and verify ' . 'a "From" address, or choose a different mail adapter.');
                 $this->newIssue('config.metamta.default-address')->setName(pht('No SES From Address Configured'))->setMessage($message)->addRelatedPhabricatorConfig('metamta.mail-adapter')->addPhabricatorConfig('metamta.default-address');
             }
             break;
     }
 }
 public function run()
 {
     $roots = array();
     $roots['libphutil'] = dirname(phutil_get_library_root('phutil'));
     $roots['arcanist'] = dirname(phutil_get_library_root('arcanist'));
     foreach ($roots as $lib => $root) {
         echo "Upgrading {$lib}...\n";
         if (!Filesystem::pathExists($root . '/.git')) {
             throw new ArcanistUsageException("{$lib} must be in its git working copy to be automatically " . "upgraded. This copy of {$lib} (in '{$root}') is not in a git " . "working copy.");
         }
         $working_copy = ArcanistWorkingCopyIdentity::newFromPath($root);
         $configuration_manager = clone $this->getConfigurationManager();
         $configuration_manager->setWorkingCopyIdentity($working_copy);
         $repository_api = ArcanistRepositoryAPI::newAPIFromConfigurationManager($configuration_manager);
         $this->setRepositoryAPI($repository_api);
         // Require no local changes.
         $this->requireCleanWorkingCopy();
         // Require the library be on master.
         $branch_name = $repository_api->getBranchName();
         if ($branch_name != 'master') {
             throw new ArcanistUsageException("{$lib} must be on branch 'master' to be automatically upgraded. " . "This copy of {$lib} (in '{$root}') is on branch '{$branch_name}'.");
         }
         chdir($root);
         try {
             phutil_passthru('git pull --rebase');
         } catch (Exception $ex) {
             phutil_passthru('git rebase --abort');
             throw $ex;
         }
     }
     echo phutil_console_wrap(phutil_console_format("**Updated!** Your copy of arc is now up to date.\n"));
     return 0;
 }
 private static function loadSkinSpecification($path)
 {
     $config_path = $path . DIRECTORY_SEPARATOR . 'skin.json';
     $config = array();
     if (Filesystem::pathExists($config_path)) {
         $config = Filesystem::readFile($config_path);
         try {
             $config = phutil_json_decode($config);
         } catch (PhutilJSONParserException $ex) {
             throw new PhutilProxyException(pht("Skin configuration file '%s' is not a valid JSON file.", $config_path), $ex);
         }
         $type = idx($config, 'type', self::TYPE_BASIC);
     } else {
         $type = self::TYPE_BASIC;
     }
     $spec = new PhameSkinSpecification();
     $spec->setRootDirectory($path);
     $spec->setConfig($config);
     switch ($type) {
         case self::TYPE_BASIC:
             $spec->setSkinClass('PhameBasicTemplateBlogSkin');
             break;
         case self::TYPE_ADVANCED:
             $spec->setSkinClass($config['class']);
             $spec->addPhutilLibrary($path . DIRECTORY_SEPARATOR . 'src');
             break;
         default:
             throw new Exception(pht('Unknown skin type!'));
     }
     $spec->setType($type);
     return $spec;
 }
Exemplo n.º 9
0
 public function run()
 {
     $roots = array('libphutil' => dirname(phutil_get_library_root('phutil')), 'arcanist' => dirname(phutil_get_library_root('arcanist')));
     foreach ($roots as $lib => $root) {
         echo phutil_console_format("%s\n", pht('Upgrading %s...', $lib));
         $working_copy = ArcanistWorkingCopyIdentity::newFromPath($root);
         $configuration_manager = clone $this->getConfigurationManager();
         $configuration_manager->setWorkingCopyIdentity($working_copy);
         $repository = ArcanistRepositoryAPI::newAPIFromConfigurationManager($configuration_manager);
         if (!Filesystem::pathExists($repository->getMetadataPath())) {
             throw new ArcanistUsageException(pht("%s must be in its git working copy to be automatically upgraded. " . "This copy of %s (in '%s') is not in a git working copy.", $lib, $lib, $root));
         }
         $this->setRepositoryAPI($repository);
         // Require no local changes.
         $this->requireCleanWorkingCopy();
         // Require the library be on master.
         $branch_name = $repository->getBranchName();
         if ($branch_name != 'master') {
             throw new ArcanistUsageException(pht("%s must be on branch '%s' to be automatically upgraded. " . "This copy of %s (in '%s') is on branch '%s'.", $lib, 'master', $lib, $root, $branch_name));
         }
         chdir($root);
         try {
             phutil_passthru('git pull --rebase');
         } catch (Exception $ex) {
             phutil_passthru('git rebase --abort');
             throw $ex;
         }
     }
     echo phutil_console_format("**%s** %s\n", pht('Updated!'), pht('Your copy of arc is now up to date.'));
     return 0;
 }
 protected function buildBareRepository($callsign)
 {
     $existing_repository = id(new PhabricatorRepositoryQuery())->withCallsigns(array($callsign))->setViewer(PhabricatorUser::getOmnipotentUser())->executeOne();
     if ($existing_repository) {
         $existing_repository->delete();
     }
     $data_dir = dirname(__FILE__) . '/data/';
     $types = array('svn' => PhabricatorRepositoryType::REPOSITORY_TYPE_SVN, 'hg' => PhabricatorRepositoryType::REPOSITORY_TYPE_MERCURIAL, 'git' => PhabricatorRepositoryType::REPOSITORY_TYPE_GIT);
     $hits = array();
     foreach ($types as $type => $const) {
         $path = $data_dir . $callsign . '.' . $type . '.tgz';
         if (Filesystem::pathExists($path)) {
             $hits[$const] = $path;
         }
     }
     if (!$hits) {
         throw new Exception("No test data for callsign '{$callsign}'. Expected an archive " . "like '{$callsign}.git.tgz' in '{$data_dir}'.");
     }
     if (count($hits) > 1) {
         throw new Exception("Expected exactly one archive matching callsign '{$callsign}', " . "found too many: " . implode(', ', $hits));
     }
     $path = head($hits);
     $vcs_type = head_key($hits);
     $dir = PhutilDirectoryFixture::newFromArchive($path);
     $local = new TempFile('.ignore');
     $user = $this->generateNewTestUser();
     $repo = PhabricatorRepository::initializeNewRepository($user)->setCallsign($callsign)->setName(pht('Test Repo "%s"', $callsign))->setVersionControlSystem($vcs_type)->setDetail('local-path', dirname($local) . '/' . $callsign)->setDetail('remote-uri', 'file://' . $dir->getPath() . '/');
     $this->didConstructRepository($repo);
     $repo->save();
     $repo->makeEphemeral();
     // Keep the disk resources around until we exit.
     $this->dirs[] = $dir;
     $this->dirs[] = $local;
     return $repo;
 }
Exemplo n.º 11
0
 protected function getProxyCommand()
 {
     $uri = new PhutilURI($this->proxyURI);
     $username = AlmanacKeys::getClusterSSHUser();
     if ($username === null) {
         throw new Exception(pht('Unable to determine the username to connect with when trying ' . 'to proxy an SSH request within the Phabricator cluster.'));
     }
     $port = $uri->getPort();
     $host = $uri->getDomain();
     $key_path = AlmanacKeys::getKeyPath('device.key');
     if (!Filesystem::pathExists($key_path)) {
         throw new Exception(pht('Unable to proxy this SSH request within the cluster: this device ' . 'is not registered and has a missing device key (expected to ' . 'find key at "%s").', $key_path));
     }
     $options = array();
     $options[] = '-o';
     $options[] = 'StrictHostKeyChecking=no';
     $options[] = '-o';
     $options[] = 'UserKnownHostsFile=/dev/null';
     // This is suppressing "added <address> to the list of known hosts"
     // messages, which are confusing and irrelevant when they arise from
     // proxied requests. It might also be suppressing lots of useful errors,
     // of course. Ideally, we would enforce host keys eventually.
     $options[] = '-o';
     $options[] = 'LogLevel=quiet';
     // NOTE: We prefix the command with "@username", which the far end of the
     // connection will parse in order to act as the specified user. This
     // behavior is only available to cluster requests signed by a trusted
     // device key.
     return csprintf('ssh %Ls -l %s -i %s -p %s %s -- %s %Ls', $options, $username, $key_path, $port, $host, '@' . $this->getUser()->getUsername(), $this->getOriginalArguments());
 }
 public final function run()
 {
     $repository = $this->loadRepository();
     $expected_type = $this->getSupportedRepositoryType();
     $repo_type = $repository->getVersionControlSystem();
     if ($repo_type != $expected_type) {
         $repo_type_name = PhabricatorRepositoryType::getNameForRepositoryType($repo_type);
         $expected_type_name = PhabricatorRepositoryType::getNameForRepositoryType($expected_type);
         $repo_name = $repository->getName() . ' (' . $repository->getCallsign() . ')';
         throw new Exception("This daemon pulls '{$expected_type_name}' repositories, but the " . "repository '{$repo_name}' is a '{$repo_type_name}' repository.");
     }
     $tracked = $repository->isTracked();
     if (!$tracked) {
         throw new Exception("Tracking is not enabled for this repository.");
     }
     $local_path = $repository->getDetail('local-path');
     if (!$local_path) {
         throw new Exception("No local path is available for this repository.");
     }
     while (true) {
         if (!Filesystem::pathExists($local_path)) {
             execx('mkdir -p %s', dirname($local_path));
             $this->executeCreate($repository, $local_path);
         } else {
             $this->executeUpdate($repository, $local_path);
         }
         $this->sleep($repository->getDetail('pull-frequency', 15));
     }
 }
 public function testSVNPullBasic()
 {
     $repo = $this->buildPulledRepository('ST');
     // We don't pull local clones for SVN, so we don't expect there to be
     // a working copy.
     $this->assertFalse(Filesystem::pathExists($repo->getLocalPath()));
 }
 public function run()
 {
     $repository = $this->loadRepository();
     if ($repository->getVersionControlSystem() != 'git') {
         throw new Exception("Not a git repository!");
     }
     $tracked = $repository->getDetail('tracking-enabled');
     if (!$tracked) {
         throw new Exception("Tracking is not enabled for this repository.");
     }
     $local_path = $repository->getDetail('local-path');
     $remote_uri = $repository->getDetail('remote-uri');
     if (!$local_path) {
         throw new Exception("No local path is available for this repository.");
     }
     while (true) {
         if (!Filesystem::pathExists($local_path)) {
             if (!$remote_uri) {
                 throw new Exception("No remote URI is available.");
             }
             execx('mkdir -p %s', dirname($local_path));
             execx('git clone %s %s', $remote_uri, rtrim($local_path, '/'));
         } else {
             execx('(cd %s && git fetch --all)', $local_path);
         }
         $this->sleep($repository->getDetail('pull-frequency', 15));
     }
 }
Exemplo n.º 15
0
 public function getPEP8Path()
 {
     $working_copy = $this->getEngine()->getWorkingCopy();
     $prefix = $working_copy->getConfig('lint.pep8.prefix');
     $bin = $working_copy->getConfig('lint.pep8.bin');
     if ($bin === null && $prefix === null) {
         $bin = csprintf('/usr/bin/env python2.6 %s', phutil_get_library_root('arcanist') . '/../externals/pep8/pep8.py');
     } else {
         if ($bin === null) {
             $bin = 'pep8';
         }
         if ($prefix !== null) {
             if (!Filesystem::pathExists($prefix . '/' . $bin)) {
                 throw new ArcanistUsageException("Unable to find PEP8 binary in a specified directory. Make sure " . "that 'lint.pep8.prefix' and 'lint.pep8.bin' keys are set " . "correctly. If you'd rather use a copy of PEP8 installed " . "globally, you can just remove these keys from your .arcconfig");
             }
             $bin = csprintf("%s/%s", $prefix, $bin);
             return $bin;
         }
         // Look for globally installed PEP8
         list($err) = exec_manual('which %s', $bin);
         if ($err) {
             throw new ArcanistUsageException("PEP8 does not appear to be installed on this system. Install it " . "(e.g., with 'easy_install pep8') or configure " . "'lint.pep8.prefix' in your .arcconfig to point to the directory " . "where it resides.");
         }
     }
     return $bin;
 }
 public function testParseRender()
 {
     $dir = dirname(__FILE__) . '/data/';
     foreach (Filesystem::listDirectory($dir, $show_hidden = false) as $file) {
         if (!preg_match('/\\.diff$/', $file)) {
             continue;
         }
         $data = Filesystem::readFile($dir . $file);
         $opt_file = $dir . $file . '.options';
         if (Filesystem::pathExists($opt_file)) {
             $options = Filesystem::readFile($opt_file);
             $options = json_decode($options, true);
             if (!is_array($options)) {
                 throw new Exception("Invalid options file: {$opt_file}.");
             }
         } else {
             $options = array();
         }
         foreach (array('one', 'two') as $type) {
             $parser = $this->buildChangesetParser($type, $data, $file);
             $actual = $parser->render(null, null, array());
             $expect = Filesystem::readFile($dir . $file . '.' . $type . '.expect');
             $this->assertEqual($expect, (string) $actual, $file . '.' . $type);
         }
     }
 }
 /**
  * Deletes the file from local disk, if it exists.
  * @task impl
  */
 public function deleteFile($handle)
 {
     $path = $this->getLocalDiskFileStorageFullPath($handle);
     if (Filesystem::pathExists($path)) {
         AphrontWriteGuard::willWrite();
         Filesystem::remove($path);
     }
 }
 public final function getPID()
 {
     $pid = null;
     if (Filesystem::pathExists($this->getPIDPath())) {
         $pid = (int) Filesystem::readFile($this->getPIDPath());
     }
     return $pid;
 }
 protected function didInitialize()
 {
     $repository = $this->getRepository();
     if (!Filesystem::pathExists($repository->getLocalPath())) {
         $this->raiseCloneException();
     }
     return;
 }
Exemplo n.º 20
0
 public static function getDeviceID()
 {
     $device_id_path = self::getKeyPath('device.id');
     if (Filesystem::pathExists($device_id_path)) {
         return trim(Filesystem::readFile($device_id_path));
     }
     return null;
 }
 public function getCacheVersion()
 {
     $version = '2';
     $path = xhpast_get_binary_path();
     if (Filesystem::pathExists($path)) {
         $version .= '-' . md5_file($path);
     }
     return $version;
 }
Exemplo n.º 22
0
function phutil_get_library_root_for_path($path)
{
    foreach (Filesystem::walkToRoot($path) as $dir) {
        if (Filesystem::pathExists($dir . '/__phutil_library_init__.php')) {
            return $dir;
        }
    }
    return null;
}
 public final function getCacheVersion()
 {
     $parts = array();
     $parts[] = $this->getVersion();
     $path = xhpast_get_binary_path();
     if (Filesystem::pathExists($path)) {
         $parts[] = md5_file($path);
     }
     return implode('-', $parts);
 }
 private function getControlDirectory($path)
 {
     if (!Filesystem::pathExists($path)) {
         list($err) = exec_manual('mkdir -p %s', $path);
         if ($err) {
             throw new Exception(pht("%s requires the directory '%s' to exist, but it does not exist " . "and could not be created. Create this directory or update " . "'%s' / '%s' in your configuration to point to an existing " . "directory.", 'phd', $path, 'phd.pid-directory', 'phd.log-directory'));
         }
     }
     return $path;
 }
 private function getControlDirectory($path)
 {
     if (!Filesystem::pathExists($path)) {
         list($err) = exec_manual('mkdir -p %s', $path);
         if ($err) {
             throw new Exception("phd requires the directory '{$path}' to exist, but it does not " . "exist and could not be created. Create this directory or update " . "'phd.pid-directory' / 'phd.log-directory' in your configuration " . "to point to an existing directory.");
         }
     }
     return $path;
 }
 public function translateResourceURI(array $matches)
 {
     $uri = trim($matches[1], "'\" \r\t\n");
     if (Filesystem::pathExists($this->root . $uri)) {
         $hash = filemtime($this->root . $uri);
     } else {
         $hash = '-';
     }
     $uri = '/phame/r/' . $this->id . '/' . $hash . '/' . $uri;
     return 'url(' . $uri . ')';
 }
 protected function execute(ConduitAPIRequest $request)
 {
     $path = xhpast_get_binary_path();
     if (!Filesystem::pathExists($path)) {
         throw new ConduitException('ERR-NOT-FOUND');
     }
     list($err, $stdout) = exec_manual('%s --version', $path);
     if ($err) {
         throw new ConduitException('ERR-COMMAND-FAILED');
     }
     return trim($stdout);
 }
 private function renderTemplate($__template__, array $__scope__)
 {
     chdir($this->getPath());
     ob_start();
     if (Filesystem::pathExists($this->getPath($__template__))) {
         // Fool lint.
         $__evil__ = 'extract';
         $__evil__($__scope__ + $this->getDefaultScope());
         require $this->getPath($__template__);
     }
     return phutil_safe_html(ob_get_clean());
 }
Exemplo n.º 29
0
 public function buildLinters()
 {
     $linters = array();
     $paths = $this->getPaths();
     // Remove all deleted files, which are not checked by the
     // following linters.
     foreach ($paths as $key => $path) {
         if (!Filesystem::pathExists($this->getFilePathOnDisk($path))) {
             unset($paths[$key]);
         } else {
             foreach (static::$IGNORED_PATH_PATTERNS as $pattern) {
                 if (preg_match($pattern, $path)) {
                     unset($paths[$key]);
                     break;
                 }
             }
         }
     }
     $generated_linter = new ArcanistGeneratedLinter();
     $linters[] = $generated_linter;
     $nolint_linter = new ArcanistNoLintLinter();
     $linters[] = $nolint_linter;
     $license_linter = new WatchmanLicenseLinter();
     $linters[] = $license_linter;
     $text_linter = new ArcanistTextLinter();
     $text_linter->setCustomSeverityMap(array(ArcanistTextLinter::LINT_LINE_WRAP => ArcanistLintSeverity::SEVERITY_ADVICE));
     $linters[] = $text_linter;
     $spelling_linter = new ArcanistSpellingLinter();
     $linters[] = $spelling_linter;
     foreach ($paths as $path) {
         if (preg_match('/\\.(c|php|markdown|h)$/', $path)) {
             $nolint_linter->addPath($path);
             $generated_linter->addPath($path);
             $generated_linter->addData($path, $this->loadData($path));
             $text_linter->addPath($path);
             $text_linter->addData($path, $this->loadData($path));
             $spelling_linter->addPath($path);
             $spelling_linter->addData($path, $this->loadData($path));
         }
         if (preg_match('/\\.(c|h|php)$/', $path)) {
             $license_linter->addPath($path);
             $license_linter->addData($path, $this->loadData($path));
         }
     }
     $name_linter = new ArcanistFilenameLinter();
     $linters[] = $name_linter;
     foreach ($paths as $path) {
         $name_linter->addPath($path);
     }
     return $linters;
 }
 protected function executeChecks()
 {
     $repo_path = PhabricatorEnv::getEnvConfig('repository.default-local-path');
     if (!$repo_path) {
         $summary = pht("The configuration option '%s' is not set.", 'repository.default-local-path');
         $this->newIssue('repository.default-local-path.empty')->setName(pht('Missing Repository Local Path'))->setSummary($summary)->addPhabricatorConfig('repository.default-local-path');
         return;
     }
     if (!Filesystem::pathExists($repo_path)) {
         $summary = pht('The path for local repositories does not exist, or is not ' . 'readable by the webserver.');
         $message = pht("The directory for local repositories (%s) does not exist, or is not " . "readable by the webserver. Phabricator uses this directory to store " . "information about repositories. If this directory does not exist, " . "create it:\n\n" . "%s\n" . "If this directory exists, make it readable to the webserver. You " . "can also edit the configuration below to use some other directory.", phutil_tag('tt', array(), $repo_path), phutil_tag('pre', array(), csprintf('$ mkdir -p %s', $repo_path)));
         $this->newIssue('repository.default-local-path.empty')->setName(pht('Missing Repository Local Path'))->setSummary($summary)->setMessage($message)->addPhabricatorConfig('repository.default-local-path');
     }
 }