Exemple #1
0
 /**
  * Remove duplicates from a source, keeping the most recent one (or the one that has highest pos in
  * the archive if the files have same date or no date specified)
  *
  * @param File_Archive_Reader a reader that may contain duplicates
  */
 function removeDuplicatesFromSource(&$toConvert, $URL = null)
 {
     $source =& File_Archive::_convertToReader($toConvert);
     if (PEAR::isError($source)) {
         return $source;
     }
     if ($URL !== null && substr($URL, -1) != '/') {
         $URL .= '/';
     }
     if ($source === null) {
         $source = File_Archive::read($URL);
     }
     require_once dirname(__FILE__) . "/Archive/Predicate/Duplicate.php";
     $pred = new File_Archive_Predicate_Duplicate($source);
     $source->close();
     return File_Archive::removeFromSource($pred, $source, null);
 }
Exemple #2
0
 function _testRemove($extension)
 {
     $writer = File_Archive::toArchive("test.{$extension}", File_Archive::toVariable($x));
     $writer->newFile('foo.txt');
     $writer->writeData('ABCDEF');
     $writer->newFile('bla_to_remove.txt');
     $writer->writeData('GHIJKL');
     $writer->newFile('bar.txt');
     $writer->writeData('MNOP');
     $writer->close();
     File_Archive::removeFromSource(File_Archive::predEreg('_to_remove'), $source = File_Archive::readSource(File_Archive::readMemory($x, "test.{$extension}"), "test.{$extension}/"));
     $this->assertEquals("foo.txt\nbar.txt", implode("\n", $source->getFileList()));
 }