|
23 | 23 | use OCP\AppFramework\Db\DoesNotExistException; |
24 | 24 | use OCP\Command\IBus; |
25 | 25 | use OCP\EventDispatcher\IEventDispatcher; |
| 26 | +use OCP\Files; |
26 | 27 | use OCP\Files\FileInfo; |
27 | 28 | use OCP\Files\Folder; |
28 | 29 | use OCP\Files\IMimeTypeDetector; |
|
32 | 33 | use OCP\Files\NotPermittedException; |
33 | 34 | use OCP\Files\Search\ISearchBinaryOperator; |
34 | 35 | use OCP\Files\Search\ISearchComparison; |
| 36 | +use OCP\Files\Storage\IWriteStreamStorage; |
35 | 37 | use OCP\Files\StorageInvalidException; |
36 | 38 | use OCP\Files\StorageNotAvailableException; |
37 | 39 | use OCP\IURLGenerator; |
@@ -416,12 +418,25 @@ private static function copyFileContents($view, $path1, $path2) { |
416 | 418 |
|
417 | 419 | try { |
418 | 420 | // TODO add a proper way of overwriting a file while maintaining file ids |
419 | | - if ($storage1->instanceOfStorage('\OC\Files\ObjectStore\ObjectStoreStorage') || $storage2->instanceOfStorage('\OC\Files\ObjectStore\ObjectStoreStorage')) { |
| 421 | + if ($storage1->instanceOfStorage(\OC\Files\ObjectStore\ObjectStoreStorage::class) |
| 422 | + || $storage2->instanceOfStorage(\OC\Files\ObjectStore\ObjectStoreStorage::class) |
| 423 | + ) { |
420 | 424 | $source = $storage1->fopen($internalPath1, 'r'); |
421 | | - $target = $storage2->fopen($internalPath2, 'w'); |
422 | | - [, $result] = \OC_Helper::streamCopy($source, $target); |
423 | | - fclose($source); |
424 | | - fclose($target); |
| 425 | + $result = $source !== false; |
| 426 | + if ($result) { |
| 427 | + if ($storage2->instanceOfStorage(IWriteStreamStorage::class)) { |
| 428 | + /** @var IWriteStreamStorage $storage2 */ |
| 429 | + $storage2->writeStream($internalPath2, $source); |
| 430 | + } else { |
| 431 | + $target = $storage2->fopen($internalPath2, 'w'); |
| 432 | + $result = $target !== false; |
| 433 | + if ($target !== false) { |
| 434 | + [, $result] = Files::streamCopy($source, $target, true); |
| 435 | + fclose($target); |
| 436 | + } |
| 437 | + } |
| 438 | + fclose($source); |
| 439 | + } |
425 | 440 |
|
426 | 441 | if ($result !== false) { |
427 | 442 | $storage1->unlink($internalPath1); |
|
0 commit comments