Skip to content
Merged
Show file tree
Hide file tree
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
fix(Storage): Fix IStorage return types
Signed-off-by: provokateurin <[email protected]>
  • Loading branch information
provokateurin committed Sep 26, 2024
commit 7cdccd058f98a5e4164fc314f06f62fd8dfcd73c
47 changes: 3 additions & 44 deletions build/psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -935,9 +935,6 @@
<InvalidNullableReturnType>
<code><![CDATA[ICacheEntry]]></code>
</InvalidNullableReturnType>
<InvalidReturnStatement>
<code><![CDATA[new FailedCache()]]></code>
</InvalidReturnStatement>
<NullableReturnStatement>
<code><![CDATA[$this->sourceRootInfo]]></code>
</NullableReturnStatement>
Expand Down Expand Up @@ -2099,10 +2096,6 @@
<code><![CDATA[!$permissions]]></code>
<code><![CDATA[$this->copyFromStorage($sourceStorage, $sourceInternalPath . '/' . $file, $targetInternalPath . '/' . $file)]]></code>
</InvalidOperand>
<NoInterfaceProperties>
<code><![CDATA[$storage->scanner]]></code>
<code><![CDATA[$storage->scanner]]></code>
</NoInterfaceProperties>
</file>
<file src="lib/private/Files/Storage/DAV.php">
<InvalidClass>
Expand All @@ -2116,16 +2109,6 @@
<code><![CDATA[fopen]]></code>
</InvalidReturnType>
</file>
<file src="lib/private/Files/Storage/FailedStorage.php">
<InvalidReturnStatement>
<code><![CDATA[new FailedCache()]]></code>
<code><![CDATA[true]]></code>
</InvalidReturnStatement>
<InvalidReturnType>
<code><![CDATA[getCache]]></code>
<code><![CDATA[verifyPath]]></code>
</InvalidReturnType>
</file>
<file src="lib/private/Files/Storage/Local.php">
<TypeDoesNotContainNull>
<code><![CDATA[$space === false || is_null($space)]]></code>
Expand Down Expand Up @@ -2169,16 +2152,12 @@
</file>
<file src="lib/private/Files/Storage/Wrapper/Encryption.php">
<InvalidOperand>
<code><![CDATA[$result]]></code>
<code><![CDATA[$result]]></code>
<code><![CDATA[$this->copyFromStorage($sourceStorage, $sourceInternalPath . '/' . $file, $targetInternalPath . '/' . $file, false, $isRename)]]></code>
</InvalidOperand>
<InvalidReturnStatement>
<code><![CDATA[$newUnencryptedSize]]></code>
<code><![CDATA[$result]]></code>
</InvalidReturnStatement>
<InvalidReturnType>
<code><![CDATA[bool]]></code>
<code><![CDATA[int]]></code>
</InvalidReturnType>
<InvalidScalarArgument>
Expand All @@ -2190,17 +2169,11 @@
<InvalidReturnStatement>
<code><![CDATA[$this->getWrapperStorage()->filetype($this->getUnjailedPath($path))]]></code>
</InvalidReturnStatement>
<InvalidReturnType>
<code><![CDATA[bool]]></code>
</InvalidReturnType>
<InvalidReturnType/>
</file>
<file src="lib/private/Files/Storage/Wrapper/Wrapper.php">
<InvalidReturnStatement>
<code><![CDATA[$this->getWrapperStorage()->test()]]></code>
</InvalidReturnStatement>
<InvalidReturnType>
<code><![CDATA[true]]></code>
</InvalidReturnType>
<InvalidReturnStatement/>
<InvalidReturnType/>
</file>
<file src="lib/private/Files/Stream/SeekableHttpStream.php">
<InvalidReturnType>
Expand Down Expand Up @@ -2370,20 +2343,6 @@
</NullableReturnStatement>
</file>
<file src="lib/private/Lockdown/Filesystem/NullStorage.php">
<InvalidNullableReturnType>
<code><![CDATA[getPermissions]]></code>
</InvalidNullableReturnType>
<InvalidReturnStatement>
<code><![CDATA[new IteratorDirectory([])]]></code>
<code><![CDATA[new NullCache()]]></code>
</InvalidReturnStatement>
<InvalidReturnType>
<code><![CDATA[getCache]]></code>
<code><![CDATA[opendir]]></code>
</InvalidReturnType>
<NullableReturnStatement>
<code><![CDATA[null]]></code>
</NullableReturnStatement>
<TooManyArguments>
<code><![CDATA[new IteratorDirectory([])]]></code>
</TooManyArguments>
Expand Down
43 changes: 18 additions & 25 deletions lib/private/Files/ObjectStore/ObjectStoreStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use OC\Files\Storage\PolyFill\CopyDirectory;
use OCP\Files\Cache\ICache;
use OCP\Files\Cache\ICacheEntry;
use OCP\Files\Cache\IScanner;
use OCP\Files\FileInfo;
use OCP\Files\GenericFileException;
use OCP\Files\NotFoundException;
Expand Down Expand Up @@ -64,7 +65,7 @@ public function __construct($params) {
$this->logger = \OCP\Server::get(LoggerInterface::class);
}

