MDL-24381 backup - avoid infinite iteration under windows caused by platform-dependen...
authorEloy Lafuente <stronk7@moodle.org>
Tue, 28 Sep 2010 21:26:11 +0000 (21:26 +0000)
committerEloy Lafuente <stronk7@moodle.org>
Tue, 28 Sep 2010 21:26:11 +0000 (21:26 +0000)
backup/util/xml/parser/processors/grouped_parser_processor.class.php
backup/util/xml/parser/processors/simplified_parser_processor.class.php
backup/util/xml/parser/progressive_parser.class.php

index 84a89c8..7d70106 100644 (file)
@@ -117,12 +117,12 @@ abstract class grouped_parser_processor extends simplified_parser_processor {
      * false if not
      */
     protected function processed_parent_exists($path) {
-        $parentpath = dirname($path);
+        $parentpath = progressive_parser::dirname($path);
         while ($parentpath != '/') {
             if ($this->path_is_selected($parentpath)) {
                 return $parentpath;
             }
-            $parentpath = dirname($parentpath);
+            $parentpath = progressive_parser::dirname($parentpath);
         }
         return false;
     }
@@ -134,12 +134,12 @@ abstract class grouped_parser_processor extends simplified_parser_processor {
      * false if not
      */
     protected function grouped_parent_exists($path) {
-        $parentpath = dirname($path);
+        $parentpath = progressive_parser::dirname($path);
         while ($parentpath != '/') {
             if ($this->path_is_grouped($parentpath)) {
                 return $parentpath;
             }
-            $parentpath = dirname($parentpath);
+            $parentpath = progressive_parser::dirname($parentpath);
         }
         return false;
     }
index 817f389..9dbe9b8 100644 (file)
@@ -55,7 +55,7 @@ abstract class simplified_parser_processor extends progressive_parser_processor
 
     public function add_path($path) {
         $this->paths[] = $path;
-        $this->parentpaths[] = dirname($path);
+        $this->parentpaths[] = progressive_parser::dirname($path);
     }
 
     /**
@@ -71,7 +71,7 @@ abstract class simplified_parser_processor extends progressive_parser_processor
     public function process_chunk($data) {
         // Precalculate some vars for readability
         $path = $data['path'];
-        $parentpath = dirname($path);
+        $parentpath = progressive_parser::dirname($path);
         $tag = basename($path);
 
         // If the path is a registered parent one, store all its tags
index 1152a2e..11f3c9c 100644 (file)
@@ -144,6 +144,14 @@ class progressive_parser {
         $this->xml_parser = null;
     }
 
+    /**
+     * Provides one cross-platform dirname function for
+     * handling parser paths, see MDL-24381
+     */
+    public static function dirname($path) {
+        return str_replace('\\', '/', dirname($path));
+    }
+
 // Protected API starts here
 
     protected function parse($data, $eof) {
@@ -204,7 +212,7 @@ class progressive_parser {
 
         // If not set, build to push common header
         if (empty($this->topush)) {
-            $this->topush['path']  = dirname($this->path);
+            $this->topush['path']  = progressive_parser::dirname($this->path);
             $this->topush['level'] = $this->level;
             $this->topush['tags']  = array();
         }
@@ -246,7 +254,7 @@ class progressive_parser {
 
         // Normal update of parser internals
         $this->level--;
-        $this->path = dirname($this->path);
+        $this->path = progressive_parser::dirname($this->path);
     }
 
     protected function char_data($parser, $data) {