예제 #1
0
 /**
  * List the contents of the prebuilt TAR files
  */
 public function test_tarcontent()
 {
     $dir = dirname(__FILE__) . '/tar';
     foreach ($this->extensions as $ext) {
         $tar = new Tar();
         $file = "{$dir}/test.{$ext}";
         $tar->open($file);
         $content = $tar->contents();
         $this->assertCount(4, $content, "Contents of {$file}");
         $this->assertEquals('tar/testdata1.txt', $content[1]->getPath(), "Contents of {$file}");
         $this->assertEquals(13, $content[1]->getSize(), "Contents of {$file}");
         $this->assertEquals('tar/foobar/testdata2.txt', $content[3]->getPath(), "Contents of {$file}");
         $this->assertEquals(13, $content[3]->getSize(), "Contents of {$file}");
     }
 }
 /**
  * Unpack a downloaded archive file.
  *
  * @param string $file
  *   The filename of the archive you wish to extract.
  * @param string $directory
  *   The directory you wish to extract the archive into.
  * @return Archive
  *   The Archiver object used to extract the archive.
  * @throws \Exception on failure.
  */
 protected function extractArchive($file, $directory)
 {
     $archive = new Tar();
     // Remove the directory if it exists, otherwise it might contain a mixture of
     // old files mixed with the new files (e.g. in cases where files were removed
     // from a later release).
     $archive->open($file);
     $files = $archive->contents();
     // First entry contains the root folder.
     $project_path = $files[0]->getPath();
     if (file_exists($directory)) {
         $this->removeDir($directory);
     }
     // Reopen archive to extract all files.
     $archive->open($file);
     // Strip first folder level.
     $archive->extract($directory, $project_path);
     return $archive;
 }
예제 #3
0
파일: Archive.php 프로젝트: akochnov/fts
 public function restore()
 {
     foreach ($this->archives as $path) {
         $this->job->log(sprintf(__('Extracting %s', 'my-wp-backup'), $path));
         if ('zip' === $this->format) {
             $archive = new Zip();
         } else {
             $archive = new Tar();
             if ($this->is_compressed()) {
                 $this->job->log(sprintf(__('Decompressing archive compressed with %s', 'my-wp-backup'), Admin\Job::$compression_methods[$this->job['compression']]));
                 $archive->setCompression(9, $this->compression);
             }
         }
         $archive->open($path);
         $contents = $archive->contents();
         /** @var FileInfo $file */
         foreach ($contents as $file) {
             $this->job->log(sprintf(__('Extract file: %s', 'my-wp-backup'), $file->getPath()), 'debug');
         }
         $archive->open($path);
         $archive->extract(MyWPBackup::$info['root_dir']);
         $this->job->log(__('Ok.', 'my-wp-backup'));
     }
 }