public function mkdir($path, bool $force = false) {
public function mkdir($path, bool $force = false): bool {
$path = $this->normalizePath($path);
if (!$force && $this->file_exists($path)) {
$this->logger->warning("Tried to create an object store folder that already exists: $path");
Expand Down Expand Up @@ -130,7 +131,7 @@ private function normalizePath($path) {
* Object Stores use a NoopScanner because metadata is directly stored in
* the file cache and cannot really scan the filesystem. The storage passed in is not used anywhere.
*/
public function getScanner($path = '', $storage = null) {
public function getScanner($path = '', $storage = null): IScanner {
if (!$storage) {
$storage = $this;
}
Expand All @@ -141,11 +142,11 @@ public function getScanner($path = '', $storage = null) {
return $this->scanner;
}

public function getId() {
public function getId(): string {
return $this->id;
}

public function rmdir($path) {
public function rmdir($path): bool {
$path = $this->normalizePath($path);
$entry = $this->getCache()->get($path);

Expand Down Expand Up @@ -175,7 +176,7 @@ private function rmObjects(ICacheEntry $entry): bool {
return true;
}

public function unlink($path) {
public function unlink($path): bool {
$path = $this->normalizePath($path);
$entry = $this->getCache()->get($path);

Expand Down Expand Up @@ -209,7 +210,7 @@ public function rmObject(ICacheEntry $entry): bool {
return true;
}

public function stat($path) {
public function stat($path): array|false {
$path = $this->normalizePath($path);
$cacheEntry = $this->getCache()->get($path);
if ($cacheEntry instanceof CacheEntry) {
Expand All @@ -226,7 +227,7 @@ public function stat($path) {
}
}

public function getPermissions($path) {
public function getPermissions($path): int {
$stat = $this->stat($path);

if (is_array($stat) && isset($stat['permissions'])) {
Expand Down Expand Up @@ -268,7 +269,7 @@ public function opendir($path) {
}
}

public function filetype($path) {
public function filetype($path): string|false {
$path = $this->normalizePath($path);
$stat = $this->stat($path);
if ($stat) {
Expand Down Expand Up @@ -373,12 +374,12 @@ public function fopen($path, $mode) {
return false;
}

public function file_exists($path) {
public function file_exists($path): bool {
$path = $this->normalizePath($path);
return (bool)$this->stat($path);
}

public function rename($source, $target) {
public function rename($source, $target): bool {
$source = $this->normalizePath($source);
$target = $this->normalizePath($target);
$this->remove($target);
Expand All @@ -387,12 +388,12 @@ public function rename($source, $target) {
return true;
}

public function getMimeType($path) {
public function getMimeType($path): string|false {
$path = $this->normalizePath($path);
return parent::getMimeType($path);
}

public function touch($path, $mtime = null) {
public function touch($path, $mtime = null): bool {
if (is_null($mtime)) {
$mtime = time();
}
Expand Down Expand Up @@ -443,22 +444,15 @@ public function writeBack($tmpFile, $path) {
$this->writeStream($path, fopen($tmpFile, 'r'), $size);
}

/**
* external changes are not supported, exclusive access to the object storage is assumed
*
* @param string $path
* @param int $time
* @return false
*/
public function hasUpdated($path, $time) {
public function hasUpdated($path, $time): bool {
return false;
}

public function needsPartFile() {
public function needsPartFile(): bool {
return false;
}

public function file_put_contents($path, $data) {
public function file_put_contents($path, $data): int {
$fh = fopen('php://temp', 'w+');
fwrite($fh, $data);
rewind($fh);
Expand Down Expand Up @@ -571,7 +565,7 @@ public function copyFromStorage(
$sourceInternalPath,
$targetInternalPath,
$preserveMtime = false,
) {
): bool {
if ($sourceStorage->instanceOfStorage(ObjectStoreStorage::class)) {
/** @var ObjectStoreStorage $sourceStorage */
if ($sourceStorage->getObjectStore()->getStorageId() === $this->getObjectStore()->getStorageId()) {
Expand Down Expand Up @@ -627,7 +621,7 @@ public function moveFromStorage(IStorage $sourceStorage, $sourceInternalPath, $t
return true;
}

public function copy($source, $target) {
public function copy($source, $target): bool {
$source = $this->normalizePath($source);
$target = $this->normalizePath($target);

Expand Down Expand Up @@ -695,7 +689,6 @@ public function startChunkedWrite(string $targetPath): string {
}

/**
*
* @throws GenericFileException
*/
public function putChunkedWritePart(
Expand Down
Loading