summaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
authorThomas Müller <thomas.mueller@tmit.eu>2016-03-15 12:15:05 +0100
committerThomas Müller <thomas.mueller@tmit.eu>2016-03-15 12:15:05 +0100
commit0f6ea9fd292a26572f28440ee71bc1a4453906b9 (patch)
tree4fff82916a0d6d35b99018d516409ec3032bd37e /apps
parente9eeb3607fe0ba15413c1c22b1120fc53aaed6dc (diff)
parenta8db587b1f036bba917288372405d8d830faee54 (diff)
downloadnextcloud-server-0f6ea9fd292a26572f28440ee71bc1a4453906b9.tar.gz
nextcloud-server-0f6ea9fd292a26572f28440ee71bc1a4453906b9.zip
Merge pull request #23039 from owncloud/invalid-share-storage
dont break when there is an invalid share
Diffstat (limited to 'apps')
-rw-r--r--apps/files_external/lib/config/configadapter.php2
-rw-r--r--apps/files_external/lib/failedcache.php131
-rw-r--r--apps/files_external/lib/failedstorage.php215
-rw-r--r--apps/files_sharing/lib/sharedstorage.php24
4 files changed, 20 insertions, 352 deletions
diff --git a/apps/files_external/lib/config/configadapter.php b/apps/files_external/lib/config/configadapter.php
index d85e0f45631..a19a111d3d9 100644
--- a/apps/files_external/lib/config/configadapter.php
+++ b/apps/files_external/lib/config/configadapter.php
@@ -34,7 +34,7 @@ use OCP\IUser;
use OCA\Files_external\Service\UserStoragesService;
use OCA\Files_External\Service\UserGlobalStoragesService;
use OCA\Files_External\Lib\StorageConfig;
-use OCA\Files_External\Lib\FailedStorage;
+use OC\Files\Storage\FailedStorage;
use OCP\Files\StorageNotAvailableException;
/**
diff --git a/apps/files_external/lib/failedcache.php b/apps/files_external/lib/failedcache.php
deleted file mode 100644
index 0f59495e595..00000000000
--- a/apps/files_external/lib/failedcache.php
+++ /dev/null
@@ -1,131 +0,0 @@
-<?php
-/**
- * @author Robin Appelman <icewind@owncloud.com>
- *
- * @copyright Copyright (c) 2016, ownCloud, Inc.
- * @license AGPL-3.0
- *
- * This code is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License, version 3,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License, version 3,
- * along with this program. If not, see <http://www.gnu.org/licenses/>
- *
- */
-
-namespace OCA\Files_External\Lib;
-
-use OC\Files\Cache\CacheEntry;
-use OCP\Constants;
-use OCP\Files\Cache\ICache;
-
-/**
- * Storage placeholder to represent a missing precondition, storage unavailable
- */
-class FailedCache implements ICache {
-
- public function getNumericStorageId() {
- return -1;
- }
-
- public function get($file) {
- if ($file === '') {
- return new CacheEntry([
- 'fileid' => -1,
- 'size' => 0,
- 'mimetype' => 'httpd/unix-directory',
- 'mimepart' => 'httpd',
- 'permissions' => Constants::PERMISSION_READ,
- 'mtime' => time()
- ]);
- } else {
- return false;
- }
- }
-
- public function getFolderContents($folder) {
- return [];
- }
-
- public function getFolderContentsById($fileId) {
- return [];
- }
-
- public function put($file, array $data) {
- return;
- }
-
- public function insert($file, array $data) {
- return;
- }
-
- public function update($id, array $data) {
- return;
- }
-
- public function getId($file) {
- return -1;
- }
-
- public function getParentId($file) {
- return -1;
- }
-
- public function inCache($file) {
- return false;
- }
-
- public function remove($file) {
- return;
- }
-
- public function move($source, $target) {
- return;
- }
-
- public function moveFromCache(ICache $sourceCache, $sourcePath, $targetPath) {
- return;
- }
-
- public function clear() {
- return;
- }
-
- public function getStatus($file) {
- return ICache::NOT_FOUND;
- }
-
- public function search($pattern) {
- return [];
- }
-
- public function searchByMime($mimetype) {
- return [];
- }
-
- public function searchByTag($tag, $userId) {
- return [];
- }
-
- public function getAll() {
- return [];
- }
-
- public function getIncomplete() {
- return [];
- }
-
- public function getPathById($id) {
- return null;
- }
-
- public function normalize($path) {
- return $path;
- }
-}
diff --git a/apps/files_external/lib/failedstorage.php b/apps/files_external/lib/failedstorage.php
deleted file mode 100644
index 20cf43d74b2..00000000000
--- a/apps/files_external/lib/failedstorage.php
+++ /dev/null
@@ -1,215 +0,0 @@
-<?php
-/**
- * @author Robin Appelman <icewind@owncloud.com>
- * @author Robin McCorkell <robin@mccorkell.me.uk>
- *
- * @copyright Copyright (c) 2016, ownCloud, Inc.
- * @license AGPL-3.0
- *
- * This code is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License, version 3,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License, version 3,
- * along with this program. If not, see <http://www.gnu.org/licenses/>
- *
- */
-
-namespace OCA\Files_External\Lib;
-
-use \OCP\Lock\ILockingProvider;
-use \OC\Files\Storage\Common;
-use \OCP\Files\StorageNotAvailableException;
-
-/**
- * Storage placeholder to represent a missing precondition, storage unavailable
- */
-class FailedStorage extends Common {
-
- /** @var \Exception */
- protected $e;
-
- /**
- * @param array $params ['exception' => \Exception]
- */
- public function __construct($params) {
- $this->e = $params['exception'];
- if (!$this->e) {
- throw new \InvalidArgumentException('Missing "exception" argument in FailedStorage constructor');
- }
- }
-
- public function getId() {
- // we can't return anything sane here
- return 'failedstorage';
- }
-
- public function mkdir($path) {
- throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
- }
-
- public function rmdir($path) {
- throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
- }
-
- public function opendir($path) {
- throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
- }
-
- public function is_dir($path) {
- throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
- }
-
- public function is_file($path) {
- throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
- }
-
- public function stat($path) {
- throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
- }
-
- public function filetype($path) {
- throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
- }
-
- public function filesize($path) {
- throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
- }
-
- public function isCreatable($path) {
- throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
- }
-
- public function isReadable($path) {
- throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
- }
-
- public function isUpdatable($path) {
- throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
- }
-
- public function isDeletable($path) {
- throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
- }
-
- public function isSharable($path) {
- throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
- }
-
- public function getPermissions($path) {
- throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
- }
-
- public function file_exists($path) {
- throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
- }
-
- public function filemtime($path) {
- throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
- }
-
- public function file_get_contents($path) {
- throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
- }
-
- public function file_put_contents($path, $data) {
- throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
- }
-
- public function unlink($path) {
- throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
- }
-
- public function rename($path1, $path2) {
- throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
- }
-
- public function copy($path1, $path2) {
- throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
- }
-
- public function fopen($path, $mode) {
- throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
- }
-
- public function getMimeType($path) {
- throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
- }
-
- public function hash($type, $path, $raw = false) {
- throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
- }
-
- public function free_space($path) {
- throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
- }
-
- public function search($query) {
- throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
- }
-
- public function touch($path, $mtime = null) {
- throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
- }
-
- public function getLocalFile($path) {
- throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
- }
-
- public function getLocalFolder($path) {
- throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
- }
-
- public function hasUpdated($path, $time) {
- throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
- }
-
- public function getETag($path) {
- throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
- }
-
- public function getDirectDownload($path) {
- throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
- }
-
- public function verifyPath($path, $fileName) {
- return true;
- }
-
- public function copyFromStorage(\OCP\Files\Storage $sourceStorage, $sourceInternalPath, $targetInternalPath) {
- throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
- }
-
- public function moveFromStorage(\OCP\Files\Storage $sourceStorage, $sourceInternalPath, $targetInternalPath) {
- throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
- }
-
- public function acquireLock($path, $type, ILockingProvider $provider) {
- throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
- }
-
- public function releaseLock($path, $type, ILockingProvider $provider) {
- throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
- }
-
- public function changeLock($path, $type, ILockingProvider $provider) {
- throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
- }
-
- public function getAvailability() {
- throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
- }
-
- public function setAvailability($isAvailable) {
- throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
- }
-
- public function getCache($path = '', $storage = null) {
- return new FailedCache();
- }
-}
diff --git a/apps/files_sharing/lib/sharedstorage.php b/apps/files_sharing/lib/sharedstorage.php
index 6998f94698e..8f4888d20e2 100644
--- a/apps/files_sharing/lib/sharedstorage.php
+++ b/apps/files_sharing/lib/sharedstorage.php
@@ -31,6 +31,7 @@
namespace OC\Files\Storage;
use OC\Files\Filesystem;
+use OC\Files\Cache\FailedCache;
use OCA\Files_Sharing\ISharedStorage;
use OCP\Constants;
use OCP\Files\Cache\ICacheEntry;
@@ -67,10 +68,16 @@ class Shared extends \OC\Files\Storage\Common implements ISharedStorage {
*/
private $sourceStorage;
+ /**
+ * @var \OCP\ILogger
+ */
+ private $logger;
+
public function __construct($arguments) {
$this->share = $arguments['share'];
$this->ownerView = $arguments['ownerView'];
$this->user = $arguments['user'];
+ $this->logger = \OC::$server->getLogger();
}
private function init() {
@@ -78,15 +85,19 @@ class Shared extends \OC\Files\Storage\Common implements ISharedStorage {
return;
}
$this->initialized = true;
- Filesystem::initMountPoints($this->share['uid_owner']);
- $sourcePath = $this->ownerView->getPath($this->share['file_source']);
- list($this->sourceStorage, $sourceInternalPath) = $this->ownerView->resolvePath($sourcePath);
- $this->sourceRootInfo = $this->sourceStorage->getCache()->get($sourceInternalPath);
+ try {
+ Filesystem::initMountPoints($this->share['uid_owner']);
+ $sourcePath = $this->ownerView->getPath($this->share['file_source']);
+ list($this->sourceStorage, $sourceInternalPath) = $this->ownerView->resolvePath($sourcePath);
+ $this->sourceRootInfo = $this->sourceStorage->getCache()->get($sourceInternalPath);
+ } catch (\Exception $e) {
+ $this->logger->logException($e);
+ }
}
private function isValid() {
$this->init();
- return ($this->sourceRootInfo->getPermissions() & Constants::PERMISSION_SHARE) === Constants::PERMISSION_SHARE;
+ return $this->sourceRootInfo && ($this->sourceRootInfo->getPermissions() & Constants::PERMISSION_SHARE) === Constants::PERMISSION_SHARE;
}
/**
@@ -568,6 +579,9 @@ class Shared extends \OC\Files\Storage\Common implements ISharedStorage {
public function getCache($path = '', $storage = null) {
$this->init();
+ if (is_null($this->sourceStorage)) {
+ return new FailedCache(false);
+ }
if (!$storage) {
$storage = $this;
}