From 4a00f33350a922f67b4de1f4db60215cc5296e32 Mon Sep 17 00:00:00 2001 From: Alexander Brandscheidt Date: Mon, 18 Dec 2023 11:34:05 +0100 Subject: [PATCH] Abort processing when user-connection aborted Signed-off-by: Alexander Brandscheidt --- lib/private/Streamer.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/lib/private/Streamer.php b/lib/private/Streamer.php index aafd3d95dfbcb..8b9ae5ff583e4 100644 --- a/lib/private/Streamer.php +++ b/lib/private/Streamer.php @@ -28,6 +28,7 @@ */ namespace OC; +use Icewind\Streams\CallBackWrapper; use OC\Files\Filesystem; use OCP\Files\File; use OCP\Files\Folder; @@ -126,6 +127,7 @@ public function addDirRecursive(string $dir, string $internalDir = ''): void { /** @var LoggerInterface $logger */ $logger = \OC::$server->query(LoggerInterface::class); foreach ($files as $file) { + if(connection_status() !== CONNECTION_NORMAL) return; if ($file instanceof File) { try { $fh = $file->fopen('r'); @@ -161,6 +163,15 @@ public function addDirRecursive(string $dir, string $internalDir = ''): void { * @return bool $success */ public function addFileFromStream($stream, string $internalName, int|float $size, $time): bool { + if(connection_status() !== CONNECTION_NORMAL) return false; + // Close file-stream when user-connection closed + $stream = CallbackWrapper::wrap($stream, + function ($count) use ($stream) { + if (connection_status() !== CONNECTION_NORMAL) { + fclose($stream); + } + }); + $options = []; if ($time) { $options = [