diff options
author | Robin Appelman <robin@icewind.nl> | 2020-07-01 15:37:47 +0200 |
---|---|---|
committer | Robin Appelman <robin@icewind.nl> | 2020-07-31 17:33:10 +0200 |
commit | 98ca765572568640f17f917a0877944d0b9f57cb (patch) | |
tree | a7d789d03fb5b4be146d4312a98d98dc59629dcd | |
parent | e860507201dc68260dc8633046ab053a93586146 (diff) | |
download | nextcloud-server-98ca765572568640f17f917a0877944d0b9f57cb.tar.gz nextcloud-server-98ca765572568640f17f917a0877944d0b9f57cb.zip |
use exceptions for error signaling in writeStream
this remove the ambiguity when writing zero length files
Signed-off-by: Robin Appelman <robin@icewind.nl>
-rw-r--r-- | lib/private/Files/Storage/Common.php | 16 | ||||
-rw-r--r-- | lib/private/Files/Storage/Local.php | 8 | ||||
-rw-r--r-- | tests/lib/Files/ViewTest.php | 1 |
3 files changed, 19 insertions, 6 deletions
diff --git a/lib/private/Files/Storage/Common.php b/lib/private/Files/Storage/Common.php index 10941937a55..403864bbb1e 100644 --- a/lib/private/Files/Storage/Common.php +++ b/lib/private/Files/Storage/Common.php @@ -52,6 +52,7 @@ use OC\Files\Storage\Wrapper\Jail; use OC\Files\Storage\Wrapper\Wrapper; use OCP\Files\EmptyFileNameException; use OCP\Files\FileNameTooLongException; +use OCP\Files\GenericFileException; use OCP\Files\InvalidCharacterInPathException; use OCP\Files\InvalidDirectoryException; use OCP\Files\InvalidPathException; @@ -618,10 +619,14 @@ abstract class Common implements Storage, ILockingStorage, IWriteStreamStorage { } } else { $source = $sourceStorage->fopen($sourceInternalPath, 'r'); + $result = false; if ($source) { - $result = $this->writeStream($targetInternalPath, $source) > 0; - } else { - $result = false; + try { + $this->writeStream($targetInternalPath, $source); + $result = true; + } catch (\Exception $e) { + \OC::$server->getLogger()->logException($e, ['level' => ILogger::WARN, 'message' => 'Failed to copy stream to storage']); + } } if ($result and $preserveMtime) { @@ -852,10 +857,13 @@ abstract class Common implements Storage, ILockingStorage, IWriteStreamStorage { public function writeStream(string $path, $stream, int $size = null): int { $target = $this->fopen($path, 'w'); if (!$target) { - return 0; + throw new GenericFileException("Failed to open $path for writing"); } try { [$count, $result] = \OC_Helper::streamCopy($stream, $target); + if (!$result) { + throw new GenericFileException("Failed to copy stream"); + } } finally { fclose($target); fclose($stream); diff --git a/lib/private/Files/Storage/Local.php b/lib/private/Files/Storage/Local.php index 13a3ca87097..5f86c5b75f8 100644 --- a/lib/private/Files/Storage/Local.php +++ b/lib/private/Files/Storage/Local.php @@ -43,6 +43,7 @@ namespace OC\Files\Storage; use OC\Files\Filesystem; use OC\Files\Storage\Wrapper\Jail; use OCP\Files\ForbiddenException; +use OCP\Files\GenericFileException; use OCP\Files\Storage\IStorage; use OCP\ILogger; @@ -500,6 +501,11 @@ class Local extends \OC\Files\Storage\Common { } public function writeStream(string $path, $stream, int $size = null): int { - return (int)file_put_contents($this->getSourcePath($path), $stream); + $result = file_put_contents($this->getSourcePath($path), $stream); + if ($result === false) { + throw new GenericFileException("Failed write steam to $path"); + } else { + return $result; + } } } diff --git a/tests/lib/Files/ViewTest.php b/tests/lib/Files/ViewTest.php index e394e0a8651..ea35b560877 100644 --- a/tests/lib/Files/ViewTest.php +++ b/tests/lib/Files/ViewTest.php @@ -13,7 +13,6 @@ use OC\Files\Filesystem; use OC\Files\Mount\MountPoint; use OC\Files\Storage\Common; use OC\Files\Storage\Temporary; -use OC\Files\Stream\Quota; use OC\Files\View; use OCP\Files\Config\IMountProvider; use OCP\Files\FileInfo; |