1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-22 14:52:41 +01:00

Add separate exception for when the repository clone is unreadable.

Summary: Show a more specific exception when the local clone cannot be read because of permission issues.

Test Plan: Create a repository in an unreadable location and check for the right exception.

Reviewers: epriestley

Reviewed By: epriestley

CC: aran, Korvin

Maniphest Tasks: T2368

Differential Revision: https://secure.phabricator.com/D4868
This commit is contained in:
epriestley 2013-02-11 08:35:00 -08:00
parent 76aee9985a
commit ca0d6aca10
3 changed files with 26 additions and 6 deletions

View file

@ -12,9 +12,7 @@ final class DiffusionGitRequest extends DiffusionRequest {
protected function didInitialize() { protected function didInitialize() {
$repository = $this->getRepository(); $repository = $this->getRepository();
if (!Filesystem::pathExists($repository->getLocalPath())) { $this->validateWorkingCopy($repository->getLocalPath());
$this->raiseCloneException();
}
if (!$this->commit) { if (!$this->commit) {
return; return;

View file

@ -12,9 +12,7 @@ final class DiffusionMercurialRequest extends DiffusionRequest {
protected function didInitialize() { protected function didInitialize() {
$repository = $this->getRepository(); $repository = $this->getRepository();
if (!Filesystem::pathExists($repository->getLocalPath())) { $this->validateWorkingCopy($repository->getLocalPath());
$this->raiseCloneException();
}
// Expand abbreviated hashes to full hashes so "/rXnnnn" (i.e., fewer than // Expand abbreviated hashes to full hashes so "/rXnnnn" (i.e., fewer than
// 40 characters) works correctly. // 40 characters) works correctly.

View file

@ -544,6 +544,30 @@ abstract class DiffusionRequest {
return $result; return $result;
} }
/**
* Check that the working copy of the repository is present and readable.
*
* @param string Path to the working copy.
*/
protected function validateWorkingCopy($path) {
if (!is_readable(dirname($path))) {
$this->raisePermissionException();
}
if (!Filesystem::pathExists($path)) {
$this->raiseCloneException();
}
}
protected function raisePermissionException() {
$host = php_uname('n');
$callsign = $this->getRepository()->getCallsign();
throw new DiffusionSetupException(
"The clone of this repository ('{$callsign}') on the local machine " .
"('{$host}') could not be read. Ensure that the repository is in a " .
"location where the web server has read permissions.");
}
protected function raiseCloneException() { protected function raiseCloneException() {
$host = php_uname('n'); $host = php_uname('n');
$callsign = $this->getRepository()->getCallsign(); $callsign = $this->getRepository()->getCallsign();