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

Tidy up typing in OC\Files\View #36836

Merged
merged 8 commits into from
Apr 5, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
3 changes: 1 addition & 2 deletions apps/dav/tests/unit/Connector/Sabre/DirectoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public function rename($path1, $path2) {
return $this->canRename;
}

public function getRelativePath($path) {
public function getRelativePath($path): ?string {
return $path;
}
}
Expand All @@ -73,7 +73,6 @@ public function getRelativePath($path) {
* @group DB
*/
class DirectoryTest extends \Test\TestCase {

use UserTrait;

/** @var \OC\Files\View | \PHPUnit\Framework\MockObject\MockObject */
Expand Down
2 changes: 1 addition & 1 deletion apps/encryption/tests/Command/FixEncryptedVersionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ public function testRepairUnencryptedFileWhenVersionIsSet() {
$cacheInfo = ['encryptedVersion' => 1, 'encrypted' => 1];
$cache1->put($fileCache1->getPath(), $cacheInfo);

$absPath = $view->getLocalFolder(''). '/hello.txt';
$absPath = $storage1->getSourcePath('').$fileInfo1->getInternalPath();

// create unencrypted file on disk, the version stays
file_put_contents($absPath, 'hello contents');
Expand Down
73 changes: 23 additions & 50 deletions lib/private/Files/Filesystem.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,32 +42,24 @@
use OC\User\NoUserException;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\Files\Events\Node\FilesystemTornDownEvent;
use OCP\Files\Mount\IMountManager;
use OCP\Files\NotFoundException;
use OCP\Files\Storage\IStorageFactory;
use OCP\IUser;
use OCP\IUserManager;
use OCP\IUserSession;

class Filesystem {
/**
* @var Mount\Manager $mounts
*/
private static $mounts;

public static $loaded = false;
/**
* @var \OC\Files\View $defaultInstance
*/
private static $defaultInstance;
private static ?Mount\Manager $mounts = null;

private static $usersSetup = [];
public static bool $loaded = false;

private static $normalizedPathCache = null;
private static ?View $defaultInstance = null;

private static $listeningForProviders = false;
private static ?CappedMemoryCache $normalizedPathCache = null;

/** @var string[]|null */
private static $blacklist = null;
private static ?array $blacklist = null;

/**
* classname which used for hooks handling
Expand Down Expand Up @@ -186,22 +178,18 @@ class Filesystem {
public const signal_param_mount_type = 'mounttype';
public const signal_param_users = 'users';

/**
* @var \OC\Files\Storage\StorageFactory $loader
*/
private static $loader;
private static ?\OC\Files\Storage\StorageFactory $loader = null;

/** @var bool */
private static $logWarningWhenAddingStorageWrapper = true;
private static bool $logWarningWhenAddingStorageWrapper = true;

/**
* @param bool $shouldLog
* @return bool previous value
* @internal
*/
public static function logWarningWhenAddingStorageWrapper($shouldLog) {
public static function logWarningWhenAddingStorageWrapper(bool $shouldLog): bool {
$previousValue = self::$logWarningWhenAddingStorageWrapper;
self::$logWarningWhenAddingStorageWrapper = (bool) $shouldLog;
self::$logWarningWhenAddingStorageWrapper = $shouldLog;
return $previousValue;
}

Expand Down Expand Up @@ -232,18 +220,17 @@ public static function addStorageWrapper($wrapperName, $wrapper, $priority = 50)
*/
public static function getLoader() {
if (!self::$loader) {
self::$loader = \OC::$server->query(IStorageFactory::class);
self::$loader = \OC::$server->get(IStorageFactory::class);
}
return self::$loader;
}

/**
* Returns the mount manager
*
* @return \OC\Files\Mount\Manager
*/
public static function getMountManager($user = '') {
public static function getMountManager(): Mount\Manager {
self::initMountManager();
assert(self::$mounts !== null);
return self::$mounts;
}

Expand Down Expand Up @@ -313,14 +300,14 @@ public static function getMountByNumericId($id) {
* resolve a path to a storage and internal path
*
* @param string $path
* @return array an array consisting of the storage and the internal path
* @return array{?\OCP\Files\Storage\IStorage, string} an array consisting of the storage and the internal path
*/
public static function resolvePath($path) {
public static function resolvePath($path): array {
$mount = self::getMountManager()->find($path);
return [$mount->getStorage(), rtrim($mount->getInternalPath($path), '/')];
}

public static function init($user, $root) {
public static function init(string|IUser|null $user, string $root): bool {
if (self::$defaultInstance) {
return false;
}
Expand All @@ -332,7 +319,7 @@ public static function init($user, $root) {
return true;
}

public static function initInternal($root) {
public static function initInternal(string $root): bool {
if (self::$defaultInstance) {
return false;
}
Expand All @@ -342,32 +329,28 @@ public static function initInternal($root) {
$eventDispatcher = \OC::$server->get(IEventDispatcher::class);
$eventDispatcher->addListener(FilesystemTornDownEvent::class, function () {
self::$defaultInstance = null;
self::$usersSetup = [];
self::$loaded = false;
});

if (!self::$mounts) {
self::$mounts = \OC::$server->getMountManager();
}
self::initMountManager();

self::$loaded = true;

return true;
}

public static function initMountManager() {
public static function initMountManager(): void {
if (!self::$mounts) {
self::$mounts = \OC::$server->getMountManager();
self::$mounts = \OC::$server->get(IMountManager::class);
}
}

/**
* Initialize system and personal mount points for a user
*
* @param string|IUser|null $user
* @throws \OC\User\NoUserException if the user is not available
*/
public static function initMountPoints($user = '') {
public static function initMountPoints(string|IUser|null $user = ''): void {
/** @var IUserManager $userManager */
$userManager = \OC::$server->get(IUserManager::class);

Expand All @@ -382,11 +365,9 @@ public static function initMountPoints($user = '') {
}

/**
* get the default filesystem view
*
* @return View
* Get the default filesystem view
*/
public static function getView() {
public static function getView(): ?View {
if (!self::$defaultInstance) {
/** @var IUserSession $session */
$session = \OC::$server->get(IUserSession::class);
Expand Down Expand Up @@ -447,14 +428,6 @@ public static function getLocalFile($path) {
return self::$defaultInstance->getLocalFile($path);
}

/**
* @param string $path
* @return string
*/
public static function getLocalFolder($path) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return self::$defaultInstance->getLocalFolder($path);
}

/**
* return path to file which reflects one visible in browser
*
Expand Down
4 changes: 0 additions & 4 deletions lib/private/Files/Storage/FailedStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,10 +164,6 @@ public function getLocalFile($path) {
throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
}

public function getLocalFolder($path) {
throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
}

public function hasUpdated($path, $time) {
throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
}
Expand Down
4 changes: 0 additions & 4 deletions lib/private/Files/Storage/Local.php
Original file line number Diff line number Diff line change
Expand Up @@ -433,10 +433,6 @@ public function getLocalFile($path) {
return $this->getSourcePath($path);
}

public function getLocalFolder($path) {
return $this->getSourcePath($path);
}

/**
* @param string $query
* @param string $dir
Expand Down
Loading