示例#1
0
 public function testBagIt_uncompressBagTar()
 {
     $tarfile = __DIR__ . '/TestBag.tgz';
     $output = BagIt_uncompressBag($tarfile);
     $this->assertFileExists($output);
     $this->assertTrue(strpos($output, sys_get_temp_dir()) !== false);
     $this->_clearTagManifest();
     $bagFiles = rls(__DIR__ . '/TestBag');
     sort($bagFiles);
     $outFiles = rls($output);
     sort($outFiles);
     $this->assertEquals(count($bagFiles), count($outFiles));
     for ($i = 0; $i < count($outFiles); $i++) {
         $this->assertEquals(basename($bagFiles[$i]), basename($outFiles[$i]));
     }
 }
示例#2
0
 /**
  * This method is used whenever something is added to or removed from the
  * bag. It performs these steps:
  *
  * <ul>
  * <li>Ensures that required files are present;</li>
  * <li>Sanitizes file names;</li>
  * <li>Makes sure that checksums are up-to-date;</li>
  * <li>Adds checksums and file entries for new files;</li>
  * <li>Removes checksums and file entries for missing files; and</li>
  * <li>If it's an extended bag, makes sure that those files are also
  * up-to-date.</li>
  * </ul>
  *
  * @return void
  */
 function update()
 {
     // Clear the manifests.
     $this->manifest->clear();
     if ($this->tagManifest !== null) {
         $this->tagManifest->clear();
     }
     // Clean up the file names in the data directory.
     $dataFiles = rls($this->getDataDirectory());
     foreach ($dataFiles as $dataFile) {
         $baseName = basename($dataFile);
         if ($baseName == '.' || $baseName == '..') {
             continue;
         }
         $cleanName = BagIt_sanitizeFileName($baseName);
         if ($baseName != $cleanName) {
             $dirName = dirname($dataFile);
             rename($dataFile, "{$dirName}/{$cleanName}");
         }
     }
     if ($this->extended || count($this->bagInfoData) > 0) {
         $this->_writeBagInfo();
     }
     // Update the manifests.
     $this->manifest->update(rls($this->getDataDirectory()));
     if ($this->tagManifest !== null) {
         $bagdir = $this->bagDirectory;
         $tagFiles = array("{$bagdir}/bagit.txt", "{$bagdir}/bag-info.txt", $this->fetch->fileName, $this->manifest->getFileName());
         $this->tagManifest->update($tagFiles);
     }
 }
示例#3
0
 public function testUpdate()
 {
     // First, clear it out and verify it.
     $this->manifest->clear();
     $this->assertEquals(0, count($this->manifest->data));
     $this->assertEquals(0, filesize($this->manifest->fileName));
     // Now, regenerate it and test.
     $this->manifest->update(rls("{$this->prefix}/data"));
     $this->assertEquals(7, count($this->manifest->data));
     $this->assertEquals('547b21e9c710f562d448a6cd7d32f8257b04e561', $this->manifest->data['data/imgs/109x109xcoins1-150x150.jpg']);
     $this->assertEquals('fba552acae866d24fb143fef0ddb24efc49b097a', $this->manifest->data['data/imgs/109x109xprosody.png']);
     $this->assertEquals('4beed314513ad81e1f5fad42672a3b1bd3a018ea', $this->manifest->data['data/imgs/110x108xmetaphor1.png']);
     $this->assertEquals('4372383348c55775966bb1deeeb2b758b197e2a1', $this->manifest->data['data/imgs/fellows1-150x150.png']);
     $this->assertEquals('b8593e2b3c2fa3756d2b206a90c7259967ff6650', $this->manifest->data['data/imgs/fibtriangle-110x110.jpg']);
     $this->assertEquals('aec60202453733a976433833c9d408a449f136b3', $this->manifest->data['data/imgs/uvalib.png']);
     $this->assertEquals('0de174b95ebacc2d91b0839cb2874b2e8f604b98', $this->manifest->data['data/README.txt']);
 }
示例#4
0
/**
 * This compresses the bag into a new file.
 *
 * @param string $dirname The directory to compress.
 * @param string $output  The output file.
 * @param string $method  Either 'tgz' or 'zip'. Default is 'tgz'.
 *
 * @return string The file name for the file.
 */
function BagIt_compressBag($dirname, $output, $method = 'tgz')
{
    $base = basename($dirname);
    $stripLen = strlen($dirname) - strlen($base);
    if ($method == 'zip') {
        $zip = new ZipArchive();
        $zip->open($output, ZIPARCHIVE::CREATE);
        foreach (rls($dirname) as $file) {
            $zip->addFile($file, substr($file, $stripLen));
        }
        $zip->close();
    } else {
        if ($method == 'tgz') {
            $tar = new Archive_Tar($output, 'gz');
            $tar->createModify($dirname, $base, $dirname);
        }
    }
}