Skip to content

Commit

Permalink
Refactor OC\Server::getLockingProvider
Browse files Browse the repository at this point in the history
Signed-off-by: Andrew Summers <18727110+summersab@users.noreply.github.com>
  • Loading branch information
summersab committed Aug 30, 2023
1 parent 613cd16 commit 22f4cac
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 8 deletions.
2 changes: 1 addition & 1 deletion lib/private/Files/Cache/Scanner.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public function __construct(\OC\Files\Storage\Storage $storage) {
$this->storageId = $this->storage->getId();
$this->cache = $storage->getCache();
$this->cacheActive = !\OC::$server->getConfig()->getSystemValueBool('filesystem_cache_readonly', false);
$this->lockingProvider = \OC::$server->getLockingProvider();
$this->lockingProvider = \OC::$server->get(ILockingProvider::class);
$this->connection = \OC::$server->get(IDBConnection::class);
}

Expand Down
3 changes: 2 additions & 1 deletion lib/private/Files/Utils/Scanner.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
use OCP\Files\Storage\IStorage;
use OCP\Files\StorageNotAvailableException;
use OCP\IDBConnection;
use OCP\Lock\ILockingProvider;
use Psr\Log\LoggerInterface;

/**
Expand Down Expand Up @@ -100,7 +101,7 @@ public function __construct($user, $db, IEventDispatcher $dispatcher, LoggerInte
$this->dispatcher = $dispatcher;
$this->logger = $logger;
// when DB locking is used, no DB transactions will be used
$this->useTransaction = !(\OC::$server->getLockingProvider() instanceof DBLockingProvider);
$this->useTransaction = !(\OC::$server->get(ILockingProvider::class) instanceof DBLockingProvider);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/private/Files/View.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public function __construct(string $root = '') {
}

$this->fakeRoot = $root;
$this->lockingProvider = \OC::$server->getLockingProvider();
$this->lockingProvider = \OC::$server->get(ILockingProvider::class);
$this->lockingEnabled = !($this->lockingProvider instanceof \OC\Lock\NoopLockingProvider);
$this->userManager = \OC::$server->getUserManager();
$this->logger = \OC::$server->get(LoggerInterface::class);
Expand Down
6 changes: 3 additions & 3 deletions tests/lib/Files/ViewTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1387,7 +1387,7 @@ public function testWriteToReadUnlockableFile($rootPath, $pathPrefix) {
* Test that locks are on mount point paths instead of mount root
*/
public function testLockLocalMountPointPathInsteadOfStorageRoot() {
$lockingProvider = \OC::$server->getLockingProvider();
$lockingProvider = \OC::$server->get(ILockingProvider::class);
$view = new View('/testuser/files/');
$storage = new Temporary([]);
Filesystem::mount($storage, [], '/');
Expand Down Expand Up @@ -1417,7 +1417,7 @@ public function testLockLocalMountPointPathInsteadOfStorageRoot() {
* Test that locks are on mount point paths and also mount root when requested
*/
public function testLockStorageRootButNotLocalMountPoint() {
$lockingProvider = \OC::$server->getLockingProvider();
$lockingProvider = \OC::$server->get(ILockingProvider::class);
$view = new View('/testuser/files/');
$storage = new Temporary([]);
Filesystem::mount($storage, [], '/');
Expand Down Expand Up @@ -1447,7 +1447,7 @@ public function testLockStorageRootButNotLocalMountPoint() {
* Test that locks are on mount point paths and also mount root when requested
*/
public function testLockMountPointPathFailReleasesBoth() {
$lockingProvider = \OC::$server->getLockingProvider();
$lockingProvider = \OC::$server->get(ILockingProvider::class);
$view = new View('/testuser/files/');
$storage = new Temporary([]);
Filesystem::mount($storage, [], '/');
Expand Down
5 changes: 3 additions & 2 deletions tests/lib/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
use OCP\IConfig;
use OCP\IDBConnection;
use OCP\IL10N;
use OCP\Lock\ILockingProvider;
use OCP\Security\ISecureRandom;
use Psr\Log\LoggerInterface;

Expand Down Expand Up @@ -176,7 +177,7 @@ protected function tearDown(): void {
// further cleanup
$hookExceptions = \OC_Hook::$thrownExceptions;
\OC_Hook::$thrownExceptions = [];
\OC::$server->getLockingProvider()->releaseAll();
\OC::$server->get(ILockingProvider::class)->releaseAll();
if (!empty($hookExceptions)) {
throw $hookExceptions[0];
}
Expand Down Expand Up @@ -395,7 +396,7 @@ protected static function tearDownAfterClassCleanStrayHooks() {
* Clean up the list of locks
*/
protected static function tearDownAfterClassCleanStrayLocks() {
\OC::$server->getLockingProvider()->releaseAll();
\OC::$server->get(ILockingProvider::class)->releaseAll();
}

/**
Expand Down

0 comments on commit 22f4cac

Please sign in to comment.