diff --git a/lib/Controller/AlbumsController.php b/lib/Controller/AlbumsController.php index fa8cfed90..fc3044b54 100644 --- a/lib/Controller/AlbumsController.php +++ b/lib/Controller/AlbumsController.php @@ -116,8 +116,8 @@ private function scanCurrentFolder(Folder $folder, bool $shared): iterable { yield $folder; foreach ($nodes as $node) { - if ($node instanceof Folder) { - yield from $this->scanFolder($node, 0, $shared); + if ($node instanceof Folder && $this->scanFolder($node, 0, $shared)) { + yield $node; } elseif ($node instanceof File) { if ($this->validFile($node, $shared)) { yield $node; @@ -138,35 +138,38 @@ private function isShared(Node $node): bool { return $node->getStorage()->instanceOfStorage(SharedStorage::class); } - private function scanFolder(Folder $folder, int $depth, bool $shared): iterable { + private function scanFolder(Folder $folder, int $depth, bool $shared): bool { if ($depth > 4) { - return []; + return false; } try { // Ignore folder with a .noimage or .nomedia node if ($folder->nodeExists('.noimage') || $folder->nodeExists('.nomedia')) { - return []; + return false; } $nodes = $folder->getDirectoryListing(); } catch (StorageNotAvailableException $e) { - return []; + return false; } foreach ($nodes as $node) { if ($node instanceof File) { if ($this->validFile($node, $shared)) { - yield $folder; - return []; + return true; } } } foreach ($nodes as $node) { if ($node instanceof Folder && $this->isShared($node) === $shared) { - yield from $this->scanFolder($node, $depth + 1, $shared); + if ($this->scanFolder($node, $depth + 1, $shared)) { + return true; + } } } + + return false; } }