コード例 #1
0
 public function testValidateChecksum()
 {
     $tmp = tmpdir();
     try {
         mkdir($tmp);
         mkdir($tmp . '/data');
         file_put_contents("{$tmp}/manifest-sha1.txt", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa data/missing.txt\n");
         touch("{$tmp}/data/missing.txt");
         $manifest = new BagItManifest("{$tmp}/manifest-sha1.txt", "{$tmp}/");
         $errors = array();
         $this->assertFalse($manifest->validate($errors));
         $this->assertTrue(seenAtKey($errors, 0, 'data/missing.txt'));
         $this->assertTrue(seenAtKey($errors, 1, 'Checksum mismatch.'));
     } catch (Exception $e) {
         rrmdir($tmp);
         throw $e;
     }
     rrmdir($tmp);
 }
コード例 #2
0
ファイル: bagit.php プロジェクト: AdrienneSerra/Digitalsc
 /**
  * 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);
     }
 }