Beispiel #1
0
 /**
  * Create a tar archive of the folders in $add_dirs
  *
  */
 public function Create_Tar($which_exported, $add_dirs)
 {
     global $dataDir, $langmessage;
     $compression =& $_POST['compression'];
     if (!$this->NewFile($which_exported, $compression)) {
         return false;
     }
     // buildFromDirectory with regular expression
     $tar_object = new \gp\tool\Archive($this->archive_path);
     foreach ($add_dirs as $dir) {
         $localname = '/gpexport' . substr($dir, strlen($dataDir));
         $tar_object->Add($dir, $localname);
     }
     //add ini file
     $this->Export_Ini($tar_object, $which_exported);
     $tar_object->compress();
     return true;
 }
Beispiel #2
0
 /**
  * Unpack the archive and save the files in temporary folders
  * @return bool
  */
 function UnpackAndSort($file)
 {
     global $langmessage;
     $archive = new \gp\tool\Archive($file);
     $archive_root = $archive->GetRoot();
     if (is_null($archive_root)) {
         $this->msg($langmessage['error_unpacking'] . ' (no root)');
         return false;
     }
     $archive_root_len = strlen($archive_root);
     $archive_files = $archive->ListFiles();
     $this->msg($langmessage['package_unpacked']);
     foreach ($archive_files as $file) {
         if (strpos($file['name'], $archive_root) === false) {
             continue;
         }
         $rel_filename = substr($file['name'], $archive_root_len);
         $name_parts = explode('/', trim($rel_filename, '/'));
         $dir = array_shift($name_parts);
         $replace_dir = false;
         switch ($dir) {
             case 'include':
                 $replace_dir = 'include';
                 $rel_filename = implode('/', $name_parts);
                 break;
             case 'themes':
             case 'addons':
                 if (count($name_parts) == 0) {
                     continue 2;
                 }
                 $replace_dir = $dir . '/' . array_shift($name_parts);
                 $rel_filename = implode('/', $name_parts);
                 break;
         }
         if ($replace_dir === false) {
             continue;
         }
         $content = $archive->getFromName($file['name']);
         if (empty($content)) {
             return true;
         }
         $replace_dir = trim($replace_dir, '/');
         if (!isset($this->replace_dirs[$replace_dir])) {
             $this->replace_dirs[$replace_dir] = \gp\tool\FileSystem::TempFile($replace_dir);
         }
         $file_rel = $this->replace_dirs[$replace_dir] . '/' . $rel_filename;
         if (!$this->PutFile($file_rel, $content)) {
             return false;
         }
     }
     return true;
 }
Beispiel #3
0
 /**
  * Create archive from files
  *
  */
 function FromFiles($type)
 {
     $path = $this->ArchivePath($type);
     $path = $this->ArchivePath($type);
     try {
         $archive = new \gp\tool\Archive($path);
         $archive->Add($this->dir);
     } catch (Exception $e) {
         self::AssertTrue(false, 'FromFiles(' . $type . ') Failed with message: ' . $e->getMessage());
         return;
     }
     $archive->Compress();
     self::AssertFileExists($path);
     return new \gp\tool\Archive($path);
     //return a readable archive
 }
Beispiel #4
0
 /**
  * Write Archive
  *
  */
 private function ExtractArchive($archive_path)
 {
     global $langmessage, $dataDir;
     $archive = new \gp\tool\Archive($archive_path);
     $extract_temp = $dataDir . \gp\tool\FileSystem::TempFile('/data/_temp/addon');
     if (!$archive->extractTo($extract_temp)) {
         $this->message($langmessage['download_failed'] . ' (Package not extracted)');
         return false;
     }
     //get archive root
     $archive_root = $archive->GetRoot();
     if (is_null($archive_root)) {
         $this->message($langmessage['download_failed'] . ' (Root not found)');
         return false;
     }
     //rename to source folder
     $rename_from = $extract_temp . '/' . ltrim($archive_root, '/');
     if (!\gp\tool\Files::Replace($rename_from, $this->source)) {
         $this->message($langmessage['download_failed'] . ' (Not replaced)');
         return false;
     }
     return true;
 }
Beispiel #5
0
 /**
  * Create a tar archive of the folders in $add_dirs
  *
  */
 public function Create_Tar($which_exported, $add_dirs)
 {
     global $dataDir, $langmessage;
     $compression =& $_POST['compression'];
     if (!$this->NewFile($which_exported, $compression)) {
         return false;
     }
     try {
         $tar_object = new \gp\tool\Archive($this->archive_path);
         foreach ($add_dirs as $dir) {
             $localname = '/gpexport' . substr($dir, strlen($dataDir));
             $tar_object->Add($dir, $localname);
         }
         //add ini file
         $this->Export_Ini($tar_object, $which_exported);
         $tar_object->compress();
     } catch (\Exception $e) {
         message($langmessage['OOPS'] . ' (Archive couldn\'t be created)');
         return false;
     }
     return true;
 }