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 d70607104e
commit 9b5accf9f3
No known key found for this signature in database
GPG key ID: CBCA68FBAEBF98C9

View file

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