]> source.dussan.org Git - nextcloud-server.git/commitdiff
Add helper method in Wrapper
authorCarl Schwan <carl@carlschwan.eu>
Mon, 10 Jan 2022 10:36:51 +0000 (11:36 +0100)
committerCarl Schwan <carl@carlschwan.eu>
Thu, 13 Jan 2022 09:39:36 +0000 (10:39 +0100)
Signed-off-by: Carl Schwan <carl@carlschwan.eu>
apps/workflowengine/lib/Check/FileSystemTags.php
lib/private/Files/Storage/Wrapper/Wrapper.php

index b6ad95a4ab6d76a124963109d32fd0d8a758286c..d3f02729f2f70ee3884c033ca524ccf1ef410b60 100644 (file)
@@ -73,11 +73,6 @@ class FileSystemTags implements ICheck, IFileCheck {
         * @return bool
         */
        public function executeCheck($operator, $value) {
-               if (str_starts_with($this->path,  '__groupfolders')) {
-                       // System tags are always empty in this case and executeCheck is called
-                       // a second time with the jailedPath
-                       return false;
-               }
                $systemTags = $this->getSystemTags();
                return ($operator === 'is') === in_array($value, $systemTags);
        }
@@ -143,13 +138,11 @@ class FileSystemTags implements ICheck, IFileCheck {
                        // Special implementation for groupfolder since all groupfolders share the same storage
                        // id so add the group folder id in the cache key too.
                        $groupFolderStorage = $this->storage;
-                       $groupFolderStorageClass = \OCA\GroupFolders\Mount\GroupFolderStorage::class;
-                       while ($groupFolderStorage->instanceOfStorage(Wrapper::class)) {
-                               if ($groupFolderStorage instanceof $groupFolderStorageClass) {
-                                       break;
-                               }
-                               /** @var Wrapper $groupFolderStorage */
-                               $groupFolderStorage = $groupFolderStorage->getWrapperStorage();
+                       if ($this->storage instanceof Wrapper) {
+                               $groupFolderStorage = $this->storage->getInstanceOfStorage(\OCA\GroupFolders\Mount\GroupFolderStorage::class);
+                       }
+                       if ($groupFolderStorage === null) {
+                               throw new \LogicException('Should not happen: Storage is instance of GroupFolderStorage but no group folder storage found while unwrapping.');
                        }
                        /** @psalm-suppress UndefinedMethod */
                        $cacheId = $cache->getNumericStorageId() . '/' . $groupFolderStorage->getFolderId();
index 5faffece67e3a70b48c96d7d179e1b8ab35455fe..b44db7c13cea73a146849c4e2fa5e59c174abda2 100644 (file)
@@ -486,7 +486,7 @@ class Wrapper implements \OC\Files\Storage\Storage, ILockingStorage, IWriteStrea
        /**
         * Check if the storage is an instance of $class or is a wrapper for a storage that is an instance of $class
         *
-        * @param string $class
+        * @param class-string<IStorage> $class
         * @return bool
         */
        public function instanceOfStorage($class) {
@@ -497,6 +497,25 @@ class Wrapper implements \OC\Files\Storage\Storage, ILockingStorage, IWriteStrea
                return is_a($this, $class) or $this->getWrapperStorage()->instanceOfStorage($class);
        }
 
+       /**
+        * @template T of IStorage
+        * @param class-string<T> $class
+        * @return ?T
+        */
+       public function getInstanceOfStorage(string $class): ?IStorage {
+               $storage = $this;
+               while ($storage->instanceOfStorage(Wrapper::class)) {
+                       if ($storage instanceof $class) {
+                               break;
+                       }
+                       $storage = $storage->getWrapperStorage();
+               }
+               if (!is_a($storage, $class)) {
+                       return null;
+               }
+               return $storage;
+       }
+
        /**
         * Pass any methods custom to specific storage implementations to the wrapped storage
         *