Merge pull request #8711 from nextcloud/objectstore-write-only-fopen

don't read existing file when overwriting using object store
This commit is contained in:
Morris Jobke 2018-03-08 09:32:39 +01:00 committed by GitHub
commit 069e3f50a7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 13 additions and 7 deletions

View File

@ -261,6 +261,12 @@ class ObjectStoreStorage extends \OC\Files\Storage\Common {
public function fopen($path, $mode) { public function fopen($path, $mode) {
$path = $this->normalizePath($path); $path = $this->normalizePath($path);
if (strrpos($path, '.') !== false) {
$ext = substr($path, strrpos($path, '.'));
} else {
$ext = '';
}
switch ($mode) { switch ($mode) {
case 'r': case 'r':
case 'rb': case 'rb':
@ -280,21 +286,21 @@ class ObjectStoreStorage extends \OC\Files\Storage\Common {
} }
case 'w': case 'w':
case 'wb': case 'wb':
case 'w+':
case 'wb+':
$tmpFile = \OC::$server->getTempManager()->getTemporaryFile($ext);
$handle = fopen($tmpFile, $mode);
return CallbackWrapper::wrap($handle, null, null, function () use ($path, $tmpFile) {
$this->writeBack($tmpFile, $path);
});
case 'a': case 'a':
case 'ab': case 'ab':
case 'r+': case 'r+':
case 'w+':
case 'wb+':
case 'a+': case 'a+':
case 'x': case 'x':
case 'x+': case 'x+':
case 'c': case 'c':
case 'c+': case 'c+':
if (strrpos($path, '.') !== false) {
$ext = substr($path, strrpos($path, '.'));
} else {
$ext = '';
}
$tmpFile = \OC::$server->getTempManager()->getTemporaryFile($ext); $tmpFile = \OC::$server->getTempManager()->getTemporaryFile($ext);
if ($this->file_exists($path)) { if ($this->file_exists($path)) {
$source = $this->fopen($path, 'r'); $source = $this->fopen($path, 'r');