From 3183919ec707e896feac61de01b2d51f1eb88dc2 Mon Sep 17 00:00:00 2001 From: Olivier Paroz Date: Tue, 21 Apr 2015 19:21:23 +0200 Subject: [PATCH] Only allow locally mounted storage on which the preview system has been enabled Fixes #13 --- service/filesservice.php | 42 +++++++++++++++++++++++++++++++++------- 1 file changed, 35 insertions(+), 7 deletions(-) diff --git a/service/filesservice.php b/service/filesservice.php index 1c02a0c447..756075477c 100644 --- a/service/filesservice.php +++ b/service/filesservice.php @@ -106,7 +106,8 @@ protected function getNodes($folder, $subDepth) { } /** - * Determines if the files are hosted locally (shared or not) + * Determines if the files are hosted locally (shared or not) and can be used by the preview + * system * * isMounted() doesn't include externally hosted shares, so we need to exclude those from the * non-mounted nodes @@ -118,12 +119,7 @@ protected function getNodes($folder, $subDepth) { protected function isAllowedAndAvailable($node) { try { if (!$node->isMounted()) { - $allowed = $node->isReadable(); - if ($this->isExternalShare($node)) { - $allowed = $allowed && $this->isExternalShareAllowed(); - } - - return $allowed; + return $this->isAllowed($node) && $this->isAvailable($node); } } catch (\Exception $exception) { $message = 'The folder is not available: ' . $exception->getMessage(); @@ -269,6 +265,37 @@ private function recoverFromGetNodesError($subDepth, $exception) { return []; } + /** + * Determines if we can consider the node mounted locally or if it's been authorised to be + * scanned + * + * @param Node $node + * + * @return bool + */ + private function isAllowed($node) { + $allowed = true; + if ($this->isExternalShare($node)) { + $allowed = $this->isExternalShareAllowed(); + } + $mount = $node->getMountPoint(); + + return $allowed && $mount && $mount->getOption('previews', true); + } + + /** + * Determines if the node is available, as in readable + * + * @todo Test to see by how much using file_exists slows things down + * + * @param Node $node + * + * @return bool + */ + private function isAvailable($node) { + return $node->isReadable(); + } + /** * Determines if the user has allowed the use of external shares * @@ -286,6 +313,7 @@ private function isExternalShareAllowed() { /** * Determines if the node is a share which is hosted externally * + * * @param Node $node * * @return bool