Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ACLStorageWrapper): Fix return types #3280

Merged
merged 2 commits into from
Sep 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
24 changes: 14 additions & 10 deletions lib/ACL/ACLStorageWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
namespace OCA\GroupFolders\ACL;

use Icewind\Streams\IteratorDirectory;
use OC\Files\Cache\Scanner;
use OC\Files\Storage\Wrapper\Wrapper;
use OCP\Constants;
use OCP\Files\Cache\ICache;
use OCP\Files\Cache\IScanner;
use OCP\Files\Storage\IStorage;

class ACLStorageWrapper extends Wrapper {
Expand Down Expand Up @@ -204,7 +204,7 @@ public function getMetaData($path): ?array {
* @param string $path
* @param ?IStorage $storage
*/
public function getScanner($path = '', $storage = null): Scanner {
public function getScanner($path = '', $storage = null): IScanner {
if (!$storage) {
$storage = $this->storage;
}
Expand All @@ -222,15 +222,15 @@ public function is_file($path): bool {
parent::is_file($path);
}

public function stat($path): array|bool {
public function stat($path): array|false {
if (!$this->checkPermissions($path, Constants::PERMISSION_READ)) {
return false;
}

return parent::stat($path);
}

public function filetype($path): string|bool {
public function filetype($path): string|false {
if (!$this->checkPermissions($path, Constants::PERMISSION_READ)) {
return false;
}
Expand All @@ -251,7 +251,7 @@ public function file_exists($path): bool {
parent::file_exists($path);
}

public function filemtime($path): int|bool {
public function filemtime($path): int|false {
if (!$this->checkPermissions($path, Constants::PERMISSION_READ)) {
return false;
}
Expand All @@ -267,15 +267,15 @@ public function file_get_contents($path): string|false {
return parent::file_get_contents($path);
}

public function getMimeType($path): string|bool {
public function getMimeType($path): string|false {
if (!$this->checkPermissions($path, Constants::PERMISSION_READ)) {
return false;
}

return parent::getMimeType($path);
}

public function hash($type, $path, $raw = false): string|bool {
public function hash($type, $path, $raw = false): string|false {
if (!$this->checkPermissions($path, Constants::PERMISSION_READ)) {
return false;
}
Expand All @@ -291,16 +291,20 @@ public function getETag($path): string|false {
return parent::getETag($path);
}

public function getDirectDownload($path): array|bool {
public function getDirectDownload($path): array|false {
if (!$this->checkPermissions($path, Constants::PERMISSION_READ)) {
return false;
}

return parent::getDirectDownload($path);
}

public function getDirectoryContent($directory): \Traversable {
foreach ($this->getWrapperStorage()->getDirectoryContent($directory) as $data) {
public function getDirectoryContent($directory): \Traversable|false {
$content = $this->getWrapperStorage()->getDirectoryContent($directory);
if ($content === false) {
return false;
}
foreach ($content as $data) {
$data['scan_permissions'] ??= $data['permissions'];
$data['permissions'] &= $this->getACLPermissionsForPath(rtrim($directory, '/') . '/' . $data['name']);

Expand Down
1 change: 1 addition & 0 deletions psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@
<file name="tests/stubs/symfony_component_console_question_question.php" />
<file name="tests/stubs/test_testcase.php" />
<file name="tests/stubs/test_traits_usertrait.php" />
<file name="tests/stubs/ocp_files_storage_iconstructablestorage.php" />
</stubs>
<projectFiles>
<directory name="lib" />
Expand Down
2 changes: 2 additions & 0 deletions tests/ACL/ACLScannerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

namespace OCA\groupfolders\tests\ACL;

use OC\Files\Cache\Cache;
use OC\Files\Storage\Temporary;
use OCA\GroupFolders\ACL\ACLManager;
use OCA\GroupFolders\ACL\ACLStorageWrapper;
Expand All @@ -33,6 +34,7 @@ public function testScanAclStorage(): void {
$baseStorage->mkdir('foo');
$baseStorage->mkdir('foo/bar');
$baseStorage->mkdir('foo/bar/asd');
/** @var Cache $cache */
$cache = $baseStorage->getCache();
$baseStorage->getScanner()->scan('');

Expand Down
2 changes: 1 addition & 1 deletion tests/stubs/oc_files_cache_cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ public function getPathById($id)
*
* @param int $id
* @return array first element holding the storage id, second the path
* @deprecated use getPathById() instead
* @deprecated 17.0.0 use getPathById() instead
*/
public static function getById($id)
{
Expand Down
43 changes: 18 additions & 25 deletions tests/stubs/oc_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 All @@ -41,39 +42,39 @@ public function __construct($params)
{
}

public function mkdir($path, bool $force = false)
public function mkdir($path, bool $force = false): bool
{
}

/**
* 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
{
}

public function getId()
public function getId(): string
{
}

public function rmdir($path)
public function rmdir($path): bool
{
}

public function unlink($path)
public function unlink($path): bool
{
}

public function rmObject(ICacheEntry $entry): bool
{
}

public function stat($path)
public function stat($path): array|false
{
}

public function getPermissions($path)
public function getPermissions($path): int
{
}

Expand All @@ -93,50 +94,43 @@ public function opendir($path)
{
}

public function filetype($path)
public function filetype($path): string|false
{
}

public function fopen($path, $mode)
{
}

public function file_exists($path)
public function file_exists($path): bool
{
}

public function rename($source, $target)
public function rename($source, $target): bool
{
}

public function getMimeType($path)
public function getMimeType($path): string|false
{
}

public function touch($path, $mtime = null)
public function touch($path, $mtime = null): bool
{
}

public function writeBack($tmpFile, $path)
{
}

/**
* 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
{
}

public function needsPartFile()
public function needsPartFile(): bool
{
}

public function file_put_contents($path, $data)
public function file_put_contents($path, $data): int
{
}

Expand All @@ -148,15 +142,15 @@ public function getObjectStore(): IObjectStore
{
}

public function copyFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath, $preserveMtime = false)
public function copyFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath, $preserveMtime = false): bool
{
}

public function moveFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath, ?ICacheEntry $sourceCacheEntry = null): bool
{
}

public function copy($source, $target)
public function copy($source, $target): bool
{
}

Expand All @@ -165,7 +159,6 @@ public function startChunkedWrite(string $targetPath): string
}

/**
*
* @throws GenericFileException
*/
public function putChunkedWritePart(string $targetPath, string $writeToken, string $chunkId, $data, $size = null): ?array
Expand Down
1 change: 1 addition & 0 deletions tests/stubs/oc_files_setupmanager.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
use OCP\Files\Config\IHomeMountProvider;
use OCP\Files\Config\IMountProvider;
use OCP\Files\Config\IUserMountCache;
use OCP\Files\Events\BeforeFileSystemSetupEvent;
use OCP\Files\Events\InvalidateMountCacheEvent;
use OCP\Files\Events\Node\FilesystemTornDownEvent;
use OCP\Files\Mount\IMountManager;
Expand Down
Loading
Loading