diff options
author | Richard Steinmetz <richard@steinmetz.cloud> | 2021-02-28 19:56:19 +0300 |
---|---|---|
committer | Richard Steinmetz <richard@steinmetz.cloud> | 2021-03-08 23:13:47 +0300 |
commit | a418e71274814618dcc9c03bacab78fcb46371a4 (patch) | |
tree | 580713e21c81b0f41ce4b808db9497fdc29cbe4e | |
parent | 431105ae4d4815a290eeee5233c4b494430a7e15 (diff) |
Use IRootFolder instead of IMountManager
Signed-off-by: Richard Steinmetz <richard@steinmetz.cloud>
-rw-r--r-- | lib/Controller/ChecksumController.php | 28 |
1 files changed, 16 insertions, 12 deletions
diff --git a/lib/Controller/ChecksumController.php b/lib/Controller/ChecksumController.php index ec69913..0f7d78d 100644 --- a/lib/Controller/ChecksumController.php +++ b/lib/Controller/ChecksumController.php @@ -4,9 +4,13 @@ declare(strict_types=1); namespace OCA\Checksum\Controller; +use OC\User\NoUserException; use OCP\AppFramework\Controller; use OCP\AppFramework\Http\JSONResponse; -use OCP\Files\Mount\IMountManager; +use OCP\Files\FileInfo; +use OCP\Files\IRootFolder; +use OCP\Files\NotFoundException; +use OCP\Files\NotPermittedException; use OCP\IL10N; use OCP\IRequest; use OCP\IUserSession; @@ -20,9 +24,9 @@ class ChecksumController extends Controller { private $language; /** - * @var IMountManager + * @var IRootFolder */ - private $mountManager; + private $rootFolder; /** * @var IUserSession @@ -35,20 +39,20 @@ class ChecksumController extends Controller { * @param string $appName * @param IRequest $request * @param IFactory $languageFactory - * @param IMountManager $mountManager + * @param IRootFolder $rootFolder * @param IUserSession $userSession */ public function __construct( string $appName, IRequest $request, IFactory $languageFactory, - IMountManager $mountManager, + IRootFolder $rootFolder, IUserSession $userSession ) { parent::__construct($appName, $request); $this->language = $languageFactory->get('checksum'); - $this->mountManager = $mountManager; + $this->rootFolder = $rootFolder; $this->userSession = $userSession; } @@ -97,18 +101,18 @@ class ChecksumController extends Controller { return null; } - $absPath = $user->getUID() . '/files/' . $source; - $mount = $this->mountManager->find($absPath); - if (!$mount) { + try { + $home = $this->rootFolder->getUserFolder($user->getUID()); + $node = $home->get($source); + } catch (NotPermittedException | NoUserException | NotFoundException $e) { return null; } - $internalPath = $mount->getInternalPath($absPath); - $file = $mount->getStorage()->fopen($internalPath, 'rb'); - if (!$file) { + if ($node->getType() !== FileInfo::TYPE_FILE) { return null; } + $file = $node->fopen('rb'); $hash = hash_init($type); hash_update_stream($hash, $file); fclose($file); |