Browse Source

chore: Fix psalm issues, put back private versions of getter in private Storage interface

Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
pull/48009/head
Côme Chilliet 1 year ago
parent
commit
492e6997d8
No known key found for this signature in database GPG Key ID: A3E2F658B28C760A
  1. 1
      apps/files_sharing/lib/External/Storage.php
  2. 7
      apps/files_trashbin/lib/Trashbin.php
  3. 13
      lib/private/Files/Cache/Scanner.php
  4. 1
      lib/private/Files/ObjectStore/ObjectStoreStorage.php
  5. 20
      lib/private/Files/Storage/Common.php
  6. 4
      lib/private/Files/Storage/Home.php
  7. 46
      lib/private/Files/Storage/Storage.php
  8. 2
      lib/private/Files/Storage/Temporary.php
  9. 2
      lib/public/Files/Storage/IStorage.php

1
apps/files_sharing/lib/External/Storage.php

@ -149,6 +149,7 @@ class Storage extends DAV implements ISharedStorage, IDisableEncryptionStorage,
if (!isset($this->scanner)) {
$this->scanner = new Scanner($storage);
}
/** @var \OCA\Files_Sharing\External\Scanner */
return $this->scanner;
}

7
apps/files_trashbin/lib/Trashbin.php

@ -29,6 +29,7 @@ use OCP\Files\IRootFolder;
use OCP\Files\Node;
use OCP\Files\NotFoundException;
use OCP\Files\NotPermittedException;
use OCP\Files\Storage\ILockingStorage;
use OCP\FilesMetadata\IFilesMetadataManager;
use OCP\IConfig;
use OCP\IDBConnection;
@ -118,7 +119,7 @@ class Trashbin {
* @param string $user
* @param string $filename
* @param string $timestamp
* @return string original location
* @return string|false original location
*/
public static function getLocation($user, $filename, $timestamp) {
$query = \OC::$server->getDatabaseConnection()->getQueryBuilder();
@ -139,7 +140,7 @@ class Trashbin {
}
}
private static function setUpTrash($user) {
private static function setUpTrash($user): void {
$view = new View('/' . $user);
if (!$view->is_dir('files_trashbin')) {
$view->mkdir('files_trashbin');
@ -256,7 +257,7 @@ class Trashbin {
while (!$gotLock) {
try {
/** @var \OC\Files\Storage\Storage $trashStorage */
/** @var ILockingStorage $trashStorage */
[$trashStorage, $trashInternalPath] = $ownerView->resolvePath($trashPath);
$trashStorage->acquireLock($trashInternalPath, ILockingProvider::LOCK_EXCLUSIVE, $lockingProvider);

13
lib/private/Files/Cache/Scanner.php

@ -15,6 +15,7 @@ use OC\SystemConfig;
use OCP\Files\Cache\IScanner;
use OCP\Files\ForbiddenException;
use OCP\Files\NotFoundException;
use OCP\Files\Storage\ILockingStorage;
use OCP\Files\Storage\IReliableEtagStorage;
use OCP\IDBConnection;
use OCP\Lock\ILockingProvider;
@ -125,7 +126,7 @@ class Scanner extends BasicEmitter implements IScanner {
if (!self::isPartialFile($file)) {
// acquire a lock
if ($lock) {
if ($this->storage->instanceOfStorage('\OCP\Files\Storage\ILockingStorage')) {
if ($this->storage->instanceOfStorage(ILockingStorage::class)) {
$this->storage->acquireLock($file, ILockingProvider::LOCK_SHARED, $this->lockingProvider);
}
}
@ -134,7 +135,7 @@ class Scanner extends BasicEmitter implements IScanner {
$data = $data ?? $this->getData($file);
} catch (ForbiddenException $e) {
if ($lock) {
if ($this->storage->instanceOfStorage('\OCP\Files\Storage\ILockingStorage')) {
if ($this->storage->instanceOfStorage(ILockingStorage::class)) {
$this->storage->releaseLock($file, ILockingProvider::LOCK_SHARED, $this->lockingProvider);
}
}
@ -233,7 +234,7 @@ class Scanner extends BasicEmitter implements IScanner {
}
} catch (\Exception $e) {
if ($lock) {
if ($this->storage->instanceOfStorage('\OCP\Files\Storage\ILockingStorage')) {
if ($this->storage->instanceOfStorage(ILockingStorage::class)) {
$this->storage->releaseLock($file, ILockingProvider::LOCK_SHARED, $this->lockingProvider);
}
}
@ -242,7 +243,7 @@ class Scanner extends BasicEmitter implements IScanner {
// release the acquired lock
if ($lock) {
if ($this->storage->instanceOfStorage('\OCP\Files\Storage\ILockingStorage')) {
if ($this->storage->instanceOfStorage(ILockingStorage::class)) {
$this->storage->releaseLock($file, ILockingProvider::LOCK_SHARED, $this->lockingProvider);
}
}
@ -319,7 +320,7 @@ class Scanner extends BasicEmitter implements IScanner {
$reuse = ($recursive === self::SCAN_SHALLOW) ? self::REUSE_ETAG | self::REUSE_SIZE : self::REUSE_ETAG;
}
if ($lock) {
if ($this->storage->instanceOfStorage('\OCP\Files\Storage\ILockingStorage')) {
if ($this->storage->instanceOfStorage(ILockingStorage::class)) {
$this->storage->acquireLock('scanner::' . $path, ILockingProvider::LOCK_EXCLUSIVE, $this->lockingProvider);
$this->storage->acquireLock($path, ILockingProvider::LOCK_SHARED, $this->lockingProvider);
}
@ -337,7 +338,7 @@ class Scanner extends BasicEmitter implements IScanner {
}
} finally {
if ($lock) {
if ($this->storage->instanceOfStorage('\OCP\Files\Storage\ILockingStorage')) {
if ($this->storage->instanceOfStorage(ILockingStorage::class)) {
$this->storage->releaseLock($path, ILockingProvider::LOCK_SHARED, $this->lockingProvider);
$this->storage->releaseLock('scanner::' . $path, ILockingProvider::LOCK_EXCLUSIVE, $this->lockingProvider);
}

1
lib/private/Files/ObjectStore/ObjectStoreStorage.php

@ -141,6 +141,7 @@ class ObjectStoreStorage extends \OC\Files\Storage\Common implements IChunkedFil
if (!isset($this->scanner)) {
$this->scanner = new ObjectStoreScanner($storage);
}
/** @var \OC\Files\ObjectStore\ObjectStoreScanner */
return $this->scanner;
}

20
lib/private/Files/Storage/Common.php

@ -44,14 +44,14 @@ use Psr\Log\LoggerInterface;
abstract class Common implements Storage, ILockingStorage, IWriteStreamStorage {
use LocalTempFileTrait;
protected $cache;
protected $scanner;
protected $watcher;
protected $propagator;
protected ?Cache $cache = null;
protected ?Scanner $scanner = null;
protected ?Watcher $watcher = null;
protected ?Propagator $propagator = null;
protected $storageCache;
protected $updater;
protected ?Updater $updater = null;
protected $mountOptions = [];
protected array $mountOptions = [];
protected $owner = null;
private ?bool $shouldLogLocks = null;
@ -310,13 +310,19 @@ abstract class Common implements Storage, ILockingStorage, IWriteStreamStorage {
return $dependencies;
}
/**
* @return Cache
*/
public function getCache($path = '', $storage = null) {
if (!$storage) {
$storage = $this;
}
/** @psalm-suppress NoInterfaceProperties The isset check is safe */
if (!isset($storage->cache)) {
$storage->cache = new Cache($storage, $this->getCacheDependencies());
}
/** @psalm-suppress NullableReturnStatement False-positive, as the if above avoids this being null */
/** @psalm-suppress NoInterfaceProperties Legacy */
return $storage->cache;
}
@ -324,9 +330,11 @@ abstract class Common implements Storage, ILockingStorage, IWriteStreamStorage {
if (!$storage) {
$storage = $this;
}
/** @psalm-suppress NoInterfaceProperties The isset check is safe */
if (!isset($storage->scanner)) {
$storage->scanner = new Scanner($storage);
}
/** @psalm-suppress NoInterfaceProperties Legacy stuff */
return $storage->scanner;
}

4
lib/private/Files/Storage/Home.php

@ -52,13 +52,14 @@ class Home extends Local implements \OCP\Files\IHomeStorage {
if (!isset($this->cache)) {
$this->cache = new \OC\Files\Cache\HomeCache($storage, $this->getCacheDependencies());
}
/** @var \OC\Files\Cache\HomeCache */
return $this->cache;
}
/**
* get a propagator instance for the cache
*
* @param \OC\Files\Storage\Storage (optional) the storage to pass to the watcher
* @param \OC\Files\Storage\Storage $storage (optional) the storage to pass to the watcher
* @return \OC\Files\Cache\Propagator
*/
public function getPropagator($storage = null) {
@ -68,6 +69,7 @@ class Home extends Local implements \OCP\Files\IHomeStorage {
if (!isset($this->propagator)) {
$this->propagator = new HomePropagator($storage, \OC::$server->getDatabaseConnection());
}
/** @var \OC\Files\Cache\Propagator */
return $this->propagator;
}

46
lib/private/Files/Storage/Storage.php

@ -8,6 +8,7 @@
namespace OC\Files\Storage;
use OCP\Files\Storage\ILockingStorage;
use OCP\Files\Storage\IStorage;
/**
@ -15,7 +16,50 @@ use OCP\Files\Storage\IStorage;
*
* All paths passed to the storage are relative to the storage and should NOT have a leading slash.
*/
interface Storage extends IStorage {
interface Storage extends IStorage, ILockingStorage {
/**
* get a cache instance for the storage
*
* @param string $path
* @param \OC\Files\Storage\Storage|null (optional) the storage to pass to the cache
* @return \OC\Files\Cache\Cache
*/
public function getCache($path = '', $storage = null);
/**
* get a scanner instance for the storage
*
* @param string $path
* @param \OC\Files\Storage\Storage (optional) the storage to pass to the scanner
* @return \OC\Files\Cache\Scanner
*/
public function getScanner($path = '', $storage = null);
/**
* get a watcher instance for the cache
*
* @param string $path
* @param \OC\Files\Storage\Storage (optional) the storage to pass to the watcher
* @return \OC\Files\Cache\Watcher
*/
public function getWatcher($path = '', $storage = null);
/**
* get a propagator instance for the cache
*
* @param \OC\Files\Storage\Storage (optional) the storage to pass to the watcher
* @return \OC\Files\Cache\Propagator
*/
public function getPropagator($storage = null);
/**
* get a updater instance for the cache
*
* @param \OC\Files\Storage\Storage (optional) the storage to pass to the watcher
* @return \OC\Files\Cache\Updater
*/
public function getUpdater($storage = null);
/**
* @return \OC\Files\Cache\Storage
*/

2
lib/private/Files/Storage/Temporary.php

@ -11,7 +11,7 @@ namespace OC\Files\Storage;
* local storage backend in temporary folder for testing purpose
*/
class Temporary extends Local {
public function __construct($arguments = null) {
public function __construct($arguments = []) {
parent::__construct(['datadir' => \OC::$server->getTempManager()->getTemporaryFolder()]);
}

2
lib/public/Files/Storage/IStorage.php

@ -410,6 +410,7 @@ interface IStorage {
/**
* @since 9.0.0
* @param bool $isAvailable
* @return void
*/
public function setAvailability($isAvailable);
@ -421,6 +422,7 @@ interface IStorage {
/**
* @param string $path path for which to retrieve the owner
* @return string
* @since 9.0.0
*/
public function getOwner($path);

Loading…
Cancel
Save