diff options
author | Vincent Petry <pvince81@owncloud.com> | 2015-01-20 19:45:32 +0100 |
---|---|---|
committer | Vincent Petry <pvince81@owncloud.com> | 2015-01-26 13:59:49 +0100 |
commit | f6e644b43fe3c33ba298ee34a73536c85cc92b4a (patch) | |
tree | 7e8fe8eaa51f56765d6147f37a91fad9a1b325d0 /apps/files_sharing/ajax | |
parent | dc4ceda2f5d1c8007ffd9b5cacbd794f06b1957d (diff) | |
download | nextcloud-server-f6e644b43fe3c33ba298ee34a73536c85cc92b4a.tar.gz nextcloud-server-f6e644b43fe3c33ba298ee34a73536c85cc92b4a.zip |
Catch storage exception in scanner for remote shares
Whenever an exception occurs during scan of a remote share, the share is
checked for availability. If the storage is gone, it will be removed
automatically.
Also, getDirectoryContent() will now skip unavailable storages.
Diffstat (limited to 'apps/files_sharing/ajax')
-rw-r--r-- | apps/files_sharing/ajax/external.php | 58 |
1 files changed, 54 insertions, 4 deletions
diff --git a/apps/files_sharing/ajax/external.php b/apps/files_sharing/ajax/external.php index 1a709eda07c..3d6d589aff8 100644 --- a/apps/files_sharing/ajax/external.php +++ b/apps/files_sharing/ajax/external.php @@ -42,20 +42,70 @@ $name = OCP\Files::buildNotExistingFileName('/', $name); // check for ssl cert if (substr($remote, 0, 5) === 'https' and !OC_Util::getUrlContent($remote)) { - \OCP\JSON::error(array('data' => array('message' => $l->t("Invalid or untrusted SSL certificate")))); + \OCP\JSON::error(array('data' => array('message' => $l->t('Invalid or untrusted SSL certificate')))); exit; } else { $mount = $externalManager->addShare($remote, $token, $password, $name, $owner, true); + /** * @var \OCA\Files_Sharing\External\Storage $storage */ $storage = $mount->getStorage(); + try { + // check if storage exists + $storage->checkStorageAvailability(); + } catch (\OCP\Files\StorageInvalidException $e) { + // note: checkStorageAvailability will already remove the invalid share + \OCP\Util::writeLog( + 'files_sharing', + 'Invalid remote storage: ' . get_class($e) . ': ' . $e->getMessage(), + \OCP\Util::DEBUG + ); + \OCP\JSON::error( + array( + 'data' => array( + 'message' => $l->t('Could not authenticate to remote share, password might be wrong') + ) + ) + ); + exit(); + } catch (\Exception $e) { + \OCP\Util::writeLog( + 'files_sharing', + 'Invalid remote storage: ' . get_class($e) . ': ' . $e->getMessage(), + \OCP\Util::DEBUG + ); + $externalManager->removeShare($mount->getMountPoint()); + \OCP\JSON::error(array('data' => array('message' => $l->t('Storage not valid')))); + throw new \OCP\Files\StorageNotAvailableException(get_class($e).': '.$e->getMessage()); + } $result = $storage->file_exists(''); if ($result) { - $storage->getScanner()->scanAll(); - \OCP\JSON::success(); + try { + $storage->getScanner()->scanAll(); + \OCP\JSON::success(); + } catch (\OCP\Files\StorageInvalidException $e) { + \OCP\Util::writeLog( + 'files_sharing', + 'Invalid remote storage: ' . get_class($e) . ': ' . $e->getMessage(), + \OCP\Util::DEBUG + ); + \OCP\JSON::error(array('data' => array('message' => $l->t('Storage not valid')))); + } catch (\Exception $e) { + \OCP\Util::writeLog( + 'files_sharing', + 'Invalid remote storage: ' . get_class($e) . ': ' . $e->getMessage(), + \OCP\Util::DEBUG + ); + \OCP\JSON::error(array('data' => array('message' => $l->t('Couldn\'t add remote share')))); + } } else { $externalManager->removeShare($mount->getMountPoint()); - \OCP\JSON::error(array('data' => array('message' => $l->t("Couldn't add remote share")))); + \OCP\Util::writeLog( + 'files_sharing', + 'Couldn\'t add remote share', + \OCP\Util::DEBUG + ); + \OCP\JSON::error(array('data' => array('message' => $l->t('Couldn\'t add remote share')))); } } |