Skip to content

Commit

Permalink
Merge pull request #213 from nextcloud/backport/212/stable18
Browse files Browse the repository at this point in the history
[stable18] Don't flatten out albums
  • Loading branch information
skjnldsv authored Feb 28, 2020
2 parents 80a17d9 + 7848b3e commit c413c80
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions lib/Controller/AlbumsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}
}

0 comments on commit c413c80

Please sign in to comment.