Skip to content

Commit

Permalink
fix(Storage): Fix IStorage return types
Browse files Browse the repository at this point in the history
Signed-off-by: provokateurin <kate@provokateurin.de>
  • Loading branch information
provokateurin committed Sep 19, 2024
1 parent c04c8ff commit 82bd709
Show file tree
Hide file tree
Showing 25 changed files with 527 additions and 1,456 deletions.
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

0 comments on commit 82bd709

Please sign in to comment.