diff options
author | Arthur Schiwon <blizzz@owncloud.com> | 2013-09-05 11:58:57 +0200 |
---|---|---|
committer | Arthur Schiwon <blizzz@owncloud.com> | 2013-09-05 11:58:57 +0200 |
commit | c01675de5d6650c7b1cd0571d8c313f21d13c33c (patch) | |
tree | a1c3672af78c6e84d4e9fedab9cff0ef38620f2f /lib/helper.php | |
parent | ec3639dc7a28348b136d2008e692cffe8c3753ad (diff) | |
download | nextcloud-server-c01675de5d6650c7b1cd0571d8c313f21d13c33c.tar.gz nextcloud-server-c01675de5d6650c7b1cd0571d8c313f21d13c33c.zip |
more is_resource checks before readdir
Diffstat (limited to 'lib/helper.php')
-rw-r--r-- | lib/helper.php | 32 |
1 files changed, 18 insertions, 14 deletions
diff --git a/lib/helper.php b/lib/helper.php index 5fb8fed3459..0af7f6f0394 100644 --- a/lib/helper.php +++ b/lib/helper.php @@ -341,17 +341,19 @@ class OC_Helper { if (!is_dir($path)) return chmod($path, $filemode); $dh = opendir($path); - while (($file = readdir($dh)) !== false) { - if ($file != '.' && $file != '..') { - $fullpath = $path . '/' . $file; - if (is_link($fullpath)) - return false; - elseif (!is_dir($fullpath) && !@chmod($fullpath, $filemode)) - return false; elseif (!self::chmodr($fullpath, $filemode)) - return false; + if(is_resource($dh)) { + while (($file = readdir($dh)) !== false) { + if ($file != '.' && $file != '..') { + $fullpath = $path . '/' . $file; + if (is_link($fullpath)) + return false; + elseif (!is_dir($fullpath) && !@chmod($fullpath, $filemode)) + return false; elseif (!self::chmodr($fullpath, $filemode)) + return false; + } } + closedir($dh); } - closedir($dh); if (@chmod($path, $filemode)) return true; else @@ -649,9 +651,11 @@ class OC_Helper { // if oc-noclean is empty delete it $isTmpDirNoCleanEmpty = true; $tmpDirNoClean = opendir($tmpDirNoCleanName); - while (false !== ($file = readdir($tmpDirNoClean))) { - if (!\OC\Files\Filesystem::isIgnoredDir($file)) { - $isTmpDirNoCleanEmpty = false; + if(is_resource($tmpDirNoClean)) { + while (false !== ($file = readdir($tmpDirNoClean))) { + if (!\OC\Files\Filesystem::isIgnoredDir($file)) { + $isTmpDirNoCleanEmpty = false; + } } } if ($isTmpDirNoCleanEmpty) { @@ -694,7 +698,7 @@ class OC_Helper { $newpath = $path . '/' . $filename; if ($view->file_exists($newpath)) { if (preg_match_all('/\((\d+)\)/', $name, $matches, PREG_OFFSET_CAPTURE)) { - //Replace the last "(number)" with "(number+1)" + //Replace the last "(number)" with "(number+1)" $last_match = count($matches[0]) - 1; $counter = $matches[1][$last_match][0] + 1; $offset = $matches[0][$last_match][1]; @@ -705,7 +709,7 @@ class OC_Helper { } do { if ($offset) { - //Replace the last "(number)" with "(number+1)" + //Replace the last "(number)" with "(number+1)" $newname = substr_replace($name, '(' . $counter . ')', $offset, $match_length); } else { $newname = $name . ' (' . $counter . ')'; |