2020use OCP \Files \Mount \IMountManager ;
2121use OCP \Files \Mount \IMountPoint ;
2222use OCP \Files \Node ;
23- use OCP \Files \NotFoundException ;
2423use OCP \Files \Storage \IStorage ;
2524use OCP \IL10N ;
2625use OCP \IURLGenerator ;
2928use OCP \WorkflowEngine \IRuleMatcher ;
3029use OCP \WorkflowEngine \ISpecificOperation ;
3130use Psr \Log \LoggerInterface ;
32- use ReflectionClass ;
3331use UnexpectedValueException ;
3432
3533class Operation implements IComplexOperation, ISpecificOperation {
@@ -50,20 +48,24 @@ public function __construct(
5048 * @param array|ICacheEntry|null $cacheEntry
5149 * @throws ForbiddenException
5250 */
53- public function checkFileAccess (IStorage $ storage , string $ path , bool $ isDir = false , $ cacheEntry = null ): void {
54- if (!$ this ->isBlockablePath ($ storage , $ path ) || $ this ->isCreatingSkeletonFiles () || $ this ->nestingLevel !== 0 ) {
51+ public function checkFileAccess (string $ path , IMountPoint $ mountPoint , bool $ isDir , $ cacheEntry = null ): void {
52+ if (!$ this ->isBlockablePath ($ mountPoint , $ path ) || $ this ->isCreatingSkeletonFiles () || $ this ->nestingLevel !== 0 ) {
5553 // Allow creating skeletons and theming
5654 // https://github.com/nextcloud/files_accesscontrol/issues/5
5755 // https://github.com/nextcloud/files_accesscontrol/issues/12
5856 return ;
5957 }
58+ $ storage = $ mountPoint ->getStorage ();
59+ if ($ storage === null ) {
60+ return ;
61+ }
6062
6163 $ this ->nestingLevel ++;
6264
6365 $ filePath = $ this ->translatePath ($ storage , $ path );
6466 $ ruleMatcher = $ this ->manager ->getRuleMatcher ();
6567 $ ruleMatcher ->setFileInfo ($ storage , $ filePath , $ isDir );
66- $ node = $ this ->getNode ($ storage , $ path , $ cacheEntry );
68+ $ node = $ this ->getNode ($ path , $ mountPoint , $ cacheEntry );
6769 if ($ node !== null ) {
6870 $ ruleMatcher ->setEntitySubject ($ this ->fileEntity , $ node );
6971 }
@@ -80,24 +82,8 @@ public function checkFileAccess(IStorage $storage, string $path, bool $isDir = f
8082 }
8183 }
8284
83- protected function isBlockablePath (IStorage $ storage , string $ path ): bool {
84- if (property_exists ($ storage , 'mountPoint ' )) {
85- $ hasMountPoint = $ storage instanceof StorageWrapper;
86- if (!$ hasMountPoint ) {
87- $ ref = new ReflectionClass ($ storage );
88- $ prop = $ ref ->getProperty ('mountPoint ' );
89- $ hasMountPoint = $ prop ->isPublic ();
90- }
91-
92- if ($ hasMountPoint ) {
93- /** @var StorageWrapper $storage */
94- $ fullPath = $ storage ->mountPoint . ltrim ($ path , '/ ' );
95- } else {
96- $ fullPath = $ path ;
97- }
98- } else {
99- $ fullPath = $ path ;
100- }
85+ protected function isBlockablePath (IMountPoint $ mountPoint , string $ path ): bool {
86+ $ fullPath = $ mountPoint ->getMountPoint () . ltrim ($ path , '/ ' );
10187
10288 if (substr_count ($ fullPath , '/ ' ) < 3 ) {
10389 return false ;
@@ -297,40 +283,22 @@ public function onEvent(string $eventName, Event $event, IRuleMatcher $ruleMatch
297283 // Noop
298284 }
299285
300- /**
301- * @param array|ICacheEntry|null $cacheEntry
302- */
303- private function getNode (IStorage $ storage , string $ path , $ cacheEntry = null ): ?Node {
304- if ($ storage ->instanceOfStorage (StorageWrapper::class)) {
305- /** @var StorageWrapper $storage */
306- $ mountPoint = $ storage ->getMount ();
307- } else {
308- // fairly sure this branch is never taken, but not 100%
309-
310- /** @var IMountPoint|false $mountPoint */
311- $ mountPoint = current ($ this ->mountManager ->findByStorageId ($ storage ->getId ()));
312- if (!$ mountPoint ) {
313- return null ;
314- }
286+ private function getNode (string $ path , IMountPoint $ mountPoint , ICacheEntry |array |null $ cacheEntry = null ): ?Node {
287+ $ fullPath = $ mountPoint ->getMountPoint () . $ path ;
288+ if (!$ cacheEntry ) {
289+ $ cacheEntry = $ mountPoint ->getStorage ()?->getCache()->get ($ path );
290+ }
291+ if (!$ cacheEntry ) {
292+ return null ;
315293 }
316294
317- $ fullPath = $ mountPoint ->getMountPoint () . $ path ;
318- if ($ cacheEntry ) {
319- // todo: LazyNode?
320- $ info = new FileInfo ($ fullPath , $ mountPoint ->getStorage (), $ path , $ cacheEntry , $ mountPoint );
321- $ isDir = $ info ->getType () === \OCP \Files \FileInfo::TYPE_FOLDER ;
322- $ view = new View ('' );
323- if ($ isDir ) {
324- return new Folder ($ this ->rootFolder , $ view , $ path , $ info );
325- } else {
326- return new \OC \Files \Node \File ($ this ->rootFolder , $ view , $ path , $ info );
327- }
328- } else {
329- try {
330- return $ this ->rootFolder ->get ($ fullPath );
331- } catch (NotFoundException $ e ) {
332- return null ;
333- }
295+ // todo: LazyNode?
296+ $ info = new FileInfo ($ fullPath , $ mountPoint ->getStorage (), $ path , $ cacheEntry , $ mountPoint );
297+ $ isDir = $ info ->getType () === \OCP \Files \FileInfo::TYPE_FOLDER ;
298+ $ view = new View ('' );
299+ if ($ isDir ) {
300+ return new Folder ($ this ->rootFolder , $ view , $ path , $ info );
334301 }
302+ return new \OC \Files \Node \File ($ this ->rootFolder , $ view , $ path , $ info );
335303 }
336304}
0 commit comments