diff options
author | Tristan Darricau <github@nicofuma.fr> | 2014-05-06 13:27:36 +0200 |
---|---|---|
committer | Tristan Darricau <github@nicofuma.fr> | 2014-05-06 14:04:06 +0200 |
commit | e4beea0c1e2a2dc423d112cf14277b49cd4f1f4e (patch) | |
tree | bfd28fb231905c01133a95f1756866f7c65ba939 | |
parent | cd5129f261b19d4e74188f652a72bd71504b439b (diff) | |
download | forums-e4beea0c1e2a2dc423d112cf14277b49cd4f1f4e.tar forums-e4beea0c1e2a2dc423d112cf14277b49cd4f1f4e.tar.gz forums-e4beea0c1e2a2dc423d112cf14277b49cd4f1f4e.tar.bz2 forums-e4beea0c1e2a2dc423d112cf14277b49cd4f1f4e.tar.xz forums-e4beea0c1e2a2dc423d112cf14277b49cd4f1f4e.zip |
[ticket/12325] Use \RecursiveDirectoryIterator
PHPBB3-12325
-rw-r--r-- | build/build_helper.php | 57 |
1 files changed, 19 insertions, 38 deletions
diff --git a/build/build_helper.php b/build/build_helper.php index 6a0fc0042e..7c75206d6d 100644 --- a/build/build_helper.php +++ b/build/build_helper.php @@ -325,19 +325,19 @@ class build_package $result = array(); $file_contents = file($deleted_filename); - foreach ($file_contents as $line) + foreach ($file_contents as $filename) { - $line = trim($line); + $filename = trim($filename); - if (!$line) + if (!$filename) { continue; } - $line = str_replace('Only in ' . $package_name, '', $line); - $line = ltrim($line, '/'); + $filename = str_replace('Only in ' . $package_name, '', $filename); + $filename = ltrim($filename, '/'); - if (substr($line, 0, 1) == ':') + if (substr($filename, 0, 1) == ':') { $replace = ''; } @@ -346,45 +346,26 @@ class build_package $replace = '/'; } - $line = str_replace(': ', $replace, $line); - - if (is_dir("{$this->locations['old_versions']}{$package_name}/{$line}")) - { - $result = array_merge($result, $this->get_files_recursive("{$this->locations['old_versions']}{$package_name}/{$line}", $line)); - } - else - { - $result[] = $line; - } - } - - return $result; - } - - /** - * Get recursively the list of the files contained in a directory - * - * @param string $directory_absolute Absolute path to the directory - * @param string $directory Relative path to the directory (used to prefixed the name of the files) - * @return array - */ - protected function get_files_recursive($directory_absolute, $directory) - { - $result = array(); - $files = scandir($directory_absolute); + $filename = str_replace(': ', $replace, $filename); - foreach ($files as $file) - { - if (is_dir($directory_absolute . '/' . $file)) + if (is_dir("{$this->locations['old_versions']}{$package_name}/{$filename}")) { - if ($file != '.' && $file != '..') + $iterator = new \RecursiveIteratorIterator( + new \RecursiveDirectoryIterator( + "{$this->locations['old_versions']}{$package_name}/{$filename}", + \FilesystemIterator::UNIX_PATHS | \FilesystemIterator::SKIP_DOTS + ), + \RecursiveIteratorIterator::LEAVES_ONLY + ); + + foreach ($iterator as $file_info) { - $result = array_merge($result, $this->get_files_recursive($directory_absolute . '/' . $file, $directory . '/' . $file)); + $result[] = "{$filename}/{$iterator->getSubPathname()}"; } } else { - $result[] = $directory . '/' . $file; + $result[] = $filename; } } |