From f5dec3702bed1d113977c5c7be943cfa9d4d5d73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julius=20H=C3=A4rtl?= Date: Wed, 9 Sep 2020 09:46:44 +0200 Subject: [PATCH 1/2] Properly catch exception from writing to stream when copying a file MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Julius Härtl --- apps/dav/lib/Connector/Sabre/File.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/apps/dav/lib/Connector/Sabre/File.php b/apps/dav/lib/Connector/Sabre/File.php index 476824a2e3..36bcada017 100644 --- a/apps/dav/lib/Connector/Sabre/File.php +++ b/apps/dav/lib/Connector/Sabre/File.php @@ -51,6 +51,7 @@ use OCP\Encryption\Exceptions\GenericEncryptionException; use OCP\Files\EntityTooLargeException; use OCP\Files\FileInfo; use OCP\Files\ForbiddenException; +use OCP\Files\GenericFileException; use OCP\Files\InvalidContentException; use OCP\Files\InvalidPathException; use OCP\Files\LockNotAcquiredException; @@ -199,8 +200,14 @@ class File extends Node implements IFile { $isEOF = feof($stream); }); - $count = $partStorage->writeStream($internalPartPath, $wrappedData); - $result = $count > 0; + $result = true; + $count = -1; + try { + $count = $partStorage->writeStream($internalPartPath, $wrappedData); + } catch (GenericFileException $e) { + $result = false; + } + if ($result === false) { $result = $isEOF; From 407fb28cb6141941681b068320ebb5204ffdb529 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julius=20H=C3=A4rtl?= Date: Wed, 9 Sep 2020 09:51:38 +0200 Subject: [PATCH 2/2] Annotate that writeStream can throw a GenericFileException MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Julius Härtl --- lib/public/Files/Storage/IWriteStreamStorage.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/public/Files/Storage/IWriteStreamStorage.php b/lib/public/Files/Storage/IWriteStreamStorage.php index 24d6d7a1f9..319453d4bb 100644 --- a/lib/public/Files/Storage/IWriteStreamStorage.php +++ b/lib/public/Files/Storage/IWriteStreamStorage.php @@ -26,6 +26,8 @@ declare(strict_types=1); namespace OCP\Files\Storage; +use OCP\Files\GenericFileException; + /** * Interface that adds the ability to write a stream directly to file * @@ -39,6 +41,7 @@ interface IWriteStreamStorage extends IStorage { * @param resource $stream * @param int|null $size the size of the stream if known in advance * @return int the number of bytes written + * @throws GenericFileException * @since 15.0.0 */ public function writeStream(string $path, $stream, int $size = null): int;