Skip to content

Commit b5fce71

Browse files
committed
fix(FileInfo): Ensure getChecksum doesn't return null
Same for getETag Signed-off-by: Carl Schwan <[email protected]>
1 parent 4168379 commit b5fce71

File tree

4 files changed

+8
-8
lines changed

4 files changed

+8
-8
lines changed

apps/dav/lib/Connector/Sabre/File.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ public function put($data) {
362362
if ($checksumHeader) {
363363
$checksum = trim($checksumHeader);
364364
$this->setChecksum($checksum);
365-
} elseif ($this->getChecksum() !== null && $this->getChecksum() !== '') {
365+
} elseif ($this->getChecksum() !== '') {
366366
$this->setChecksum('');
367367
}
368368
} catch (StorageNotAvailableException $e) {
@@ -599,10 +599,8 @@ private function convertToSabreException(\Exception $e) {
599599

600600
/**
601601
* Get the checksum for this file
602-
*
603-
* @return string|null
604602
*/
605-
public function getChecksum() {
603+
public function getChecksum(): string {
606604
return $this->info->getChecksum();
607605
}
608606

apps/dav/lib/Connector/Sabre/FilesPlugin.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ public function httpGet(RequestInterface $request, ResponseInterface $response)
276276
if ($node instanceof File) {
277277
//Add OC-Checksum header
278278
$checksum = $node->getChecksum();
279-
if ($checksum !== null && $checksum !== '') {
279+
if ($checksum !== '') {
280280
$response->addHeader('OC-Checksum', $checksum);
281281
}
282282
}
@@ -487,7 +487,7 @@ public function handleGetProperties(PropFind $propFind, \Sabre\DAV\INode $node)
487487

488488
$propFind->handle(self::CHECKSUMS_PROPERTYNAME, function () use ($node) {
489489
$checksum = $node->getChecksum();
490-
if ($checksum === null || $checksum === '') {
490+
if ($checksum === '') {
491491
return null;
492492
}
493493

lib/private/Files/FileInfo.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ public function getEtag(): string {
117117
$combinedEtag = $this->data['etag'] . '::' . implode('::', $this->childEtags);
118118
return md5($combinedEtag);
119119
} else {
120-
return $this->data['etag'];
120+
return $this->data['etag'] ?? '';
121121
}
122122
}
123123

@@ -283,7 +283,7 @@ public function addSubEntry(array|ICacheEntry|false $data, string $entryPath): v
283283

284284
#[Override]
285285
public function getChecksum(): string {
286-
return $this->data['checksum'];
286+
return $this->data['checksum'] ?? '';
287287
}
288288

289289
#[Override]

lib/public/Files/FileInfo.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,8 @@ public function getOwner(): ?IUser;
255255
* Checksums are stored in the format TYPE:CHECKSUM, here may be multiple checksums separated by a single space
256256
* e.g. MD5:d3b07384d113edec49eaa6238ad5ff00 SHA1:f1d2d2f924e986ac86fdf7b36c94bcdf32beec15
257257
*
258+
* @note This will return an empty string if no checksum is currently stored.
259+
*
258260
* @since 9.0.0
259261
*/
260262
public function getChecksum(): string;

0 commit comments

Comments
 (0)