OSDN Git Service

BugTrack2/236: Care for readdir() returns FALSE
authorhenoheno <henoheno>
Sat, 3 Nov 2007 15:26:19 +0000 (00:26 +0900)
committerumorigu <umorigu@gmail.com>
Sun, 30 Nov 2014 04:00:19 +0000 (13:00 +0900)
plugin/rename.inc.php

index 4b096d1..258eeba 100644 (file)
@@ -307,21 +307,20 @@ function plugin_rename_get_files($pages)
        $matches = array();
        foreach ($dirs as $path) {
                $dir = opendir($path);
-               if (! $dir) continue;
-
-               while ($file = readdir($dir)) {
+               if (! $dir) continue;   // TODO: !== FALSE or die()?
+               while (($file = readdir($dir)) !== FALSE) {
                        if ($file == '.' || $file == '..') continue;
-
-                       foreach ($pages as $from=>$to) {
+                       foreach ($pages as $from => $to) {
+                               // TODO: preg_quote()?
                                $pattern = '/^' . str_replace('/', '\/', $from) . '([._].+)$/';
-                               if (! preg_match($pattern, $file, $matches))
-                                       continue;
-
-                               $newfile = $to . $matches[1];
-                               $files[$from][$path . $file] = $path . $newfile;
+                               if (preg_match($pattern, $file, $matches)) {
+                                       $newfile = $to . $matches[1];
+                                       $files[$from][$path . $file] = $path . $newfile;
+                               }
                        }
                }
        }
+
        return $files;
 }