Beispiel #1
0
 /**
  * Open a descriptor for this archive
  *
  * @param GitPHP_Archive $archive archive
  * @return boolean true on success
  */
 public function Open($archive)
 {
     if (!$archive) {
         return false;
     }
     if ($this->handle) {
         return true;
     }
     $args = array();
     $args[] = '--format=tar';
     $args[] = "--prefix='" . $archive->GetPrefix() . "'";
     $args[] = $archive->GetObject()->GetHash();
     $this->handle = $this->exe->Open($archive->GetProject()->GetPath(), GIT_ARCHIVE, $args);
     // hack to get around the fact that gzip files
     // can't be compressed on the fly and the php zlib stream
     // doesn't seem to daisy chain with any non-file streams
     $this->tempfile = tempnam(sys_get_temp_dir(), "GitPHP");
     $mode = 'wb';
     if ($this->compressLevel) {
         $mode .= $this->compressLevel;
     }
     $temphandle = gzopen($this->tempfile, $mode);
     if ($temphandle) {
         while (!feof($this->handle)) {
             gzwrite($temphandle, fread($this->handle, 1048576));
         }
         gzclose($temphandle);
         $temphandle = fopen($this->tempfile, 'rb');
     }
     if ($this->handle) {
         pclose($this->handle);
     }
     $this->handle = $temphandle;
     return $this->handle !== false;
 }
Beispiel #2
0
 /**
  * Open a descriptor for this archive
  *
  * @param GitPHP_Archive $archive archive
  * @return boolean true on success
  */
 public function Open($archive)
 {
     if (!$archive) {
         return false;
     }
     if ($this->handle) {
         return true;
     }
     $args = array();
     $args[] = '--format=tar';
     $args[] = "--prefix='" . $archive->GetPrefix() . "'";
     $args[] = $archive->GetObject()->GetHash();
     $this->handle = $this->exe->Open($archive->GetProject()->GetPath(), GIT_ARCHIVE, $args);
     return $this->handle !== false;
 }
Beispiel #3
0
 /**
  * Open
  *
  * Opens a descriptor for reading archive data
  *
  * @access public
  * @return boolean true on success
  */
 public function Open()
 {
     if (!$this->gitObject) {
         throw new Exception('Invalid object for archive');
     }
     if ($this->handle) {
         return true;
     }
     $exe = new GitPHP_GitExe($this->GetProject());
     $args = array();
     switch ($this->format) {
         case GITPHP_COMPRESS_ZIP:
             $args[] = '--format=zip';
             break;
         case GITPHP_COMPRESS_TAR:
         case GITPHP_COMPRESS_BZ2:
         case GITPHP_COMPRESS_GZ:
             $args[] = '--format=tar';
             break;
     }
     $args[] = '--prefix=' . $this->GetPrefix();
     $args[] = $this->gitObject->GetHash();
     $this->handle = $exe->Open(GIT_ARCHIVE, $args);
     unset($exe);
     if ($this->format == GITPHP_COMPRESS_GZ) {
         // hack to get around the fact that gzip files
         // can't be compressed on the fly and the php zlib stream
         // doesn't seem to daisy chain with any non-file streams
         $this->tempfile = tempnam(sys_get_temp_dir(), "GitPHP");
         $compress = GitPHP_Config::GetInstance()->GetValue('compresslevel');
         $mode = 'wb';
         if (is_int($compress) && $compress >= 1 && $compress <= 9) {
             $mode .= $compress;
         }
         $temphandle = gzopen($this->tempfile, $mode);
         if ($temphandle) {
             while (!feof($this->handle)) {
                 gzwrite($temphandle, fread($this->handle, 1048576));
             }
             gzclose($temphandle);
             $temphandle = fopen($this->tempfile, 'rb');
         }
         if ($this->handle) {
             pclose($this->handle);
         }
         $this->handle = $temphandle;
     }
     return $this->handle !== false;
 }