From 845693582fb5f12101cad051bd82222dc137205f Mon Sep 17 00:00:00 2001 From: Ferdinand Thiessen Date: Tue, 18 Feb 2025 16:41:10 +0100 Subject: [PATCH] fix(dav): Handle end of stream in `File::put` If the stream is aborted and the callback wrapper returns false (or null as it happened in some cases), we should not try to write to the storage but abort the operation. Signed-off-by: Ferdinand Thiessen --- apps/dav/lib/Connector/Sabre/File.php | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/apps/dav/lib/Connector/Sabre/File.php b/apps/dav/lib/Connector/Sabre/File.php index 13cf8d5b0c027..115817575903d 100644 --- a/apps/dav/lib/Connector/Sabre/File.php +++ b/apps/dav/lib/Connector/Sabre/File.php @@ -13,7 +13,6 @@ use OC\Files\Stream\HashWrapper; use OC\Files\View; use OCA\DAV\AppInfo\Application; -use OCA\DAV\Connector\Sabre\Exception\BadGateway; use OCA\DAV\Connector\Sabre\Exception\EntityTooLarge; use OCA\DAV\Connector\Sabre\Exception\FileLocked; use OCA\DAV\Connector\Sabre\Exception\Forbidden as DAVForbiddenException; @@ -209,21 +208,17 @@ public function put($data) { $isEOF = feof($stream); }); - $result = true; - $count = -1; - try { - $count = $partStorage->writeStream($internalPartPath, $wrappedData); - } catch (GenericFileException $e) { - $result = false; - } catch (BadGateway $e) { - throw $e; - } - - - if ($result === false) { - $result = $isEOF; - if (is_resource($wrappedData)) { - $result = feof($wrappedData); + $result = is_resource($wrappedData); + if ($result) { + $count = -1; + try { + /** @var IWriteStreamStorage $partStorage */ + $count = $partStorage->writeStream($internalPartPath, $wrappedData); + } catch (GenericFileException) { + $result = $isEOF; + if (is_resource($wrappedData)) { + $result = feof($wrappedData); + } } } } else {