|
53 | 53 | use OC\Files\Storage\Wrapper\Wrapper; |
54 | 54 | use OCP\Files\EmptyFileNameException; |
55 | 55 | use OCP\Files\FileNameTooLongException; |
| 56 | +use OCP\Files\GenericFileException; |
56 | 57 | use OCP\Files\InvalidCharacterInPathException; |
57 | 58 | use OCP\Files\InvalidDirectoryException; |
58 | 59 | use OCP\Files\InvalidPathException; |
@@ -620,18 +621,19 @@ public function copyFromStorage(IStorage $sourceStorage, $sourceInternalPath, $t |
620 | 621 | } |
621 | 622 | } else { |
622 | 623 | $source = $sourceStorage->fopen($sourceInternalPath, 'r'); |
623 | | - // TODO: call fopen in a way that we execute again all storage wrappers |
624 | | - // to avoid that we bypass storage wrappers which perform important actions |
625 | | - // for this operation. Same is true for all other operations which |
626 | | - // are not the same as the original one.Once this is fixed we also |
627 | | - // need to adjust the encryption wrapper. |
628 | | - $target = $this->fopen($targetInternalPath, 'w'); |
629 | | - [, $result] = \OC_Helper::streamCopy($source, $target); |
| 624 | + $result = false; |
| 625 | + if ($source) { |
| 626 | + try { |
| 627 | + $this->writeStream($targetInternalPath, $source); |
| 628 | + $result = true; |
| 629 | + } catch (\Exception $e) { |
| 630 | + \OC::$server->getLogger()->logException($e, ['level' => ILogger::WARN, 'message' => 'Failed to copy stream to storage']); |
| 631 | + } |
| 632 | + } |
| 633 | + |
630 | 634 | if ($result and $preserveMtime) { |
631 | 635 | $this->touch($targetInternalPath, $sourceStorage->filemtime($sourceInternalPath)); |
632 | 636 | } |
633 | | - fclose($source); |
634 | | - fclose($target); |
635 | 637 |
|
636 | 638 | if (!$result) { |
637 | 639 | // delete partially written target file |
@@ -858,10 +860,13 @@ public function needsPartFile() { |
858 | 860 | public function writeStream(string $path, $stream, int $size = null): int { |
859 | 861 | $target = $this->fopen($path, 'w'); |
860 | 862 | if (!$target) { |
861 | | - return 0; |
| 863 | + throw new GenericFileException("Failed to open $path for writing"); |
862 | 864 | } |
863 | 865 | try { |
864 | 866 | [$count, $result] = \OC_Helper::streamCopy($stream, $target); |
| 867 | + if (!$result) { |
| 868 | + throw new GenericFileException("Failed to copy stream"); |
| 869 | + } |
865 | 870 | } finally { |
866 | 871 | fclose($target); |
867 | 872 | fclose($stream); |
|
0 commit comments