summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorRobin Appelman <robin@icewind.nl>2017-01-05 14:49:55 +0100
committerGitHub <noreply@github.com>2017-01-05 14:49:55 +0100
commitcb32d21682624f2752823bccb90247d46a9eecfb (patch)
tree4dee4f252b9fcf3c5db0e25af5bddffeb2d10141 /lib
parent9e95a89ab7d84f5b15e3b60880ec78ece9de0856 (diff)
parent72a3ea6073b19c1c4241daf5bcc5aa2d383e0f8d (diff)
downloadnextcloud-server-cb32d21682624f2752823bccb90247d46a9eecfb.tar.gz
nextcloud-server-cb32d21682624f2752823bccb90247d46a9eecfb.zip
Merge pull request #2922 from nextcloud/fopen-only-simple-modes
log a warning when trying to use a non basic fopen mode
Diffstat (limited to 'lib')
-rw-r--r--lib/private/Files/View.php25
1 files changed, 11 insertions, 14 deletions
diff --git a/lib/private/Files/View.php b/lib/private/Files/View.php
index 6facc7b9462..909c49197b8 100644
--- a/lib/private/Files/View.php
+++ b/lib/private/Files/View.php
@@ -931,39 +931,36 @@ class View {
/**
* @param string $path
- * @param string $mode
+ * @param string $mode 'r' or 'w'
* @return resource
*/
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();
switch ($mode) {
case 'r':
- case 'rb':
$hooks[] = 'read';
break;
case 'r+':
- case 'rb+':
case 'w+':
- case 'wb+':
case 'x+':
- case 'xb+':
case 'a+':
- case 'ab+':
$hooks[] = 'read';
$hooks[] = 'write';
break;
case 'w':
- case 'wb':
case 'x':
- case 'xb':
case 'a':
- case 'ab':
$hooks[] = 'write';
break;
default:
\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);
}
@@ -1005,7 +1002,7 @@ class View {
// Create the directories if any
if (!$this->file_exists($filePath)) {
$result = $this->createParentDirectories($filePath);
- if($result === false) {
+ if ($result === false) {
return false;
}
}
@@ -1357,7 +1354,7 @@ class View {
//add the sizes of other mount points to the folder
$extOnly = ($includeMountPoints === 'ext');
$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();
return !($extOnly && $subStorage instanceof \OCA\Files_Sharing\SharedStorage);
}));
@@ -2106,13 +2103,13 @@ class View {
private function createParentDirectories($filePath) {
$directoryParts = explode('/', $filePath);
$directoryParts = array_filter($directoryParts);
- foreach($directoryParts as $key => $part) {
+ foreach ($directoryParts as $key => $part) {
$currentPathElements = array_slice($directoryParts, 0, $key);
$currentPath = '/' . implode('/', $currentPathElements);
- if($this->is_file($currentPath)) {
+ if ($this->is_file($currentPath)) {
return false;
}
- if(!$this->file_exists($currentPath)) {
+ if (!$this->file_exists($currentPath)) {
$this->mkdir($currentPath);
}
}