aboutsummaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
authorFerdinand Thiessen <opensource@fthiessen.de>2025-05-17 12:01:44 +0200
committerGitHub <noreply@github.com>2025-05-17 12:01:44 +0200
commite2a331f53d05cfd4254b8b8e1b806264dad134da (patch)
tree43959e0ea51c69808c654084d77d2a784ee57397 /apps
parent0c2934e885f77284b2923dcf6a43d0f39727c2c3 (diff)
parent0f69648d0ade5b2d8bbf24e1a7bf520b4722e5e5 (diff)
downloadnextcloud-server-master.tar.gz
nextcloud-server-master.zip
Merge pull request #52890 from nextcloud/chore/move-stream-copy-implementationHEADmaster
chore: move streamCopy implementation from `OC_Helper` to `OCP\Files`
Diffstat (limited to 'apps')
-rw-r--r--apps/dav/lib/Connector/Sabre/File.php3
-rw-r--r--apps/files_versions/lib/Storage.php25
2 files changed, 22 insertions, 6 deletions
diff --git a/apps/dav/lib/Connector/Sabre/File.php b/apps/dav/lib/Connector/Sabre/File.php
index 045b9d7e784..98e0f2e9e4b 100644
--- a/apps/dav/lib/Connector/Sabre/File.php
+++ b/apps/dav/lib/Connector/Sabre/File.php
@@ -19,6 +19,7 @@ use OCA\DAV\Connector\Sabre\Exception\Forbidden as DAVForbiddenException;
use OCA\DAV\Connector\Sabre\Exception\UnsupportedMediaType;
use OCP\App\IAppManager;
use OCP\Encryption\Exceptions\GenericEncryptionException;
+use OCP\Files;
use OCP\Files\EntityTooLargeException;
use OCP\Files\FileInfo;
use OCP\Files\ForbiddenException;
@@ -229,7 +230,7 @@ class File extends Node implements IFile {
// because we have no clue about the cause we can only throw back a 500/Internal Server Error
throw new Exception($this->l10n->t('Could not write file contents'));
}
- [$count, $result] = \OC_Helper::streamCopy($data, $target);
+ [$count, $result] = Files::streamCopy($data, $target, true);
fclose($target);
}
diff --git a/apps/files_versions/lib/Storage.php b/apps/files_versions/lib/Storage.php
index 19e7dd598ae..4b58d721583 100644
--- a/apps/files_versions/lib/Storage.php
+++ b/apps/files_versions/lib/Storage.php
@@ -23,6 +23,7 @@ use OCA\Files_Versions\Versions\IVersionManager;
use OCP\AppFramework\Db\DoesNotExistException;
use OCP\Command\IBus;
use OCP\EventDispatcher\IEventDispatcher;
+use OCP\Files;
use OCP\Files\FileInfo;
use OCP\Files\Folder;
use OCP\Files\IMimeTypeDetector;
@@ -32,6 +33,7 @@ use OCP\Files\NotFoundException;
use OCP\Files\NotPermittedException;
use OCP\Files\Search\ISearchBinaryOperator;
use OCP\Files\Search\ISearchComparison;
+use OCP\Files\Storage\IWriteStreamStorage;
use OCP\Files\StorageInvalidException;
use OCP\Files\StorageNotAvailableException;
use OCP\IURLGenerator;
@@ -416,12 +418,25 @@ class Storage {
try {
// TODO add a proper way of overwriting a file while maintaining file ids
- if ($storage1->instanceOfStorage('\OC\Files\ObjectStore\ObjectStoreStorage') || $storage2->instanceOfStorage('\OC\Files\ObjectStore\ObjectStoreStorage')) {
+ if ($storage1->instanceOfStorage(\OC\Files\ObjectStore\ObjectStoreStorage::class)
+ || $storage2->instanceOfStorage(\OC\Files\ObjectStore\ObjectStoreStorage::class)
+ ) {
$source = $storage1->fopen($internalPath1, 'r');
- $target = $storage2->fopen($internalPath2, 'w');
- [, $result] = \OC_Helper::streamCopy($source, $target);
- fclose($source);
- fclose($target);
+ $result = $source !== false;
+ if ($result) {
+ if ($storage2->instanceOfStorage(IWriteStreamStorage::class)) {
+ /** @var IWriteStreamStorage $storage2 */
+ $storage2->writeStream($internalPath2, $source);
+ } else {
+ $target = $storage2->fopen($internalPath2, 'w');
+ $result = $target !== false;
+ if ($target !== false) {
+ [, $result] = Files::streamCopy($source, $target, true);
+ fclose($target);
+ }
+ }
+ fclose($source);
+ }
if ($result !== false) {
$storage1->unlink($internalPath1);