/** * 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); } }