From 40edb426a3a6857598ff3f447a85e83e32ff0c32 Mon Sep 17 00:00:00 2001 From: Andrew Summers <18727110+summersab@users.noreply.github.com> Date: Tue, 29 Aug 2023 18:50:12 -0500 Subject: [PATCH] Refactor `OC\Server::getRootFolder` Signed-off-by: Andrew Summers <18727110+summersab@users.noreply.github.com> --- lib/private/Streamer.php | 3 ++- lib/private/legacy/OC_Files.php | 5 +++-- tests/lib/Preview/BackgroundCleanupJobTest.php | 4 ++-- tests/lib/Preview/Provider.php | 3 ++- tests/lib/Share20/DefaultShareProviderTest.php | 6 +++--- 5 files changed, 12 insertions(+), 9 deletions(-) diff --git a/lib/private/Streamer.php b/lib/private/Streamer.php index aafd3d95dfbcb..4a88278ed9948 100644 --- a/lib/private/Streamer.php +++ b/lib/private/Streamer.php @@ -32,6 +32,7 @@ use OCP\Files\File; use OCP\Files\Folder; use OCP\Files\InvalidPathException; +use OCP\Files\IRootFolder; use OCP\Files\NotFoundException; use OCP\Files\NotPermittedException; use OCP\IRequest; @@ -118,7 +119,7 @@ public function addDirRecursive(string $dir, string $internalDir = ''): void { // prevent absolute dirs $internalDir = ltrim($internalDir, '/'); - $userFolder = \OC::$server->getRootFolder()->get(Filesystem::getRoot()); + $userFolder = \OC::$server->get(IRootFolder::class)->get(Filesystem::getRoot()); /** @var Folder $dirNode */ $dirNode = $userFolder->get($dir); $files = $dirNode->getDirectoryListing(); diff --git a/lib/private/legacy/OC_Files.php b/lib/private/legacy/OC_Files.php index ac0a2bbd0e9f3..ee3be30948bed 100644 --- a/lib/private/legacy/OC_Files.php +++ b/lib/private/legacy/OC_Files.php @@ -46,6 +46,7 @@ use OCP\Lock\ILockingProvider; use OCP\Files\Events\BeforeZipCreatedEvent; use OCP\Files\Events\BeforeDirectFileDownloadEvent; +use OCP\Files\IRootFolder; use OCP\EventDispatcher\IEventDispatcher; /** @@ -187,7 +188,7 @@ public static function get($dir, $files, $params = null) { foreach ($files as $file) { $file = $dir . '/' . $file; if (\OC\Files\Filesystem::is_file($file)) { - $userFolder = \OC::$server->getRootFolder()->get(\OC\Files\Filesystem::getRoot()); + $userFolder = \OC::$server->get(IRootFolder::class)->get(\OC\Files\Filesystem::getRoot()); $file = $userFolder->get($file); if ($file instanceof \OC\Files\Node\File) { try { @@ -307,7 +308,7 @@ private static function getSingleFile($view, $dir, $name, $params) { $file = null; try { - $userFolder = \OC::$server->getRootFolder()->get(\OC\Files\Filesystem::getRoot()); + $userFolder = \OC::$server->get(IRootFolder::class)->get(\OC\Files\Filesystem::getRoot()); $file = $userFolder->get($filename); if (!$file instanceof \OC\Files\Node\File || !$file->isReadable()) { http_response_code(403); diff --git a/tests/lib/Preview/BackgroundCleanupJobTest.php b/tests/lib/Preview/BackgroundCleanupJobTest.php index aa15ea7f562d9..3b95676e4708a 100644 --- a/tests/lib/Preview/BackgroundCleanupJobTest.php +++ b/tests/lib/Preview/BackgroundCleanupJobTest.php @@ -84,7 +84,7 @@ protected function setUp(): void { $this->connection = \OC::$server->getDatabaseConnection(); $this->previewManager = \OC::$server->getPreviewManager(); - $this->rootFolder = \OC::$server->getRootFolder(); + $this->rootFolder = \OC::$server->get(IRootFolder::class); $this->mimeTypeLoader = \OC::$server->getMimeTypeLoader(); $this->timeFactory = \OCP\Server::get(ITimeFactory::class); } @@ -102,7 +102,7 @@ protected function tearDown(): void { private function getRoot(): Root { return new Root( - \OC::$server->getRootFolder(), + \OC::$server->get(IRootFolder::class), \OC::$server->getSystemConfig() ); } diff --git a/tests/lib/Preview/Provider.php b/tests/lib/Preview/Provider.php index a2e5170c82cd0..b4b50c873a5ae 100644 --- a/tests/lib/Preview/Provider.php +++ b/tests/lib/Preview/Provider.php @@ -22,6 +22,7 @@ namespace Test\Preview; use OC\Files\Node\File; +use OCP\Files\IRootFolder; abstract class Provider extends \Test\TestCase { /** @var string */ @@ -137,7 +138,7 @@ protected function prepareTestFile($fileName, $fileContent) { * @return bool|\OCP\IImage */ private function getPreview($provider) { - $file = new File(\OC::$server->getRootFolder(), $this->rootView, $this->imgPath); + $file = new File(\OC::$server->get(IRootFolder::class), $this->rootView, $this->imgPath); $preview = $provider->getThumbnail($file, $this->maxWidth, $this->maxHeight, $this->scalingUp); if (get_class($this) === BitmapTest::class && $preview === null) { diff --git a/tests/lib/Share20/DefaultShareProviderTest.php b/tests/lib/Share20/DefaultShareProviderTest.php index 0ce96102a30d2..afa428014f80c 100644 --- a/tests/lib/Share20/DefaultShareProviderTest.php +++ b/tests/lib/Share20/DefaultShareProviderTest.php @@ -2514,7 +2514,7 @@ public function testUserDeletedFromGroup($group, $user, $toDelete) { public function testGetSharesInFolder() { $userManager = \OC::$server->getUserManager(); $groupManager = \OC::$server->getGroupManager(); - $rootFolder = \OC::$server->getRootFolder(); + $rootFolder = \OC::$server->get(IRootFolder::class); $provider = new DefaultShareProvider( $this->dbConn, @@ -2612,7 +2612,7 @@ public function testGetSharesInFolder() { public function testGetAccessListNoCurrentAccessRequired() { $userManager = \OC::$server->getUserManager(); $groupManager = \OC::$server->getGroupManager(); - $rootFolder = \OC::$server->getRootFolder(); + $rootFolder = \OC::$server->get(IRootFolder::class); $provider = new DefaultShareProvider( $this->dbConn, @@ -2708,7 +2708,7 @@ public function testGetAccessListNoCurrentAccessRequired() { public function testGetAccessListCurrentAccessRequired() { $userManager = \OC::$server->getUserManager(); $groupManager = \OC::$server->getGroupManager(); - $rootFolder = \OC::$server->getRootFolder(); + $rootFolder = \OC::$server->get(IRootFolder::class); $provider = new DefaultShareProvider( $this->dbConn,