Skip to content

Commit

Permalink
Refactor OC\Server::getRootFolder
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 fc9c9fb
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 9 deletions.
3 changes: 2 additions & 1 deletion lib/private/Streamer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down
5 changes: 3 additions & 2 deletions lib/private/legacy/OC_Files.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -188,7 +189,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 {
Expand Down Expand Up @@ -304,7 +305,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);
Expand Down
4 changes: 2 additions & 2 deletions tests/lib/Preview/BackgroundCleanupJobTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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()
);
}
Expand Down
3 changes: 2 additions & 1 deletion tests/lib/Preview/Provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
namespace Test\Preview;

use OC\Files\Node\File;
use OCP\Files\IRootFolder;

abstract class Provider extends \Test\TestCase {
/** @var string */
Expand Down Expand Up @@ -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) {
Expand Down
6 changes: 3 additions & 3 deletions tests/lib/Share20/DefaultShareProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2513,7 +2513,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,
Expand Down Expand Up @@ -2611,7 +2611,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,
Expand Down Expand Up @@ -2707,7 +2707,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,
Expand Down

0 comments on commit fc9c9fb

Please sign in to comment.