예제 #1
0
 public function test_createlongpathgnu()
 {
     $tar = new Tar();
     $tar->setCompression(0);
     $tmp = tempnam(sys_get_temp_dir(), 'dwtartest');
     $path = '';
     for ($i = 0; $i < 20; $i++) {
         $path .= '1234567890/';
     }
     $path = rtrim($path, '/');
     $tar->create($tmp);
     $tar->addData("{$path}/test.txt", 'testcontent1');
     $tar->close();
     $this->assertTrue(filesize($tmp) > 30);
     //arbitrary non-zero number
     $data = file_get_contents($tmp);
     // We should find the complete path/filename and a longlink entry
     $this->assertTrue(strpos($data, 'testcontent1') !== false, 'content in TAR');
     $this->assertTrue(strpos($data, 'test.txt') !== false, 'filename in TAR');
     $this->assertTrue(strpos($data, $path) !== false, 'path in TAR');
     $this->assertTrue(strpos($data, "{$path}/test.txt") !== false, 'full filename in TAR');
     $this->assertTrue(strpos($data, '@LongLink') !== false, '@LongLink in TAR');
     @unlink($tmp);
 }
예제 #2
0
파일: Archive.php 프로젝트: akochnov/fts
 /**
  * @throws \Exception
  * @throws \splitbrain\PHPArchive\ArchiveIOException
  */
 public function create()
 {
     $this->job->log(__('Creating archive', 'my-wp-backup'));
     $archive_name = $this->job->get_filename() . '.' . $this->extension;
     if ('zip' === $this->format) {
         $archive = new Zip();
         $archive->create($archive_name);
     } else {
         $archive = new Tar();
         if ($this->is_compressed()) {
             $this->job->log(sprintf(__('Compressing archive with %s', 'my-wp-backup'), Admin\Job::$compression_methods[$this->job['compression']]));
         }
         $archive->setCompression(9, $this->compression);
         $archive->create($archive_name);
     }
     $this->archives = array($archive_name);
     if ('1' === $this->job['backup_files']) {
         $files = $this->job->get_files();
         /**
          * @var string $name filename
          * @var \DirectoryIterator $file
          */
         foreach ($files['iterator'] as $name => $file) {
             // Skip directories (they would be added automatically)
             if ($file->isDir()) {
                 continue;
             }
             // Get real and relative path for current file
             $filePath = $file->getRealPath();
             $relativePath = substr($filePath, strlen(MyWPBackup::$info['root_dir']));
             if (false === $relativePath) {
                 $this->job->log(sprintf(__('Skipping "%s", not in root dir', 'my-wp-backup'), $filePath), 'error');
                 continue;
             }
             $this->job->log(sprintf(__('Adding file: %s....', 'my-wp-backup'), $relativePath), 'debug');
             $archive->addFile($filePath, $relativePath);
             $this->job->log(__('Ok.', 'my-wp-backup'), 'debug');
             $this->job->get_hashfile()->fwrite("ok {$relativePath}\n");
         }
     } else {
         $this->job->log(__('Only backing up database file.', 'my-wp-backup'));
     }
     $archive->addFile($this->job->get_hashfile()->getPathname(), '.my-wp-backup');
     if ('1' === $this->job['export_db']) {
         $this->job->log(__('Adding database export file...', 'my-wp-backup'), 'debug');
         $archive->addFile($this->job->get_dbpath(), ExportFile::FILENAME);
         $this->job->log(__('Ok.', 'my-wp-backup'), 'debug');
     }
     $this->job->log(__('Closing archive...', 'my-wp-backup'), 'debug');
     $archive->close();
     $this->job->log(__('Ok.', 'my-wp-backup'), 'debug');
     $this->calc_size();
     if ($this->split_size > 0 && $this->size > $this->split_size) {
         $this->job->log(__('Splitting archive', 'my-wp-backup'));
         $root_archive = fopen($this->archives[0], 'rb');
         $this->archives = array();
         $part = 0;
         if (!$root_archive) {
             throw new \Exception(__('Unable to split archive.', 'my-wp-backup'));
         }
         while (!feof($root_archive)) {
             $buffer = fread($root_archive, $this->split_size);
             $filename = sprintf('%s.vol%s.%s', $this->job->get_filename(), ++$part, $this->extension);
             $handle = fopen($filename, 'wb');
             $this->job->log(sprintf(__('Creating volume %s...', 'my-wp-backup'), $part), 'debug');
             if (!$handle) {
                 throw new \Exception(sprintf(__('Unable to create volume %s.', 'my-wp-backup'), $part));
             }
             fwrite($handle, $buffer);
             fclose($handle);
             array_push($this->archives, $filename);
             $this->job->log(__('Ok.', 'my-wp-backup'), 'debug');
             $this->job->log(sprintf(__('Created volume %s', 'my-wp-backup'), $part));
         }
         fclose($root_archive);
         unlink($archive_name);
     }
     $this->job->log(sprintf(__('Archive location: %s', 'my-wp-backup'), implode(',', $this->archives)), 'debug');
     $this->job->log(__('Done create archive', 'my-wp-backup'));
     $this->job->set_archive($this);
 }