mirror of
https://github.com/nextcloud/server.git
synced 2026-06-08 16:26:59 -04:00
Detect aborted connection in OC\Files\View and stop writing data to the
output buffer Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
This commit is contained in:
parent
79c2353d7f
commit
cb2a6d688f
2 changed files with 10 additions and 5 deletions
|
|
@ -428,6 +428,7 @@ class View {
|
|||
$chunkSize = 524288; // 512 kB chunks
|
||||
while (!feof($handle)) {
|
||||
echo fread($handle, $chunkSize);
|
||||
$this->checkConnectionStatus();
|
||||
flush();
|
||||
}
|
||||
fclose($handle);
|
||||
|
|
@ -480,6 +481,7 @@ class View {
|
|||
$len = $chunkSize;
|
||||
}
|
||||
echo fread($handle, $len);
|
||||
$this->checkConnectionStatus();
|
||||
flush();
|
||||
}
|
||||
return ftell($handle) - $from;
|
||||
|
|
@ -490,6 +492,14 @@ class View {
|
|||
return false;
|
||||
}
|
||||
|
||||
|
||||
private function checkConnectionStatus(): void {
|
||||
$connectionStatus = \connection_status();
|
||||
if ($connectionStatus !== 0) {
|
||||
throw new \RuntimeException("Connection lost. Status: $connectionStatus");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $path
|
||||
* @return mixed
|
||||
|
|
@ -1053,7 +1063,6 @@ class View {
|
|||
public function fromTmpFile($tmpFile, $path) {
|
||||
$this->assertPathLength($path);
|
||||
if (Filesystem::isValidPath($path)) {
|
||||
|
||||
// Get directory that the file is going into
|
||||
$filePath = dirname($path);
|
||||
|
||||
|
|
@ -1809,7 +1818,6 @@ class View {
|
|||
* @return boolean
|
||||
*/
|
||||
private function targetIsNotShared(IStorage $targetStorage, string $targetInternalPath) {
|
||||
|
||||
// note: cannot use the view because the target is already locked
|
||||
$fileId = (int)$targetStorage->getCache()->getId($targetInternalPath);
|
||||
if ($fileId === -1) {
|
||||
|
|
|
|||
|
|
@ -238,9 +238,6 @@ class OC_Files {
|
|||
OC::$server->getLogger()->logException($ex);
|
||||
$l = \OC::$server->getL10N('lib');
|
||||
$hint = method_exists($ex, 'getHint') ? $ex->getHint() : '';
|
||||
if ($event && $event->getErrorMessage() !== null) {
|
||||
$hint .= ' ' . $event->getErrorMessage();
|
||||
}
|
||||
\OC_Template::printErrorPage($l->t('Cannot download file'), $hint, 200);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue