From e521039d22294813fb562257fe529bfcdacd145e Mon Sep 17 00:00:00 2001 From: Eloy Lafuente Date: Tue, 28 Sep 2010 21:26:11 +0000 Subject: [PATCH] MDL-24381 backup - avoid infinite iteration under windows caused by platform-dependent dirname() --- .../processors/grouped_parser_processor.class.php | 8 ++++---- .../processors/simplified_parser_processor.class.php | 4 ++-- backup/util/xml/parser/progressive_parser.class.php | 12 ++++++++++-- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/backup/util/xml/parser/processors/grouped_parser_processor.class.php b/backup/util/xml/parser/processors/grouped_parser_processor.class.php index 84a89c868e2..7d701064933 100644 --- a/backup/util/xml/parser/processors/grouped_parser_processor.class.php +++ b/backup/util/xml/parser/processors/grouped_parser_processor.class.php @@ -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; } diff --git a/backup/util/xml/parser/processors/simplified_parser_processor.class.php b/backup/util/xml/parser/processors/simplified_parser_processor.class.php index 817f3898135..9dbe9b8a0fc 100644 --- a/backup/util/xml/parser/processors/simplified_parser_processor.class.php +++ b/backup/util/xml/parser/processors/simplified_parser_processor.class.php @@ -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 diff --git a/backup/util/xml/parser/progressive_parser.class.php b/backup/util/xml/parser/progressive_parser.class.php index 1152a2e269c..11f3c9c682e 100644 --- a/backup/util/xml/parser/progressive_parser.class.php +++ b/backup/util/xml/parser/progressive_parser.class.php @@ -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) {