summaryrefslogtreecommitdiffstats
path: root/lib/private/Files/Storage/Common.php
diff options
context:
space:
mode:
authorRobin Appelman <robin@icewind.nl>2018-10-26 19:15:23 +0200
committerRobin Appelman <robin@icewind.nl>2018-10-31 21:10:44 +0100
commit93de63777e4a519484ad8f50f7a8ee809697c20a (patch)
tree9a2d670e0eedf42bc7aaf38cf5dfcd53c78c94c2 /lib/private/Files/Storage/Common.php
parent3c442e4138883f45a8ab123f8405017e7a99e283 (diff)
downloadnextcloud-server-93de63777e4a519484ad8f50f7a8ee809697c20a.tar.gz
nextcloud-server-93de63777e4a519484ad8f50f7a8ee809697c20a.zip
extend storage api to allow directly writing a stream to storage
this removes the need for temporary storages with some external storage backends. The new method is added to a separate interface to maintain compatibility with storage backends implementing the storage interface directly (without inheriting common) Currently the interface is implemented for objectstorage based storages and local storage and used by webdav uploads Signed-off-by: Robin Appelman <robin@icewind.nl>
Diffstat (limited to 'lib/private/Files/Storage/Common.php')
-rw-r--r--lib/private/Files/Storage/Common.php19
1 files changed, 18 insertions, 1 deletions
diff --git a/lib/private/Files/Storage/Common.php b/lib/private/Files/Storage/Common.php
index b6c82f3a1df..6324050b472 100644
--- a/lib/private/Files/Storage/Common.php
+++ b/lib/private/Files/Storage/Common.php
@@ -54,6 +54,7 @@ use OCP\Files\InvalidPathException;
use OCP\Files\ReservedWordException;
use OCP\Files\Storage\ILockingStorage;
use OCP\Files\Storage\IStorage;
+use OCP\Files\Storage\IWriteStreamStorage;
use OCP\ILogger;
use OCP\Lock\ILockingProvider;
use OCP\Lock\LockedException;
@@ -69,7 +70,7 @@ use OCP\Lock\LockedException;
* Some \OC\Files\Storage\Common methods call functions which are first defined
* in classes which extend it, e.g. $this->stat() .
*/
-abstract class Common implements Storage, ILockingStorage {
+abstract class Common implements Storage, ILockingStorage, IWriteStreamStorage {
use LocalTempFileTrait;
@@ -809,4 +810,20 @@ abstract class Common implements Storage, ILockingStorage {
public function needsPartFile() {
return true;
}
+
+ /**
+ * fallback implementation
+ *
+ * @param string $path
+ * @param resource $stream
+ * @param int $size
+ * @return int
+ */
+ public function writeStream(string $path, $stream, int $size = null): int {
+ $target = $this->fopen($path, 'w');
+ list($count, $result) = \OC_Helper::streamCopy($stream, $target);
+ fclose($stream);
+ fclose($target);
+ return $count;
+ }
}