more is_resource checks before readdir
This commit is contained in:
parent
ec3639dc7a
commit
c01675de5d
|
@ -329,72 +329,73 @@ class Util {
|
|||
$this->view->is_dir($directory)
|
||||
&& $handle = $this->view->opendir($directory)
|
||||
) {
|
||||
if(is_resource($handle)) {
|
||||
while (false !== ($file = readdir($handle))) {
|
||||
|
||||
while (false !== ($file = readdir($handle))) {
|
||||
if (
|
||||
$file !== "."
|
||||
&& $file !== ".."
|
||||
) {
|
||||
|
||||
if (
|
||||
$file !== "."
|
||||
&& $file !== ".."
|
||||
) {
|
||||
$filePath = $directory . '/' . $this->view->getRelativePath('/' . $file);
|
||||
$relPath = \OCA\Encryption\Helper::stripUserFilesPath($filePath);
|
||||
|
||||
$filePath = $directory . '/' . $this->view->getRelativePath('/' . $file);
|
||||
$relPath = \OCA\Encryption\Helper::stripUserFilesPath($filePath);
|
||||
// If the path is a directory, search
|
||||
// its contents
|
||||
if ($this->view->is_dir($filePath)) {
|
||||
|
||||
// If the path is a directory, search
|
||||
// its contents
|
||||
if ($this->view->is_dir($filePath)) {
|
||||
$this->findEncFiles($filePath, $found);
|
||||
|
||||
$this->findEncFiles($filePath, $found);
|
||||
// If the path is a file, determine
|
||||
// its encryption status
|
||||
} elseif ($this->view->is_file($filePath)) {
|
||||
|
||||
// If the path is a file, determine
|
||||
// its encryption status
|
||||
} elseif ($this->view->is_file($filePath)) {
|
||||
// Disable proxies again, some-
|
||||
// where they got re-enabled :/
|
||||
\OC_FileProxy::$enabled = false;
|
||||
|
||||
// Disable proxies again, some-
|
||||
// where they got re-enabled :/
|
||||
\OC_FileProxy::$enabled = false;
|
||||
$isEncryptedPath = $this->isEncryptedPath($filePath);
|
||||
// If the file is encrypted
|
||||
// NOTE: If the userId is
|
||||
// empty or not set, file will
|
||||
// detected as plain
|
||||
// NOTE: This is inefficient;
|
||||
// scanning every file like this
|
||||
// will eat server resources :(
|
||||
if (
|
||||
Keymanager::getFileKey($this->view, $this->userId, $relPath)
|
||||
&& $isEncryptedPath
|
||||
) {
|
||||
|
||||
$isEncryptedPath = $this->isEncryptedPath($filePath);
|
||||
// If the file is encrypted
|
||||
// NOTE: If the userId is
|
||||
// empty or not set, file will
|
||||
// detected as plain
|
||||
// NOTE: This is inefficient;
|
||||
// scanning every file like this
|
||||
// will eat server resources :(
|
||||
if (
|
||||
Keymanager::getFileKey($this->view, $this->userId, $relPath)
|
||||
&& $isEncryptedPath
|
||||
) {
|
||||
$found['encrypted'][] = array(
|
||||
'name' => $file,
|
||||
'path' => $filePath
|
||||
);
|
||||
|
||||
$found['encrypted'][] = array(
|
||||
'name' => $file,
|
||||
'path' => $filePath
|
||||
);
|
||||
// If the file uses old
|
||||
// encryption system
|
||||
} elseif (Crypt::isLegacyEncryptedContent($isEncryptedPath, $relPath)) {
|
||||
|
||||
// If the file uses old
|
||||
// encryption system
|
||||
} elseif (Crypt::isLegacyEncryptedContent($isEncryptedPath, $relPath)) {
|
||||
$found['legacy'][] = array(
|
||||
'name' => $file,
|
||||
'path' => $filePath
|
||||
);
|
||||
|
||||
$found['legacy'][] = array(
|
||||
'name' => $file,
|
||||
'path' => $filePath
|
||||
);
|
||||
// If the file is not encrypted
|
||||
} else {
|
||||
|
||||
// If the file is not encrypted
|
||||
} else {
|
||||
$found['plain'][] = array(
|
||||
'name' => $file,
|
||||
'path' => $relPath
|
||||
);
|
||||
|
||||
$found['plain'][] = array(
|
||||
'name' => $file,
|
||||
'path' => $relPath
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
\OC_FileProxy::$enabled = true;
|
||||
|
|
|
@ -378,7 +378,7 @@ class OC_Mount_Config {
|
|||
}
|
||||
$result = array();
|
||||
$handle = opendir($path);
|
||||
if ( ! $handle) {
|
||||
if(!is_resource($handle)) {
|
||||
return array();
|
||||
}
|
||||
while (false !== ($file = readdir($handle))) {
|
||||
|
|
|
@ -221,7 +221,8 @@ class Shared extends \OC\Files\Storage\Common {
|
|||
public function filemtime($path) {
|
||||
if ($path == '' || $path == '/') {
|
||||
$mtime = 0;
|
||||
if ($dh = $this->opendir($path)) {
|
||||
$dh = $this->opendir($path);
|
||||
if(is_resource($dh)) {
|
||||
while (($filename = readdir($dh)) !== false) {
|
||||
$tempmtime = $this->filemtime($filename);
|
||||
if ($tempmtime > $mtime) {
|
||||
|
|
|
@ -65,16 +65,18 @@ class MappedLocal extends \OC\Files\Storage\Common{
|
|||
|
||||
$logicalPath = $this->mapper->physicalToLogic($physicalPath);
|
||||
$dh = opendir($physicalPath);
|
||||
while (($file = readdir($dh)) !== false) {
|
||||
if ($file === '.' or $file === '..') {
|
||||
continue;
|
||||
if(is_resource($dh)) {
|
||||
while (($file = readdir($dh)) !== false) {
|
||||
if ($file === '.' or $file === '..') {
|
||||
continue;
|
||||
}
|
||||
|
||||
$logicalFilePath = $this->mapper->physicalToLogic($physicalPath.'/'.$file);
|
||||
|
||||
$file= $this->mapper->stripRootFolder($logicalFilePath, $logicalPath);
|
||||
$file = $this->stripLeading($file);
|
||||
$files[]= $file;
|
||||
}
|
||||
|
||||
$logicalFilePath = $this->mapper->physicalToLogic($physicalPath.'/'.$file);
|
||||
|
||||
$file= $this->mapper->stripRootFolder($logicalFilePath, $logicalPath);
|
||||
$file = $this->stripLeading($file);
|
||||
$files[]= $file;
|
||||
}
|
||||
|
||||
\OC\Files\Stream\Dir::register('local-win32'.$path, $files);
|
||||
|
|
|
@ -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 . ')';
|
||||
|
|
|
@ -191,7 +191,8 @@ class OC_Migration_Content{
|
|||
if( !file_exists( $dir ) ) {
|
||||
return false;
|
||||
}
|
||||
if ($dirhandle = opendir($dir)) {
|
||||
$dirhandle = opendir($dir);
|
||||
if(is_resource($dirhandle)) {
|
||||
while (false !== ( $file = readdir($dirhandle))) {
|
||||
|
||||
if (( $file != '.' ) && ( $file != '..' )) {
|
||||
|
|
Loading…
Reference in New Issue