summaryrefslogtreecommitdiffstats
path: root/apps/files_sharing/lib
diff options
context:
space:
mode:
authorMorris Jobke <hey@morrisjobke.de>2015-01-28 00:31:37 +0100
committerMorris Jobke <hey@morrisjobke.de>2015-01-28 00:31:37 +0100
commit87b39e8f03913f6e571c526167c18f0be0021c41 (patch)
treea190a15c3549c53dcc263ccd41334507d9865caa /apps/files_sharing/lib
parent3fa6e0f4dca7f477e93b10287f7de5cc75d39275 (diff)
parent5376b0b123873269a92d9aa45f6233c48c2720df (diff)
downloadnextcloud-server-87b39e8f03913f6e571c526167c18f0be0021c41.tar.gz
nextcloud-server-87b39e8f03913f6e571c526167c18f0be0021c41.zip
Merge pull request #13525 from owncloud/s2s-fixscanfileforbrokenstorage
Catch storage exception in scanner for remote shares
Diffstat (limited to 'apps/files_sharing/lib')
-rw-r--r--apps/files_sharing/lib/external/scanner.php53
-rw-r--r--apps/files_sharing/lib/external/storage.php56
2 files changed, 89 insertions, 20 deletions
diff --git a/apps/files_sharing/lib/external/scanner.php b/apps/files_sharing/lib/external/scanner.php
index 4e61e0c4ccb..b45a8942e96 100644
--- a/apps/files_sharing/lib/external/scanner.php
+++ b/apps/files_sharing/lib/external/scanner.php
@@ -8,6 +8,11 @@
namespace OCA\Files_Sharing\External;
+use OC\ForbiddenException;
+use OCP\Files\NotFoundException;
+use OCP\Files\StorageInvalidException;
+use OCP\Files\StorageNotAvailableException;
+
class Scanner extends \OC\Files\Cache\Scanner {
/**
* @var \OCA\Files_Sharing\External\Storage
@@ -18,12 +23,56 @@ class Scanner extends \OC\Files\Cache\Scanner {
$this->scanAll();
}
+ /**
+ * Scan a single file and store it in the cache.
+ * If an exception happened while accessing the external storage,
+ * the storage will be checked for availability and removed
+ * if it is not available any more.
+ *
+ * @param string $file file to scan
+ * @param int $reuseExisting
+ * @return array an array of metadata of the scanned file
+ */
+ public function scanFile($file, $reuseExisting = 0) {
+ try {
+ return parent::scanFile($file, $reuseExisting);
+ } catch (ForbiddenException $e) {
+ $this->storage->checkStorageAvailability();
+ } catch (NotFoundException $e) {
+ // if the storage isn't found, the call to
+ // checkStorageAvailable() will verify it and remove it
+ // if appropriate
+ $this->storage->checkStorageAvailability();
+ } catch (StorageInvalidException $e) {
+ $this->storage->checkStorageAvailability();
+ } catch (StorageNotAvailableException $e) {
+ $this->storage->checkStorageAvailability();
+ }
+ }
+
+ /**
+ * Checks the remote share for changes.
+ * If changes are available, scan them and update
+ * the cache.
+ */
public function scanAll() {
- $data = $this->storage->getShareInfo();
+ try {
+ $data = $this->storage->getShareInfo();
+ } catch (\Exception $e) {
+ $this->storage->checkStorageAvailability();
+ throw new \Exception(
+ 'Error while scanning remote share: "' .
+ $this->storage->getRemote() . '" ' .
+ $e->getMessage()
+ );
+ }
if ($data['status'] === 'success') {
$this->addResult($data['data'], '');
} else {
- throw new \Exception('Error while scanning remote share');
+ throw new \Exception(
+ 'Error while scanning remote share: "' .
+ $this->storage->getRemote() . '"'
+ );
}
}
diff --git a/apps/files_sharing/lib/external/storage.php b/apps/files_sharing/lib/external/storage.php
index b3978af6852..648376e8cb5 100644
--- a/apps/files_sharing/lib/external/storage.php
+++ b/apps/files_sharing/lib/external/storage.php
@@ -142,27 +142,47 @@ class Storage extends DAV implements ISharedStorage {
$this->updateChecked = true;
try {
return parent::hasUpdated('', $time);
+ } catch (StorageInvalidException $e) {
+ // check if it needs to be removed
+ $this->checkStorageAvailability();
+ throw $e;
} catch (StorageNotAvailableException $e) {
- // see if we can find out why the share is unavailable\
- try {
- $this->getShareInfo();
- } catch (NotFoundException $shareException) {
- // a 404 can either mean that the share no longer exists or there is no ownCloud on the remote
- if ($this->testRemote()) {
- // valid ownCloud instance means that the public share no longer exists
- // since this is permanent (re-sharing the file will create a new token)
- // we remove the invalid storage
- $this->manager->removeShare($this->mountPoint);
- $this->manager->getMountManager()->removeMount($this->mountPoint);
- throw new StorageInvalidException();
- } else {
- // ownCloud instance is gone, likely to be a temporary server configuration error
- throw $e;
- }
- } catch (\Exception $shareException) {
- // todo, maybe handle 403 better and ask the user for a new password
+ // check if it needs to be removed or just temp unavailable
+ $this->checkStorageAvailability();
+ throw $e;
+ }
+ }
+
+ /**
+ * Check whether this storage is permanently or temporarily
+ * unavailable
+ *
+ * @throws \OCP\Files\StorageNotAvailableException
+ * @throws \OCP\Files\StorageInvalidException
+ */
+ public function checkStorageAvailability() {
+ // see if we can find out why the share is unavailable
+ try {
+ $this->getShareInfo();
+ } catch (NotFoundException $e) {
+ // a 404 can either mean that the share no longer exists or there is no ownCloud on the remote
+ if ($this->testRemote()) {
+ // valid ownCloud instance means that the public share no longer exists
+ // since this is permanent (re-sharing the file will create a new token)
+ // we remove the invalid storage
+ $this->manager->removeShare($this->mountPoint);
+ $this->manager->getMountManager()->removeMount($this->mountPoint);
+ throw new StorageInvalidException();
+ } else {
+ // ownCloud instance is gone, likely to be a temporary server configuration error
throw $e;
}
+ } catch (ForbiddenException $e) {
+ // auth error, remove share for now (provide a dialog in the future)
+ $this->manager->removeShare($this->mountPoint);
+ $this->manager->getMountManager()->removeMount($this->mountPoint);
+ throw new StorageInvalidException();
+ } catch (\Exception $e) {
throw $e;
}
}