Skip to content

Commit

Permalink
Merge pull request #48009 from nextcloud/fix/remove-references-to-dep…
Browse files Browse the repository at this point in the history
…rected-storage-interface

fix: Remove OCP\Files\Storage interface deprecated since version 9
  • Loading branch information
come-nc committed Sep 16, 2024
2 parents ede0c26 + 03b969f commit b9fb1db
Show file tree
Hide file tree
Showing 38 changed files with 167 additions and 656 deletions.
14 changes: 8 additions & 6 deletions apps/dav/lib/Connector/Sabre/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
use OCP\Files\LockNotAcquiredException;
use OCP\Files\NotFoundException;
use OCP\Files\NotPermittedException;
use OCP\Files\Storage;
use OCP\Files\Storage\IWriteStreamStorage;
use OCP\Files\StorageNotAvailableException;
use OCP\IL10N;
use OCP\IRequest;
Expand Down Expand Up @@ -117,8 +117,10 @@ public function put($data) {
// verify path of the target
$this->verifyPath();

/** @var Storage $partStorage */
[$partStorage] = $this->fileView->resolvePath($this->path);
if ($partStorage === null) {
throw new ServiceUnavailable($this->l10n->t('Failed to get storage for file'));
}
$needsPartFile = $partStorage->needsPartFile() && (strlen($this->path) > 1);

$view = \OC\Files\Filesystem::getView();
Expand All @@ -141,10 +143,11 @@ public function put($data) {
}

// the part file and target file might be on a different storage in case of a single file storage (e.g. single file share)
/** @var \OC\Files\Storage\Storage $partStorage */
[$partStorage, $internalPartPath] = $this->fileView->resolvePath($partFilePath);
/** @var \OC\Files\Storage\Storage $storage */
[$storage, $internalPath] = $this->fileView->resolvePath($this->path);
if ($partStorage === null || $storage === null) {
throw new ServiceUnavailable($this->l10n->t('Failed to get storage for file'));
}
try {
if (!$needsPartFile) {
try {
Expand Down Expand Up @@ -196,7 +199,7 @@ public function put($data) {
}
}

if ($partStorage->instanceOfStorage(Storage\IWriteStreamStorage::class)) {
if ($partStorage->instanceOfStorage(IWriteStreamStorage::class)) {
$isEOF = false;
$wrappedData = CallbackWrapper::wrap($data, null, null, null, null, function ($stream) use (&$isEOF) {
$isEOF = feof($stream);
Expand Down Expand Up @@ -535,7 +538,6 @@ public function getDirectDownload() {
if (\OCP\Server::get(\OCP\App\IAppManager::class)->isEnabledForUser('encryption')) {
return [];
}
/** @var \OCP\Files\Storage $storage */
[$storage, $internalPath] = $this->fileView->resolvePath($this->path);
if (is_null($storage)) {
return [];
Expand Down
14 changes: 4 additions & 10 deletions apps/dav/tests/unit/Connector/Sabre/FileTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
use OCP\Constants;
use OCP\Files\FileInfo;
use OCP\Files\ForbiddenException;
use OCP\Files\Storage;
use OCP\Files\Storage\IStorage;
use OCP\IConfig;
use OCP\IRequestId;
use OCP\ITempManager;
Expand Down Expand Up @@ -72,22 +72,16 @@ protected function tearDown(): void {
parent::tearDown();
}

/**
* @return MockObject|Storage
*/
private function getMockStorage() {
$storage = $this->getMockBuilder(Storage::class)
private function getMockStorage(): MockObject&IStorage {
$storage = $this->getMockBuilder(IStorage::class)
->disableOriginalConstructor()
->getMock();
$storage->method('getId')
->willReturn('home::someuser');
return $storage;
}

/**
* @param string $string
*/
private function getStream($string) {
private function getStream(string $string) {
$stream = fopen('php://temp', 'r+');
fwrite($stream, $string);
fseek($stream, 0);
Expand Down
8 changes: 4 additions & 4 deletions apps/dav/tests/unit/Connector/Sabre/NodeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
use OCP\Constants;
use OCP\Files\Cache\ICacheEntry;
use OCP\Files\Mount\IMountPoint;
use OCP\Files\Storage;
use OCP\Files\Storage\IStorage;
use OCP\ICache;
use OCP\Share\IManager;
use OCP\Share\IShare;
Expand Down Expand Up @@ -75,7 +75,7 @@ public function testDavPermissions($permissions, $type, $shared, $shareRootPermi
return $this->createMock(MountPoint::class);
}
});
$storage = $this->createMock(Storage\IStorage::class);
$storage = $this->createMock(IStorage::class);
if ($shared) {
$storage->method('instanceOfStorage')
->willReturn(true);
Expand Down Expand Up @@ -145,7 +145,7 @@ public function sharePermissionsProvider() {
* @dataProvider sharePermissionsProvider
*/
public function testSharePermissions($type, $user, $permissions, $expected): void {
$storage = $this->getMockBuilder(Storage::class)
$storage = $this->getMockBuilder(IStorage::class)
->disableOriginalConstructor()
->getMock();
$storage->method('getPermissions')->willReturn($permissions);
Expand Down Expand Up @@ -223,7 +223,7 @@ public function testShareAttributes(): void {
}

public function testShareAttributesNonShare(): void {
$storage = $this->getMockBuilder(Storage::class)
$storage = $this->getMockBuilder(IStorage::class)
->disableOriginalConstructor()
->getMock();

Expand Down
8 changes: 4 additions & 4 deletions apps/encryption/tests/Crypto/EncryptionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@
use OCA\Encryption\KeyManager;
use OCA\Encryption\Session;
use OCA\Encryption\Util;
use OCP\Files\Storage;
use OCP\Files\Storage\IStorage;
use OCP\IL10N;
use PHPUnit\Framework\MockObject\MockObject;
use Psr\Log\LoggerInterface;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
Expand Down Expand Up @@ -50,13 +51,12 @@ class EncryptionTest extends TestCase {
/** @var \OCP\IL10N|\PHPUnit\Framework\MockObject\MockObject */
private $l10nMock;

/** @var \OCP\Files\Storage|\PHPUnit\Framework\MockObject\MockObject */
private $storageMock;
private IStorage&MockObject $storageMock;

protected function setUp(): void {
parent::setUp();

$this->storageMock = $this->getMockBuilder(Storage::class)
$this->storageMock = $this->getMockBuilder(IStorage::class)
->disableOriginalConstructor()->getMock();
$this->cryptMock = $this->getMockBuilder(Crypt::class)
->disableOriginalConstructor()
Expand Down
4 changes: 2 additions & 2 deletions apps/encryption/tests/KeyManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
use OCA\Encryption\Util;
use OCP\Encryption\Keys\IStorage;
use OCP\Files\Cache\ICache;
use OCP\Files\Storage;
use OCP\Files\Storage\IStorage as FilesIStorage;
use OCP\IConfig;
use OCP\IUserSession;
use OCP\Lock\ILockingProvider;
Expand Down Expand Up @@ -687,7 +687,7 @@ public function testSetVersionWithFileInfo(): void {
$cache->expects($this->once())
->method('update')
->with(123, ['encrypted' => 5, 'encryptedVersion' => 5]);
$storage = $this->getMockBuilder(Storage::class)
$storage = $this->getMockBuilder(FilesIStorage::class)
->disableOriginalConstructor()->getMock();
$storage->expects($this->once())
->method('getCache')
Expand Down
4 changes: 2 additions & 2 deletions apps/encryption/tests/UtilTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
use OCA\Encryption\Crypto\Crypt;
use OCA\Encryption\Util;
use OCP\Files\Mount\IMountPoint;
use OCP\Files\Storage;
use OCP\Files\Storage\IStorage;
use OCP\IConfig;
use OCP\IUser;
use OCP\IUserManager;
Expand Down Expand Up @@ -181,7 +181,7 @@ public function dataTestSetEncryptHomeStorage() {
}

public function testGetStorage(): void {
$return = $this->getMockBuilder(Storage::class)
$return = $this->getMockBuilder(IStorage::class)
->disableOriginalConstructor()
->getMock();

Expand Down
20 changes: 8 additions & 12 deletions apps/files_external/lib/Config/ConfigAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
use OCA\Files_External\Service\UserGlobalStoragesService;
use OCA\Files_External\Service\UserStoragesService;
use OCP\Files\Config\IMountProvider;
use OCP\Files\Storage;
use OCP\Files\ObjectStore\IObjectStore;
use OCP\Files\Storage\IStorage;
use OCP\Files\Storage\IStorageFactory;
use OCP\Files\StorageNotAvailableException;
use OCP\IUser;
Expand All @@ -34,19 +35,17 @@ public function __construct(
/**
* Process storage ready for mounting
*
* @param StorageConfig $storage
* @param IUser $user
* @throws \OCP\AppFramework\QueryException
*/
private function prepareStorageConfig(StorageConfig &$storage, IUser $user) {
private function prepareStorageConfig(StorageConfig &$storage, IUser $user): void {
foreach ($storage->getBackendOptions() as $option => $value) {
$storage->setBackendOption($option, \OCA\Files_External\MountConfig::substitutePlaceholdersInConfig($value, $user->getUID()));
}

$objectStore = $storage->getBackendOption('objectstore');
if ($objectStore) {
$objectClass = $objectStore['class'];
if (!is_subclass_of($objectClass, '\OCP\Files\ObjectStore\IObjectStore')) {
if (!is_subclass_of($objectClass, IObjectStore::class)) {
throw new \InvalidArgumentException('Invalid object store');
}
$storage->setBackendOption('objectstore', new $objectClass($objectStore));
Expand All @@ -60,9 +59,8 @@ private function prepareStorageConfig(StorageConfig &$storage, IUser $user) {
* Construct the storage implementation
*
* @param StorageConfig $storageConfig
* @return Storage
*/
private function constructStorage(StorageConfig $storageConfig) {
private function constructStorage(StorageConfig $storageConfig): IStorage {
$class = $storageConfig->getBackend()->getStorageClass();
$storage = new $class($storageConfig->getBackendOptions());

Expand All @@ -76,8 +74,6 @@ private function constructStorage(StorageConfig $storageConfig) {
/**
* Get all mountpoints applicable for the user
*
* @param \OCP\IUser $user
* @param \OCP\Files\Storage\IStorageFactory $loader
* @return \OCP\Files\Mount\IMountPoint[]
*/
public function getMountsForUser(IUser $user, IStorageFactory $loader) {
Expand All @@ -97,11 +93,11 @@ public function getMountsForUser(IUser $user, IStorageFactory $loader) {
}, $storageConfigs);


\OC\Files\Cache\Storage::getGlobalCache()->loadForStorageIds(array_map(function (Storage\IStorage $storage) {
\OC\Files\Cache\Storage::getGlobalCache()->loadForStorageIds(array_map(function (IStorage $storage) {
return $storage->getId();
}, $storages));

$availableStorages = array_map(function (Storage\IStorage $storage, StorageConfig $storageConfig) {
$availableStorages = array_map(function (IStorage $storage, StorageConfig $storageConfig): IStorage {
try {
$availability = $storage->getAvailability();
if (!$availability['available'] && !Availability::shouldRecheck($availability)) {
Expand All @@ -116,7 +112,7 @@ public function getMountsForUser(IUser $user, IStorageFactory $loader) {
return $storage;
}, $storages, $storageConfigs);

$mounts = array_map(function (StorageConfig $storageConfig, Storage\IStorage $storage) use ($user, $loader) {
$mounts = array_map(function (StorageConfig $storageConfig, IStorage $storage) use ($user, $loader) {
$storage->setOwner($user->getUID());
if ($storageConfig->getType() === StorageConfig::MOUNT_TYPE_PERSONAL) {
return new PersonalMount(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
use OCA\Files_External\Lib\StorageConfig;
use OCP\Authentication\Exceptions\CredentialsUnavailableException;
use OCP\Authentication\LoginCredentials\IStore as CredentialsStore;
use OCP\Files\Storage;
use OCP\Files\Storage\IStorage;
use OCP\Files\StorageAuthException;
use OCP\IL10N;
use OCP\IUser;
Expand Down Expand Up @@ -56,7 +56,7 @@ public function manipulateStorageConfig(StorageConfig &$storage, ?IUser $user =
$storage->setBackendOption('password', $credentials->getPassword());
}

public function wrapStorage(Storage $storage) {
public function wrapStorage(IStorage $storage): IStorage {
return new SessionStorageWrapper(['storage' => $storage]);
}
}
12 changes: 5 additions & 7 deletions apps/files_external/lib/Lib/StorageModifierTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/
namespace OCA\Files_External\Lib;

use OCP\Files\Storage;
use OCP\Files\Storage\IStorage;
use OCP\Files\StorageNotAvailableException;
use OCP\IUser;

Expand All @@ -28,8 +28,8 @@ trait StorageModifierTrait {
/**
* Modify a StorageConfig parameters
*
* @param StorageConfig $storage
* @param IUser $user User the storage is being used as
* @param StorageConfig &$storage
* @param ?IUser $user User the storage is being used as
* @return void
* @throws InsufficientDataForMeaningfulAnswerException
* @throws StorageNotAvailableException
Expand All @@ -38,14 +38,12 @@ public function manipulateStorageConfig(StorageConfig &$storage, ?IUser $user =
}

/**
* Wrap a Storage if necessary
* Wrap a storage if necessary
*
* @param Storage $storage
* @return Storage
* @throws InsufficientDataForMeaningfulAnswerException
* @throws StorageNotAvailableException
*/
public function wrapStorage(Storage $storage) {
public function wrapStorage(IStorage $storage): IStorage {
return $storage;
}
}
1 change: 1 addition & 0 deletions apps/files_sharing/lib/External/Storage.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ public function getScanner($path = '', $storage = null) {
if (!isset($this->scanner)) {
$this->scanner = new Scanner($storage);
}
/** @var \OCA\Files_Sharing\External\Scanner */
return $this->scanner;
}

Expand Down
7 changes: 4 additions & 3 deletions apps/files_sharing/lib/SharedStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
use OCP\Files\IRootFolder;
use OCP\Files\NotFoundException;
use OCP\Files\Storage\IDisableEncryptionStorage;
use OCP\Files\Storage\ILockingStorage;
use OCP\Files\Storage\ISharedStorage;
use OCP\Files\Storage\IStorage;
use OCP\Lock\ILockingProvider;
Expand Down Expand Up @@ -494,7 +495,7 @@ public function unshareStorage(): bool {
* @throws \OCP\Lock\LockedException
*/
public function acquireLock($path, $type, ILockingProvider $provider) {
/** @var \OCP\Files\Storage $targetStorage */
/** @var ILockingStorage $targetStorage */
[$targetStorage, $targetInternalPath] = $this->resolvePath($path);
$targetStorage->acquireLock($targetInternalPath, $type, $provider);
// lock the parent folders of the owner when locking the share as recipient
Expand All @@ -510,7 +511,7 @@ public function acquireLock($path, $type, ILockingProvider $provider) {
* @param \OCP\Lock\ILockingProvider $provider
*/
public function releaseLock($path, $type, ILockingProvider $provider) {
/** @var \OCP\Files\Storage $targetStorage */
/** @var ILockingStorage $targetStorage */
[$targetStorage, $targetInternalPath] = $this->resolvePath($path);
$targetStorage->releaseLock($targetInternalPath, $type, $provider);
// unlock the parent folders of the owner when unlocking the share as recipient
Expand All @@ -526,7 +527,7 @@ public function releaseLock($path, $type, ILockingProvider $provider) {
* @param \OCP\Lock\ILockingProvider $provider
*/
public function changeLock($path, $type, ILockingProvider $provider) {
/** @var \OCP\Files\Storage $targetStorage */
/** @var ILockingStorage $targetStorage */
[$targetStorage, $targetInternalPath] = $this->resolvePath($path);
$targetStorage->changeLock($targetInternalPath, $type, $provider);
}
Expand Down
Loading

0 comments on commit b9fb1db

Please sign in to comment.