log a warning when trying to use a non basic fopen mode

Signed-off-by: Robin Appelman <robin@icewind.nl>
This commit is contained in:
Robin Appelman 2017-01-03 15:01:47 +01:00 committed by Roeland Jago Douma
parent 6a0f0403d0
commit 72a3ea6073
No known key found for this signature in database
GPG Key ID: F941078878347C0C
1 changed files with 11 additions and 14 deletions

View File

@ -931,39 +931,36 @@ class View {
/** /**
* @param string $path * @param string $path
* @param string $mode * @param string $mode 'r' or 'w'
* @return resource * @return resource
*/ */
public function fopen($path, $mode) { public function fopen($path, $mode) {
$mode = str_replace('b', '', $mode); // the binary flag is a windows only feature which we do not support
$hooks = array(); $hooks = array();
switch ($mode) { switch ($mode) {
case 'r': case 'r':
case 'rb':
$hooks[] = 'read'; $hooks[] = 'read';
break; break;
case 'r+': case 'r+':
case 'rb+':
case 'w+': case 'w+':
case 'wb+':
case 'x+': case 'x+':
case 'xb+':
case 'a+': case 'a+':
case 'ab+':
$hooks[] = 'read'; $hooks[] = 'read';
$hooks[] = 'write'; $hooks[] = 'write';
break; break;
case 'w': case 'w':
case 'wb':
case 'x': case 'x':
case 'xb':
case 'a': case 'a':
case 'ab':
$hooks[] = 'write'; $hooks[] = 'write';
break; break;
default: default:
\OCP\Util::writeLog('core', 'invalid mode (' . $mode . ') for ' . $path, \OCP\Util::ERROR); \OCP\Util::writeLog('core', 'invalid mode (' . $mode . ') for ' . $path, \OCP\Util::ERROR);
} }
if ($mode !== 'r' && $mode !== 'w') {
\OC::$server->getLogger()->info('Trying to open a file with a mode other than "r" or "w" can cause severe performance issues with some backends');
}
return $this->basicOperation('fopen', $path, $hooks, $mode); return $this->basicOperation('fopen', $path, $hooks, $mode);
} }
@ -1005,7 +1002,7 @@ class View {
// Create the directories if any // Create the directories if any
if (!$this->file_exists($filePath)) { if (!$this->file_exists($filePath)) {
$result = $this->createParentDirectories($filePath); $result = $this->createParentDirectories($filePath);
if($result === false) { if ($result === false) {
return false; return false;
} }
} }
@ -1357,7 +1354,7 @@ class View {
//add the sizes of other mount points to the folder //add the sizes of other mount points to the folder
$extOnly = ($includeMountPoints === 'ext'); $extOnly = ($includeMountPoints === 'ext');
$mounts = Filesystem::getMountManager()->findIn($path); $mounts = Filesystem::getMountManager()->findIn($path);
$info->setSubMounts(array_filter($mounts, function(IMountPoint $mount) use ($extOnly) { $info->setSubMounts(array_filter($mounts, function (IMountPoint $mount) use ($extOnly) {
$subStorage = $mount->getStorage(); $subStorage = $mount->getStorage();
return !($extOnly && $subStorage instanceof \OCA\Files_Sharing\SharedStorage); return !($extOnly && $subStorage instanceof \OCA\Files_Sharing\SharedStorage);
})); }));
@ -2106,13 +2103,13 @@ class View {
private function createParentDirectories($filePath) { private function createParentDirectories($filePath) {
$directoryParts = explode('/', $filePath); $directoryParts = explode('/', $filePath);
$directoryParts = array_filter($directoryParts); $directoryParts = array_filter($directoryParts);
foreach($directoryParts as $key => $part) { foreach ($directoryParts as $key => $part) {
$currentPathElements = array_slice($directoryParts, 0, $key); $currentPathElements = array_slice($directoryParts, 0, $key);
$currentPath = '/' . implode('/', $currentPathElements); $currentPath = '/' . implode('/', $currentPathElements);
if($this->is_file($currentPath)) { if ($this->is_file($currentPath)) {
return false; return false;
} }
if(!$this->file_exists($currentPath)) { if (!$this->file_exists($currentPath)) {
$this->mkdir($currentPath); $this->mkdir($currentPath);
} }
} }