userFolder->get($file); if ($info instanceof File) { // access to filecache is expensive in the loop if (!$this->checkFileInfo($info)) { return false; } } elseif ($info instanceof Folder) { // get directory content is rather cheap query if (!$this->dirRecursiveCheck($info)) { return false; } } } catch (NotFoundException $e) { continue; } } return true; } /** * @param Folder $dirInfo * @return bool * @throws NotFoundException */ private function dirRecursiveCheck(Folder $dirInfo): bool { if (!$this->checkFileInfo($dirInfo)) { return false; } // If any of elements cannot be downloaded, prevent whole download $files = $dirInfo->getDirectoryListing(); foreach ($files as $file) { if ($file instanceof File) { if (!$this->checkFileInfo($file)) { return false; } } elseif ($file instanceof Folder) { return $this->dirRecursiveCheck($file); } } return true; } /** * @param Node $fileInfo * @return bool * @throws NotFoundException */ private function checkFileInfo(Node $fileInfo): bool { // Restrict view-only to nodes which are shared $storage = $fileInfo->getStorage(); if (!$storage->instanceOfStorage(SharedStorage::class)) { return true; } // Extract extra permissions /** @var SharedStorage $storage */ $share = $storage->getShare(); // Check whether download-permission was denied (granted if not set) $attributes = $share->getAttributes(); $canDownload = $attributes?->getAttribute('permissions', 'download'); return $canDownload !== false; } }