mirror of
https://github.com/nextcloud/server.git
synced 2026-04-15 22:11:17 -04:00
refactor(dav): simplify length header handling
Reduce nesting and drop duplicated sections. Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
This commit is contained in:
parent
9bc3368f97
commit
15726db205
1 changed files with 25 additions and 31 deletions
|
|
@ -230,42 +230,36 @@ class File extends Node implements IFile {
|
|||
fclose($target);
|
||||
}
|
||||
|
||||
if ($result === false) {
|
||||
$expected = -1;
|
||||
$lengthHeader = $this->request->getHeader('content-length');
|
||||
if ($lengthHeader) {
|
||||
$expected = (int)$lengthHeader;
|
||||
}
|
||||
if ($expected !== 0) {
|
||||
throw new Exception(
|
||||
$this->l10n->t(
|
||||
'Error while copying file to target location (copied: %1$s, expected filesize: %2$s)',
|
||||
[
|
||||
$this->l10n->n('%n byte', '%n bytes', $count),
|
||||
$this->l10n->n('%n byte', '%n bytes', $expected),
|
||||
],
|
||||
)
|
||||
);
|
||||
}
|
||||
$lengthHeader = $this->request->getHeader('content-length');
|
||||
$expected = $lengthHeader !== '' ? (int)$lengthHeader : -1;
|
||||
if ($result === false && $expected >= 0) {
|
||||
throw new Exception(
|
||||
$this->l10n->t(
|
||||
'Error while copying file to target location (copied: %1$s, expected filesize: %2$s)',
|
||||
[
|
||||
$this->l10n->n('%n byte', '%n bytes', $count),
|
||||
$this->l10n->n('%n byte', '%n bytes', $expected),
|
||||
],
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
// if content length is sent by client:
|
||||
// double check if the file was fully received
|
||||
// compare expected and actual size
|
||||
$lengthHeader = $this->request->getHeader('content-length');
|
||||
if ($lengthHeader && $this->request->getMethod() === 'PUT') {
|
||||
$expected = (int)$lengthHeader;
|
||||
if ($count !== $expected) {
|
||||
throw new BadRequest(
|
||||
$this->l10n->t(
|
||||
'Expected filesize of %1$s but read (from Nextcloud client) and wrote (to Nextcloud storage) %2$s. Could either be a network problem on the sending side or a problem writing to the storage on the server side.',
|
||||
[
|
||||
$this->l10n->n('%n byte', '%n bytes', $expected),
|
||||
$this->l10n->n('%n byte', '%n bytes', $count),
|
||||
],
|
||||
)
|
||||
);
|
||||
}
|
||||
if ($expected >= 0
|
||||
&& $expected !== $count
|
||||
&& $this->request->getMethod() === 'PUT'
|
||||
) {
|
||||
throw new BadRequest(
|
||||
$this->l10n->t(
|
||||
'Expected filesize of %1$s but read (from Nextcloud client) and wrote (to Nextcloud storage) %2$s. Could either be a network problem on the sending side or a problem writing to the storage on the server side.',
|
||||
[
|
||||
$this->l10n->n('%n byte', '%n bytes', $expected),
|
||||
$this->l10n->n('%n byte', '%n bytes', $count),
|
||||
],
|
||||
)
|
||||
);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
if ($e instanceof LockedException) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue