public $id;
/**
- * Full path to the git repository
+ * Full path to the .git repository
*
* @var string
*/
- public $repoDir;
+ public $gitDir;
+
+ /**
+ * Full path to the work tree directory
+ *
+ * @var string
+ */
+ public $workDir;
/**
* Load Repository data from GET-Request
throw new Exception_Input('Paste ID not numeric');
}
$this->id = (int)$_GET['id'];
+ $this->loadDirs();
+ }
+
+ protected function loadDirs()
+ {
+ $gitDir = $GLOBALS['phorkie']['cfg']['gitdir'] . '/' . $this->id . '.git';
+ if (!is_dir($gitDir)) {
+ throw new Exception_NotFound(
+ sprintf('Paste %d .git dir not found', $this->id)
+ );
+ }
+ $this->gitDir = $gitDir;
- $repoDir = $GLOBALS['phorkie']['cfg']['repos'] . '/' . $this->id;
- if (!is_dir($repoDir)) {
- throw new Exception_NotFound('Paste not found');
+ $workDir = $GLOBALS['phorkie']['cfg']['workdir'] . '/' . $this->id;
+ if (!is_dir($workDir)) {
+ throw new Exception_NotFound(
+ sprintf('Paste %d work dir not found', $this->id)
+ );
}
- $this->repoDir = $repoDir;
+ $this->workDir = $workDir;
}
public function loadById($id)
throw new Exception_Input('Paste ID not numeric');
}
$this->id = (int)$id;
-
- $repoDir = $GLOBALS['phorkie']['cfg']['repos'] . '/' . $this->id;
- if (!is_dir($repoDir)) {
- throw new Exception_NotFound('Paste not found');
- }
- $this->repoDir = $repoDir;
+ $this->loadDirs();
}
public function getVc()
{
- return new \VersionControl_Git($this->repoDir);
+ return new \VersionControl_Git($this->gitDir);
}
/**
*/
public function getFiles()
{
- $files = glob($this->repoDir . '/*');
+ $files = glob($this->workDir . '/*');
$arFiles = array();
foreach ($files as $path) {
$arFiles[] = new File($path, $this);
if ($name == '') {
throw new Exception_Input('Empty file name given');
}
- $path = $this->repoDir . '/' . $base;
+ $path = $this->workDir . '/' . $base;
if ($bHasToExist && !is_readable($path)) {
throw new Exception_Input('File does not exist');
}
*/
public function delete()
{
- return Tools::recursiveDelete($this->repoDir);
+ return Tools::recursiveDelete($this->workDir)
+ && Tools::recursiveDelete($this->gitDir);
}
public function getDescription()
{
- if (!is_readable($this->repoDir . '/.git/description')) {
+ if (!is_readable($this->gitDir . '/description')) {
return null;
}
- return file_get_contents($this->repoDir . '/.git/description');
+ return file_get_contents($this->gitDir . '/description');
}
public function setDescription($description)
{
- file_put_contents($this->repoDir . '/.git/description', $description);
+ file_put_contents($this->gitDir . '/description', $description);
}
/**
throw new Exception('Unknown link type');
}
+ public function getCloneURL($public = true)
+ {
+ $var = $public ? 'public' : 'private';
+ if (isset($GLOBALS['phorkie']['cfg']['git'][$var])) {
+ return $GLOBALS['phorkie']['cfg']['git'][$var] . $this->id . '/.git';
+ }
+ return null;
+ }
}
?>