Skip to content

Commit e667522

Browse files
committed
Add helper method in Wrapper
Signed-off-by: Carl Schwan <carl@carlschwan.eu>
1 parent 407a4b1 commit e667522

File tree

2 files changed

+25
-13
lines changed

2 files changed

+25
-13
lines changed

apps/workflowengine/lib/Check/FileSystemTags.php

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,6 @@ public function __construct(IL10N $l, ISystemTagManager $systemTagManager, ISyst
7373
* @return bool
7474
*/
7575
public function executeCheck($operator, $value) {
76-
if (str_starts_with($this->path, '__groupfolders')) {
77-
// System tags are always empty in this case and executeCheck is called
78-
// a second time with the jailedPath
79-
return false;
80-
}
8176
$systemTags = $this->getSystemTags();
8277
return ($operator === 'is') === in_array($value, $systemTags);
8378
}
@@ -143,13 +138,11 @@ protected function getFileIds(ICache $cache, $path, $isExternalStorage) {
143138
// Special implementation for groupfolder since all groupfolders share the same storage
144139
// id so add the group folder id in the cache key too.
145140
$groupFolderStorage = $this->storage;
146-
$groupFolderStorageClass = \OCA\GroupFolders\Mount\GroupFolderStorage::class;
147-
while ($groupFolderStorage->instanceOfStorage(Wrapper::class)) {
148-
if ($groupFolderStorage instanceof $groupFolderStorageClass) {
149-
break;
150-
}
151-
/** @var Wrapper $groupFolderStorage */
152-
$groupFolderStorage = $groupFolderStorage->getWrapperStorage();
141+
if ($this->storage instanceof Wrapper) {
142+
$groupFolderStorage = $this->storage->getInstanceOfStorage(\OCA\GroupFolders\Mount\GroupFolderStorage::class);
143+
}
144+
if ($groupFolderStorage === null) {
145+
throw new \LogicException('Should not happen: Storage is instance of GroupFolderStorage but no group folder storage found while unwrapping.');
153146
}
154147
/** @psalm-suppress UndefinedMethod */
155148
$cacheId = $cache->getNumericStorageId() . '/' . $groupFolderStorage->getFolderId();

lib/private/Files/Storage/Wrapper/Wrapper.php

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,7 @@ public function isLocal() {
486486
/**
487487
* Check if the storage is an instance of $class or is a wrapper for a storage that is an instance of $class
488488
*
489-
* @param string $class
489+
* @param class-string<IStorage> $class
490490
* @return bool
491491
*/
492492
public function instanceOfStorage($class) {
@@ -497,6 +497,25 @@ public function instanceOfStorage($class) {
497497
return is_a($this, $class) or $this->getWrapperStorage()->instanceOfStorage($class);
498498
}
499499

500+
/**
501+
* @template T of IStorage
502+
* @param class-string<T> $class
503+
* @return ?T
504+
*/
505+
public function getInstanceOfStorage(string $class): ?IStorage {
506+
$storage = $this;
507+
while ($storage->instanceOfStorage(Wrapper::class)) {
508+
if ($storage instanceof $class) {
509+
break;
510+
}
511+
$storage = $storage->getWrapperStorage();
512+
}
513+
if (!is_a($storage, $class)) {
514+
return null;
515+
}
516+
return $storage;
517+
}
518+
500519
/**
501520
* Pass any methods custom to specific storage implementations to the wrapped storage
502521
*

0 commit comments

Comments
 (0)