more efficient write only fopen

Signed-off-by: Robin Appelman <robin@icewind.nl>
This commit is contained in:
Robin Appelman 2017-06-07 16:50:51 +02:00
parent 474c8aff29
commit f45a7a43df
No known key found for this signature in database
GPG Key ID: CBCA68FBAEBF98C9
1 changed files with 9 additions and 1 deletions

View File

@ -42,6 +42,7 @@ use Icewind\Streams\CallbackWrapper;
use Icewind\Streams\IteratorDirectory; use Icewind\Streams\IteratorDirectory;
use OC\Files\ObjectStore\S3ConnectionTrait; use OC\Files\ObjectStore\S3ConnectionTrait;
use OC\Files\ObjectStore\S3ObjectTrait; use OC\Files\ObjectStore\S3ObjectTrait;
use OCP\Constants;
class AmazonS3 extends \OC\Files\Storage\Common { class AmazonS3 extends \OC\Files\Storage\Common {
use S3ConnectionTrait; use S3ConnectionTrait;
@ -339,6 +340,12 @@ class AmazonS3 extends \OC\Files\Storage\Common {
} }
case 'w': case 'w':
case 'wb': case 'wb':
$tmpFile = \OCP\Files::tmpFile();
$handle = fopen($tmpFile, 'w');
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+':
@ -506,11 +513,12 @@ class AmazonS3 extends \OC\Files\Storage\Common {
public function writeBack($tmpFile, $path) { public function writeBack($tmpFile, $path) {
try { try {
$source = $this->fopen($tmpFile, 'r'); $source = fopen($tmpFile, 'r');
$this->writeObject($path, $source); $this->writeObject($path, $source);
fclose($source); fclose($source);
unlink($tmpFile); unlink($tmpFile);
return true;
} catch (S3Exception $e) { } catch (S3Exception $e) {
\OCP\Util::logException('files_external', $e); \OCP\Util::logException('files_external', $e);
return false; return false;