-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Fix] Abort Streamer-processing when user-connection aborted #42352
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -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; | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
// Close file-stream when user-connection closed | ||||||||||
$stream = CallbackWrapper::wrap($stream, | ||||||||||
|
||||||||||
function ($count) use ($stream) { | ||||||||||
if (connection_status() !== CONNECTION_NORMAL) { | ||||||||||
fclose($stream); | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm unsure if closing the stream inside the read callback is a good idea. I suggested using exceptions to bubble up the state properly here: #8161 (comment) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. mhh, I thought we can handle this gracefully. In this case e.g. ZipStreamer doesnt catch exceptions so they just bubble to the top and then after everything finished the file is closed by PHP garbage collection. If we want an exception (so we force cleanup, if any, to execute) we should be consistent and do this in any other case aswell. What do you think? |
||||||||||
} | ||||||||||
}); | ||||||||||
|
||||||||||
$options = []; | ||||||||||
if ($time) { | ||||||||||
$options = [ | ||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can even skip the
=== 1
:Same for the following calls to
connection_status