Revision | ae843f94ad43ceff88dd5402b1d1c9471507bf72 (tree) |
---|---|
Time | 2014-11-30 13:00:19 |
Author | henoheno <henoheno> |
Commiter | umorigu |
BugTrack2/236: Care for readdir() returns FALSE
@@ -307,21 +307,20 @@ function plugin_rename_get_files($pages) | ||
307 | 307 | $matches = array(); |
308 | 308 | foreach ($dirs as $path) { |
309 | 309 | $dir = opendir($path); |
310 | - if (! $dir) continue; | |
311 | - | |
312 | - while ($file = readdir($dir)) { | |
310 | + if (! $dir) continue; // TODO: !== FALSE or die()? | |
311 | + while (($file = readdir($dir)) !== FALSE) { | |
313 | 312 | if ($file == '.' || $file == '..') continue; |
314 | - | |
315 | - foreach ($pages as $from=>$to) { | |
313 | + foreach ($pages as $from => $to) { | |
314 | + // TODO: preg_quote()? | |
316 | 315 | $pattern = '/^' . str_replace('/', '\/', $from) . '([._].+)$/'; |
317 | - if (! preg_match($pattern, $file, $matches)) | |
318 | - continue; | |
319 | - | |
320 | - $newfile = $to . $matches[1]; | |
321 | - $files[$from][$path . $file] = $path . $newfile; | |
316 | + if (preg_match($pattern, $file, $matches)) { | |
317 | + $newfile = $to . $matches[1]; | |
318 | + $files[$from][$path . $file] = $path . $newfile; | |
319 | + } | |
322 | 320 | } |
323 | 321 | } |
324 | 322 | } |
323 | + | |
325 | 324 | return $files; |
326 | 325 | } |
327 | 326 |