Fixes bugs in MediawikiArchiveIterator as well as stop start for iterators, a=chris

Chris Pollett [2013-03-23 17:Mar:rd]
Fixes bugs in MediawikiArchiveIterator as well as stop start for iterators, a=chris
Filename
lib/archive_bundle_iterators/text_archive_bundle_iterator.php
lib/bzip2_block_iterator.php
diff --git a/lib/archive_bundle_iterators/text_archive_bundle_iterator.php b/lib/archive_bundle_iterators/text_archive_bundle_iterator.php
index afe43ff14..cd21986d2 100644
--- a/lib/archive_bundle_iterators/text_archive_bundle_iterator.php
+++ b/lib/archive_bundle_iterators/text_archive_bundle_iterator.php
@@ -594,19 +594,21 @@ class TextArchiveBundleIterator extends ArchiveBundleIterator
      */
     function fileOpen($filename, $make_buffer_if_needed = true)
     {
-        switch($this->compression)
-        {
-            case 'bzip2':
-                $this->bz2_iterator = new BZip2BlockIterator($filename);
-            break;
+        if($this->iterate_dir) {
+            switch($this->compression)
+            {
+                case 'bzip2':
+                    $this->bz2_iterator = new BZip2BlockIterator($filename);
+                break;

-            case 'gzip':
-                $this->fh = gzopen($filename, "rb");
-            break;
+                case 'gzip':
+                    $this->fh = gzopen($filename, "rb");
+                break;

-            case 'plain':
-                $this->fh = fopen($filename, "rb");
-            break;
+                case 'plain':
+                    $this->fh = fopen($filename, "rb");
+                break;
+            }
         }
         if($make_buffer_if_needed) {
             if(!file_exists($this->buffer_filename)) {
@@ -699,8 +701,13 @@ class TextArchiveBundleIterator extends ArchiveBundleIterator
         $this->remainder = (isset($info['remainder'])) ? $info['remainder']:"";
         $this->header = (isset($info['header'])) ? $info['header']: array();
         $this->bz2_iterator = $info['bz2_iterator'];
-        if(!$this->end_of_iterator) {
-            $this->fileOpen($this->partitions[$this->current_partition_num]);
+        if(!$this->end_of_iterator && !$this->bz2_iterator) {
+            if(isset($this->partitions[$this->current_partition_num])) {
+                $filename = $this->partitions[$this->current_partition_num];
+            } else if(!$this->iterate_dir) { // fetcher case
+                $filename = ""; // will only use buffer so don't need
+            }
+            $this->fileOpen($filename);
             $success = fseek($this->buffer_fh, $info['current_offset']);
             if($success == -1) { $this->buffer_fh = NULL; }
         }
diff --git a/lib/bzip2_block_iterator.php b/lib/bzip2_block_iterator.php
index 87541f56c..69b1a94a4 100644
--- a/lib/bzip2_block_iterator.php
+++ b/lib/bzip2_block_iterator.php
@@ -362,4 +362,4 @@ if(!function_exists("main")) {
     if(isset($argv[0]) && realpath($argv[0]) == __FILE__) {
         main();
     }
-}
\ No newline at end of file
+}
ViewGit