Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Make written byte counter variable name more obvious
Signed-off-by: Julius Härtl <[email protected]>
  • Loading branch information
juliusknorr committed Dec 22, 2022
commit 59275e2c2fd8feb7c38d362e769321b51b0cd44c
14 changes: 7 additions & 7 deletions apps/dav/lib/Connector/Sabre/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -244,9 +244,9 @@ public function put($data) {
});

$result = true;
$count = -1;
$writtenByteCount = -1;
try {
$count = $partStorage->writeStream($internalPartPath, $wrappedData);
$writtenByteCount = $partStorage->writeStream($internalPartPath, $wrappedData);

Check notice

Code scanning / Psalm

PossiblyInvalidArgument

Argument 2 of OCP\Files\Storage\IWriteStreamStorage::writeStream expects resource, possibly different type bool|resource provided
} catch (GenericFileException $e) {
$result = false;
} catch (BadGateway $e) {
Expand All @@ -267,7 +267,7 @@ public function put($data) {
// because we have no clue about the cause we can only throw back a 500/Internal Server Error
throw new Exception($this->l10n->t('Could not write file contents'));
}
[$count, $result] = \OC_Helper::streamCopy($data, $target);
[$writtenByteCount, $result] = \OC_Helper::streamCopy($data, $target);

Check notice

Code scanning / Psalm

PossiblyInvalidArgument

Argument 2 of OC_Helper::streamCopy expects resource, possibly different type resource|true provided
fclose($target);
}

Expand All @@ -281,7 +281,7 @@ public function put($data) {
$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', $writtenByteCount),
$this->l10n->n('%n byte', '%n bytes', $expected),
],
)
Expand All @@ -294,13 +294,13 @@ public function put($data) {
// compare expected and actual size
if (isset($_SERVER['CONTENT_LENGTH']) && $_SERVER['REQUEST_METHOD'] === 'PUT') {
$expected = (int)$_SERVER['CONTENT_LENGTH'];
if ($count !== $expected) {
if ($writtenByteCount !== $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),
$this->l10n->n('%n byte', '%n bytes', $writtenByteCount),
],
)
);
Expand Down Expand Up @@ -366,7 +366,7 @@ public function put($data) {
}

// since we skipped the view we need to scan and emit the hooks ourselves
$storage->getUpdater()->update($internalPath, null, ($count-$previousFileSize));
$storage->getUpdater()->update($internalPath, null, ($writtenByteCount - $previousFileSize));

try {
$this->changeLock(ILockingProvider::LOCK_SHARED);
Expand Down