Ejemplo n.º 1
0
 /**
  * @param string $tar_filename
  * @param string $dst_dir
  * @return boolean
  */
 public function unpack($tar_filename, $dst_dir)
 {
     if (!file_exists($tar_filename)) {
         $this->error = 'Error: Can\'t unpack file "' . $tar_filename . '" because it does not exists.';
         $error = new AError($this->error);
         $error->toLog()->toDebug();
         return false;
     }
     if (!file_exists($dst_dir) || !is_dir($dst_dir)) {
         $this->error = 'Error: Can\'t unpack file "' . $tar_filename . '" because destination directory "' . $dst_dir . '" does not exists.';
         $error = new AError($this->error);
         $error->toLog()->toDebug();
         return false;
     }
     if (!is_writable($dst_dir)) {
         $this->error = 'Error: Can\'t unpack file "' . $tar_filename . '" because destination directory "' . $dst_dir . '" have no write permission.';
         $error = new AError($this->error);
         $error->toLog()->toDebug();
         return false;
     }
     $command = 'tar -C ' . $dst_dir . ' -xzvf ' . $tar_filename . ' > /dev/null';
     if (isFunctionAvailable('system')) {
         system($command, $exit_code);
     } else {
         $exit_code = 1;
     }
     if ($exit_code) {
         if (class_exists('PharData')) {
             //remove destination folder first
             $this->removeDir($dst_dir . $this->session->data['package_info']['tmp_dir']);
             try {
                 $phar = new PharData($tar_filename);
                 $phar->extractTo($dst_dir);
             } catch (Exception $e) {
             }
         } else {
             $this->load->library('targz');
             $targz = new Atargz();
             $targz->extractTar($tar_filename, $dst_dir);
         }
     }
     $this->chmod_R($dst_dir . $this->session->data['package_info']['tmp_dir'], 0777, 0777);
     return true;
 }
Ejemplo n.º 2
0
 /**
  * @param string $tar_filename
  * @param string $dst_dir
  * @return boolean
  */
 public function unpack($tar_filename, $dst_dir)
 {
     if (!file_exists($tar_filename)) {
         $this->error = 'Error: Can\'t unpack file "' . $tar_filename . '" because it does not exists.';
         $error = new AError($this->error);
         $error->toLog()->toDebug();
         return false;
     }
     if (!file_exists($dst_dir) || !is_dir($dst_dir)) {
         $this->error = 'Error: Can\'t unpack file "' . $tar_filename . '" because destination directory "' . $dst_dir . '" does not exists.';
         $error = new AError($this->error);
         $error->toLog()->toDebug();
         return false;
     }
     if (!is_writable($dst_dir)) {
         $this->error = 'Error: Can\'t unpack file "' . $tar_filename . '" because destination directory "' . $dst_dir . '" have no write permission.';
         $error = new AError($this->error);
         $error->toLog()->toDebug();
         return false;
     }
     $exit_code = 0;
     if (class_exists('PharData')) {
         //remove destination folder first
         //run pathinfo twice for tar.gz. files
         $this->removeDir($dst_dir . pathinfo(pathinfo($tar_filename, PATHINFO_FILENAME), PATHINFO_FILENAME));
         try {
             $phar = new PharData($tar_filename);
             $phar->extractTo($dst_dir, null, true);
         } catch (Exception $e) {
             $error = new AError($e->getMessage());
             $error->toLog()->toDebug();
             $this->error = 'Error: Cannot to unpack file "' . $tar_filename . '". Please, see error log for details. ';
             return false;
         }
     } else {
         $exit_code = 1;
     }
     if ($exit_code) {
         $this->load->library('targz');
         $targz = new Atargz();
         $targz->extractTar($tar_filename, $dst_dir);
     }
     $this->chmod_R($dst_dir . $this->session->data['package_info']['tmp_dir'], 0777, 0777);
     return true;
 }