Copyright 2008-2016 Horde LLC (http://www.horde.org/) See the enclosed file COPYING for license information (LGPL). If you did not receive this file, see http://www.horde.org/licenses/lgpl21.
Автор: Anil Madhavapeddy (anil@recoil.org)
Автор: Michael Slusarz (slusarz@horde.org)
Автор: Jan Schneider (jan@horde.org)
Пример #1
1
 /**
  * Constructor.
  *
  * @param Horde_Vcs_Base $rep  A repository object.
  * @param string $dn           Path to the directory.
  * @param array $opts          Any additional options:
  *
  * @throws Horde_Vcs_Exception
  */
 public function __construct(Horde_Vcs_Base $rep, $dn, $opts = array())
 {
     parent::__construct($rep, $dn, $opts);
     $cmd = $rep->getCommand() . ' ls ' . escapeshellarg($rep->sourceroot . $this->_dirName);
     $dir = proc_open($cmd, array(1 => array('pipe', 'w'), 2 => array('pipe', 'w')), $pipes);
     if (!$dir) {
         throw new Horde_Vcs_Exception('Failed to execute svn ls: ' . $cmd);
     }
     if ($error = stream_get_contents($pipes[2])) {
         proc_close($dir);
         throw new Horde_Vcs_Exception($error);
     }
     /* Create two arrays - one of all the files, and the other of all the
      * dirs. */
     $errors = array();
     while (!feof($pipes[1])) {
         $line = chop(fgets($pipes[1], 1024));
         if (!strlen($line)) {
             continue;
         }
         if (substr($line, 0, 4) == 'svn:') {
             $errors[] = $line;
         } elseif (substr($line, -1) == '/') {
             $this->_dirs[] = substr($line, 0, -1);
         } else {
             $this->_files[] = $rep->getFile($this->_dirName . '/' . $line);
         }
     }
     proc_close($dir);
 }
Пример #2
0
 /**
  * Constructor.
  *
  * @param Horde_Vcs_Base $rep  A repository object.
  * @param string $dn           Path to the directory.
  * @param array $opts          Any additional options:
  *
  * @throws Horde_Vcs_Exception
  */
 public function __construct(Horde_Vcs_Base $rep, $dn, $opts = array())
 {
     parent::__construct($rep, $dn, $opts);
     $dir = $rep->sourceroot . $this->_dirName;
     /* Make sure we are trying to list a directory */
     if (!@is_dir($dir)) {
         throw new Horde_Vcs_Exception('Unable to find directory: ' . $dir);
     }
     /* Open the directory for reading its contents */
     if (!($handle = @opendir($dir))) {
         throw new Horde_Vcs_Exception(empty($php_errormsg) ? 'Permission denied' : $php_errormsg);
     }
     /* Create two arrays - one of all the files, and the other of all the
      * directories. */
     while (($name = readdir($handle)) !== false) {
         if ($name == '.' || $name == '..') {
             continue;
         }
         $path = $dir . '/' . $name;
         if (@is_dir($path)) {
             /* Skip Attic directory. */
             if ($name != 'Attic') {
                 $this->_dirs[] = $name;
             }
         } elseif (@is_file($path) && substr($name, -2) == ',v') {
             /* Spawn a new file object to represent this file. */
             $this->_files[] = $rep->getFile(substr($path, strlen($rep->sourceroot), -2));
         }
     }
     /* Close the filehandle; we've now got a list of dirs and files. */
     closedir($handle);
 }
Пример #3
0
 /**
  * Constructor.
  *
  * @todo Throw exception if not a valid directory (ls-tree doesn't really
  *       list directory contents, but all objects matching a pattern, so it
  *       returns an empty list when used with non-existant directories.
  *
  * @param Horde_Vcs_Base $rep  A repository object.
  * @param string $dn           Path to the directory.
  * @param array $opts          Any additional options:
  *                             - 'rev': (string) Generate directory list for
  *                               a certain branch or revision.
  *
  * @throws Horde_Vcs_Exception
  */
 public function __construct(Horde_Vcs_Base $rep, $dn, $opts = array())
 {
     parent::__construct($rep, $dn, $opts);
     $this->_branch = empty($opts['rev']) ? $rep->getDefaultBranch() : $opts['rev'];
     // @TODO See if we have a valid cache of the tree at this revision
     $dir = $this->_dirName;
     if (substr($dir, 0, 1) == '/') {
         $dir = (string) substr($dir, 1);
     }
     if (strlen($dir) && substr($dir, -1) != '/') {
         $dir .= '/';
     }
     list($stream, $result) = $rep->runCommand('ls-tree --full-name ' . escapeshellarg($this->_branch) . ' ' . escapeshellarg($dir));
     $octchr = function ($oct) {
         return chr(octdec($oct[1]));
     };
     /* Create two arrays - one of all the files, and the other of all the
      * dirs. */
     while (!feof($result)) {
         $line = rtrim(fgets($result));
         if (!strlen($line)) {
             continue;
         }
         list(, $type, , $file) = preg_split('/\\s+/', $line, -1, PREG_SPLIT_NO_EMPTY);
         $file = preg_replace_callback('/\\\\(\\d+)/', $octchr, $file);
         $file = str_replace(array('\\t', '\\n', '\\\\'), array("\t", "\n", '\\'), $file);
         $file = trim($file, '"');
         if ($type == 'tree') {
             $this->_dirs[] = basename($file);
         } else {
             $this->_files[] = $rep->getFile($file, array('branch' => $this->_branch));
         }
     }
     fclose($result);
     proc_close($stream);
 }