Differential D20778 Diff 49549 src/applications/diffusion/ssh/DiffusionGitReceivePackSSHWorkflow.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/diffusion/ssh/DiffusionGitReceivePackSSHWorkflow.php
<?php | <?php | ||||
final class DiffusionGitReceivePackSSHWorkflow extends DiffusionGitSSHWorkflow { | final class DiffusionGitReceivePackSSHWorkflow extends DiffusionGitSSHWorkflow { | ||||
protected function didConstruct() { | protected function didConstruct() { | ||||
$this->setName('git-receive-pack'); | $this->setName('git-receive-pack'); | ||||
$this->setArguments( | $this->setArguments( | ||||
array( | array( | ||||
array( | array( | ||||
'name' => 'dir', | 'name' => 'dir', | ||||
'wildcard' => true, | 'wildcard' => true, | ||||
), | ), | ||||
)); | )); | ||||
} | } | ||||
protected function executeRepositoryOperations() { | protected function executeRepositoryOperations() { | ||||
// This is a write, and must have write access. | |||||
$this->requireWriteAccess(); | |||||
$is_proxy = $this->shouldProxy(); | |||||
if ($is_proxy) { | |||||
return $this->executeRepositoryProxyOperations($for_write = true); | |||||
} | |||||
$host_wait_start = microtime(true); | $host_wait_start = microtime(true); | ||||
$repository = $this->getRepository(); | $repository = $this->getRepository(); | ||||
$viewer = $this->getSSHUser(); | $viewer = $this->getSSHUser(); | ||||
$device = AlmanacKeys::getLiveDevice(); | $device = AlmanacKeys::getLiveDevice(); | ||||
// This is a write, and must have write access. | |||||
$this->requireWriteAccess(); | |||||
$cluster_engine = id(new DiffusionRepositoryClusterEngine()) | $cluster_engine = id(new DiffusionRepositoryClusterEngine()) | ||||
->setViewer($viewer) | ->setViewer($viewer) | ||||
->setRepository($repository) | ->setRepository($repository) | ||||
->setLog($this); | ->setLog($this); | ||||
$is_proxy = $this->shouldProxy(); | |||||
if ($is_proxy) { | |||||
$command = $this->getProxyCommand(true); | |||||
$did_write = false; | |||||
if ($device) { | |||||
$this->writeClusterEngineLogMessage( | |||||
pht( | |||||
"# Push received by \"%s\", forwarding to cluster host.\n", | |||||
$device->getName())); | |||||
} | |||||
} else { | |||||
$command = csprintf('git-receive-pack %s', $repository->getLocalPath()); | $command = csprintf('git-receive-pack %s', $repository->getLocalPath()); | ||||
$did_write = true; | |||||
$cluster_engine->synchronizeWorkingCopyBeforeWrite(); | $cluster_engine->synchronizeWorkingCopyBeforeWrite(); | ||||
if ($device) { | if ($device) { | ||||
$this->writeClusterEngineLogMessage( | $this->writeClusterEngineLogMessage( | ||||
pht( | pht( | ||||
"# Ready to receive on cluster host \"%s\".\n", | "# Ready to receive on cluster host \"%s\".\n", | ||||
$device->getName())); | $device->getName())); | ||||
} | } | ||||
} | |||||
$log = $this->newProtocolLog($is_proxy); | $log = $this->newProtocolLog($is_proxy); | ||||
if ($log) { | if ($log) { | ||||
$this->setProtocolLog($log); | $this->setProtocolLog($log); | ||||
$log->didStartSession($command); | $log->didStartSession($command); | ||||
} | } | ||||
$caught = null; | $caught = null; | ||||
try { | try { | ||||
$err = $this->executeRepositoryCommand($command); | $err = $this->executeRepositoryCommand($command); | ||||
} catch (Exception $ex) { | } catch (Exception $ex) { | ||||
$caught = $ex; | $caught = $ex; | ||||
} | } | ||||
if ($log) { | if ($log) { | ||||
$log->didEndSession(); | $log->didEndSession(); | ||||
} | } | ||||
// We've committed the write (or rejected it), so we can release the lock | // We've committed the write (or rejected it), so we can release the lock | ||||
// without waiting for the client to receive the acknowledgement. | // without waiting for the client to receive the acknowledgement. | ||||
if ($did_write) { | |||||
$cluster_engine->synchronizeWorkingCopyAfterWrite(); | $cluster_engine->synchronizeWorkingCopyAfterWrite(); | ||||
} | |||||
if ($caught) { | if ($caught) { | ||||
throw $caught; | throw $caught; | ||||
} | } | ||||
if (!$err) { | if (!$err) { | ||||
$this->waitForGitClient(); | $this->waitForGitClient(); | ||||
// When a repository is clustered, we reach this cleanup code on both | // When a repository is clustered, we reach this cleanup code on both | ||||
// the proxy and the actual final endpoint node. Don't do more cleanup | // the proxy and the actual final endpoint node. Don't do more cleanup | ||||
// or logging than we need to. | // or logging than we need to. | ||||
if ($did_write) { | |||||
$repository->writeStatusMessage( | $repository->writeStatusMessage( | ||||
PhabricatorRepositoryStatusMessage::TYPE_NEEDS_UPDATE, | PhabricatorRepositoryStatusMessage::TYPE_NEEDS_UPDATE, | ||||
PhabricatorRepositoryStatusMessage::CODE_OKAY); | PhabricatorRepositoryStatusMessage::CODE_OKAY); | ||||
$host_wait_end = microtime(true); | $host_wait_end = microtime(true); | ||||
$this->updatePushLogWithTimingInformation( | $this->updatePushLogWithTimingInformation( | ||||
$this->getClusterEngineLogProperty('writeWait'), | $this->getClusterEngineLogProperty('writeWait'), | ||||
$this->getClusterEngineLogProperty('readWait'), | $this->getClusterEngineLogProperty('readWait'), | ||||
($host_wait_end - $host_wait_start)); | ($host_wait_end - $host_wait_start)); | ||||
} | } | ||||
} | |||||
return $err; | return $err; | ||||
} | } | ||||
private function executeRepositoryCommand($command) { | private function executeRepositoryCommand($command) { | ||||
$repository = $this->getRepository(); | $repository = $this->getRepository(); | ||||
$command = PhabricatorDaemon::sudoCommandAsDaemonUser($command); | $command = PhabricatorDaemon::sudoCommandAsDaemonUser($command); | ||||
▲ Show 20 Lines • Show All 43 Lines • Show Last 20 Lines |