Skip to content

Commit

Permalink
Only allow locally mounted storage on which the preview system has be…
Browse files Browse the repository at this point in the history
…en enabled

Fixes #13
  • Loading branch information
oparoz committed Jul 3, 2015
1 parent 5e45385 commit 352bd50
Showing 1 changed file with 35 additions and 7 deletions.
42 changes: 35 additions & 7 deletions service/filesservice.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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();
Expand Down Expand Up @@ -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
*
Expand All @@ -286,6 +313,7 @@ private function isExternalShareAllowed() {
/**
* Determines if the node is a share which is hosted externally
*
*
* @param Node $node
*
* @return bool
Expand Down

0 comments on commit 352bd50

Please sign in to comment.