[ Index ]
 

Code source de Horde 3.1.3

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/lib/Horde/VC/ -> rcs.php (source)

   1  <?php
   2  /**
   3   * VC_rcs implementation.
   4   *
   5   * Copyright 2004-2006 Jeff Schwentner <jeffrey.schwentner@lmco.com>
   6   *
   7   * $Horde: framework/VC/VC/rcs.php,v 1.3.8.5 2006/01/01 21:28:42 jan Exp $
   8   *
   9   * @author  Jeff Schwentner <jeffrey.schwentner@lmco.com>
  10   * @author  Chuck Hagenbuch <chuck@horde.org>
  11   * @package VC
  12   */
  13  class VC_rcs extends VC {
  14  
  15      /**
  16       * Checks an RCS file in with a specified change log.
  17       *
  18       * @param string $filepath    Location of file to check in.
  19       * @param string $message     Log of changes since last version.
  20       * @param string $user        The user name to use for the check in.
  21       * @param boolean $newBinary  Does the change involve binary data?
  22       *
  23       * @return string|object  The new revision number on success, or a
  24       *                        PEAR_Error object on failure.
  25       */
  26      function ci($filepath, $message, $user = null, $newBinary = false)
  27      {
  28          if ($user) {
  29              putenv('LOGNAME=' . $user);
  30          } else {
  31              putenv('LOGNAME=guest');
  32          }
  33  
  34          $Q = VC_WINDOWS ? '"' : "'" ;
  35  
  36          $ci_cmd = $this->getPath('ci') . ' ' . $Q . $filepath . $Q.' 2>&1';
  37          $rcs_cmd = $this->getPath('rcs') . ' -i -kb ' . $Q . $filepath . $Q.' 2>&1';
  38          $output = '';
  39  
  40          $message_lines = explode("\n", $message);
  41  
  42          $pipe_def = array(0 => array("pipe", 'r'),
  43                            1 => array("pipe", 'w'));
  44  
  45          if ($newBinary) {
  46              $process = proc_open($rcs_cmd, $pipe_def, $pipes);
  47          } else {
  48              $process = proc_open($ci_cmd, $pipe_def, $pipes);
  49          }
  50  
  51          if (is_resource($process)) {
  52              foreach ($message_lines as $line) {
  53                  if ($line == '.\n') {
  54                      $line = '. \n';
  55                  }
  56                  fwrite($pipes[0], $line);
  57              }
  58  
  59              fwrite($pipes[0], "\n.\n");
  60              fclose($pipes[0]);
  61  
  62              while (!feof($pipes[1])) {
  63                  $output .= fread($pipes[1], 8192);
  64              }
  65              fclose($pipes[1]);
  66              proc_close($process);
  67          } else {
  68              return PEAR::raiseError('Failed to open pipe in ci()');
  69          }
  70  
  71          if ($newBinary) {
  72              exec($ci_cmd . ' 2>&1', $return_array, $retval);
  73  
  74              if ($retval) {
  75                  return PEAR::raiseError("Unable to spawn ci on $filepath from ci()");
  76              } else {
  77                  foreach ($return_array as $line) {
  78                      $output .= $line;
  79                  }
  80              }
  81          }
  82  
  83          $rev_start = strpos($output, 'new revision: ');
  84  
  85          // If no new revision, see if this is an initial checkin.
  86          if ($rev_start === false) {
  87              $rev_start = strpos($output, 'initial revision: ');
  88              $rev_end = strpos($output, ' ', $rev_start);
  89          } else {
  90              $rev_end = strpos($output, ';', $rev_start);
  91          }
  92  
  93          if ($rev_start !== false && $rev_end !== false) {
  94              $rev_start += 14;
  95              return substr($output, $rev_start, $rev_end - $rev_start);
  96          } else {
  97              unlock($filepath);
  98              $temp_pos = strpos($output, 'file is unchanged');
  99              if ($temp_pos !== false) {
 100                  return PEAR::raiseError('Check-in Failure: ' . basename($filepath) . ' has not been modified');
 101              } else {
 102                  return PEAR::raiseError("Failed to checkin $filepath, $ci_cmd, $output");
 103              }
 104          }
 105      }
 106  
 107      /**
 108       * Checks the locks on a CVS/RCS file.
 109       *
 110       * @param string $filepath    Location of file.
 111       * @param string &$locked_by  Returns the username holding the lock.
 112       *
 113       * @return boolean|object  True on success, or a PEAR_Error on failure.
 114       */
 115      function isLocked($filepath, &$locked_by)
 116      {
 117          $rlog_cmd  = $this->getPath('rlog');
 118          $rlog_flag = ' -L ';
 119  
 120          $Q = VC_WINDOWS ? '"' : "'";
 121  
 122          $cmd = $rlog_cmd . $rlog_flag . $Q . $filepath . $Q;
 123  
 124          exec($cmd.' 2>&1', $return_array, $retval);
 125  
 126          if ($retval) {
 127              return PEAR::raiseError("Unable to spawn rlog on $filepath from isLocked()");
 128          } else {
 129              $output = '';
 130  
 131              foreach ($return_array as $line) {
 132                  $output .= $line;
 133              }
 134  
 135              $start_name = strpos($output, 'locked by: ');
 136              $end_name = strpos($output, ';', $start_name);
 137  
 138              if ($start_name !== false && $end_name !== false) {
 139                  $start_name += 11;
 140                  $locked_by = substr($output, $start_name, $end_name - $start_name);
 141                  return true;
 142              }  elseif (strlen($output) == 0) {
 143                  return false;
 144              } else {
 145                  return PEAR::raiseError('Failure running rlog in isLocked()');
 146              }
 147          }
 148      }
 149  
 150      /**
 151       * Locks a CVS/RCS file.
 152       *
 153       * @param string $filepath  Location of file.
 154       * @param string $user      User name to lock the file with
 155       *
 156       * @return boolean|object  True on success, or a PEAR_Error on failure.
 157       */
 158      function lock($filepath, $user = null)
 159      {
 160          // Get username for RCS tag.
 161          if ($user) {
 162              putenv('LOGNAME=' . $user);
 163          } else {
 164              putenv('LOGNAME=guest');
 165          }
 166  
 167          $rcs_cmd = $this->getPath('rcs');
 168          $rcs_flag = ' -l ';
 169  
 170          $Q = VC_WINDOWS ? '"' : "'" ;
 171          $cmd = $rcs_cmd . $rcs_flag . $Q . $filepath . $Q;
 172          exec($cmd.' 2>&1', $return_array, $retval);
 173  
 174          if ($retval) {
 175              return PEAR::raiseError('Failed to spawn rcs ("' . $cmd . '") on "' . $filepath . '" (returned ' . $retval . ')');
 176          } else {
 177              $output = '';
 178              foreach ($return_array as $line) {
 179                  $output .= $line;
 180              }
 181  
 182              $locked_pos = strpos($output, 'locked');
 183              if ($locked_pos !== false) {
 184                  return true;
 185              } else {
 186                  return PEAR::raiseError('Failed to lock "' . $filepath . '" (Ran "' . $cmd . '", got return code ' . $retval . ', output: ' . $output . ')');
 187              }
 188          }
 189      }
 190  
 191      /**
 192       * Unlocks a CVS/RCS file.
 193       *
 194       * @param string $filepath  Location of file.
 195       * @param string $user      User name to unlock the file with
 196       *
 197       * @return boolean|object  True on success, or a PEAR_Error on failure.
 198       */
 199      function unlock($filepath, $user = null)
 200      {
 201          // Get username for RCS tag.
 202          if ($user) {
 203              putenv('LOGNAME=' . $user);
 204          } else {
 205              putenv('LOGNAME=guest');
 206          }
 207  
 208          $rcs_cmd = $this->getPath('rcs');
 209          $rcs_flag = ' -u ';
 210  
 211          $Q = VC_WINDOWS ? '"' : "'" ;
 212          $cmd = $rcs_cmd . $rcs_flag . $Q . $filepath . $Q;
 213          exec($cmd . ' 2>&1', $return_array, $retval);
 214  
 215          if ($retval) {
 216              return PEAR::raiseError('Failed to spawn rcs ("' . $cmd . '") on "' . $filepath . '" (returned ' . $retval . ')');
 217          } else {
 218              $output = '';
 219  
 220              foreach ($return_array as $line) {
 221                  $output .= $line;
 222              }
 223  
 224              $unlocked_pos = strpos($output, 'unlocked');
 225  
 226              if ($unlocked_pos !== false) {
 227                  return true;
 228              } else {
 229                  // Already unlocked.
 230                  return true;
 231              }
 232          }
 233      }
 234  
 235  }


Généré le : Sun Feb 25 18:01:28 2007 par Balluche grâce à PHPXref 0.7