diff options
author | Morris Jobke <hey@morrisjobke.de> | 2015-01-28 00:31:37 +0100 |
---|---|---|
committer | Morris Jobke <hey@morrisjobke.de> | 2015-01-28 00:31:37 +0100 |
commit | 87b39e8f03913f6e571c526167c18f0be0021c41 (patch) | |
tree | a190a15c3549c53dcc263ccd41334507d9865caa /lib/private | |
parent | 3fa6e0f4dca7f477e93b10287f7de5cc75d39275 (diff) | |
parent | 5376b0b123873269a92d9aa45f6233c48c2720df (diff) | |
download | nextcloud-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 'lib/private')
-rw-r--r-- | lib/private/files/storage/dav.php | 41 | ||||
-rw-r--r-- | lib/private/files/view.php | 17 |
2 files changed, 56 insertions, 2 deletions
diff --git a/lib/private/files/storage/dav.php b/lib/private/files/storage/dav.php index 355148de37a..2d4916df08a 100644 --- a/lib/private/files/storage/dav.php +++ b/lib/private/files/storage/dav.php @@ -8,6 +8,7 @@ namespace OC\Files\Storage; +use OCP\Files\StorageInvalidException; use OCP\Files\StorageNotAvailableException; use Sabre\DAV\Exception; @@ -125,6 +126,8 @@ class DAV extends \OC\Files\Storage\Common { return opendir('fakedir://' . $id); } catch (Exception\NotFound $e) { return false; + } catch (\Sabre\DAV\Exception $e) { + $this->convertSabreException($e); } catch (\Exception $e) { // TODO: log for now, but in the future need to wrap/rethrow exception \OCP\Util::writeLog('files_external', $e->getMessage(), \OCP\Util::ERROR); @@ -144,6 +147,8 @@ class DAV extends \OC\Files\Storage\Common { return (count($responseType) > 0 and $responseType[0] == "{DAV:}collection") ? 'dir' : 'file'; } catch (Exception\NotFound $e) { return false; + } catch (\Sabre\DAV\Exception $e) { + $this->convertSabreException($e); } catch (\Exception $e) { // TODO: log for now, but in the future need to wrap/rethrow exception \OCP\Util::writeLog('files_external', $e->getMessage(), \OCP\Util::ERROR); @@ -159,6 +164,8 @@ class DAV extends \OC\Files\Storage\Common { return true; //no 404 exception } catch (Exception\NotFound $e) { return false; + } catch (\Sabre\DAV\Exception $e) { + $this->convertSabreException($e); } catch (\Exception $e) { // TODO: log for now, but in the future need to wrap/rethrow exception \OCP\Util::writeLog('files_external', $e->getMessage(), \OCP\Util::ERROR); @@ -275,6 +282,8 @@ class DAV extends \OC\Files\Storage\Common { $this->client->proppatch($this->encodePath($path), array('{DAV:}lastmodified' => $mtime)); } catch (Exception\NotImplemented $e) { return false; + } catch (\Sabre\DAV\Exception $e) { + $this->convertSabreException($e); } catch (\Exception $e) { // TODO: log for now, but in the future need to wrap/rethrow exception \OCP\Util::writeLog('files_external', $e->getMessage(), \OCP\Util::ERROR); @@ -326,6 +335,8 @@ class DAV extends \OC\Files\Storage\Common { $this->removeCachedFile($path1); $this->removeCachedFile($path2); return true; + } catch (\Sabre\DAV\Exception $e) { + $this->convertSabreException($e); } catch (\Exception $e) { // TODO: log for now, but in the future need to wrap/rethrow exception \OCP\Util::writeLog('files_external', $e->getMessage(), \OCP\Util::ERROR); @@ -341,6 +352,8 @@ class DAV extends \OC\Files\Storage\Common { $this->client->request('COPY', $path1, null, array('Destination' => $path2)); $this->removeCachedFile($path2); return true; + } catch (\Sabre\DAV\Exception $e) { + $this->convertSabreException($e); } catch (\Exception $e) { // TODO: log for now, but in the future need to wrap/rethrow exception \OCP\Util::writeLog('files_external', $e->getMessage(), \OCP\Util::ERROR); @@ -359,6 +372,8 @@ class DAV extends \OC\Files\Storage\Common { ); } catch (Exception\NotFound $e) { return array(); + } catch (\Sabre\DAV\Exception $e) { + $this->convertSabreException($e); } catch (\Exception $e) { // TODO: log for now, but in the future need to wrap/rethrow exception \OCP\Util::writeLog('files_external', $e->getMessage(), \OCP\Util::ERROR); @@ -383,6 +398,8 @@ class DAV extends \OC\Files\Storage\Common { } else { return false; } + } catch (\Sabre\DAV\Exception $e) { + $this->convertSabreException($e); } catch (\Exception $e) { // TODO: log for now, but in the future need to wrap/rethrow exception \OCP\Util::writeLog('files_external', $e->getMessage(), \OCP\Util::ERROR); @@ -423,6 +440,8 @@ class DAV extends \OC\Files\Storage\Common { try { $response = $this->client->request($method, $this->encodePath($path), $body); return $response['statusCode'] == $expected; + } catch (\Sabre\DAV\Exception $e) { + $this->convertSabreException($e); } catch (\Exception $e) { // TODO: log for now, but in the future need to wrap/rethrow exception \OCP\Util::writeLog('files_external', $e->getMessage(), \OCP\Util::ERROR); @@ -529,8 +548,28 @@ class DAV extends \OC\Files\Storage\Common { } catch (Exception\NotFound $e) { return false; } catch (Exception $e) { - throw new StorageNotAvailableException(get_class($e).": ".$e->getMessage()); + $this->convertSabreException($e); } } + + /** + * Convert sabre DAV exception to a storage exception, + * then throw it + * + * @param \Sabre\Dav\Exception $e sabre exception + * @throws StorageInvalidException if the storage is invalid, for example + * when the authentication expired or is invalid + * @throws StorageNotAvailableException if the storage is not available, + * which might be temporary + */ + private function convertSabreException(\Sabre\Dav\Exception $e) { + \OCP\Util::writeLog('files_external', $e->getMessage(), \OCP\Util::ERROR); + if ($e instanceof \Sabre\DAV\Exception\NotAuthenticated) { + // either password was changed or was invalid all along + throw new StorageInvalidException(get_class($e).': '.$e->getMessage()); + } + + throw new StorageNotAvailableException(get_class($e).': '.$e->getMessage()); + } } diff --git a/lib/private/files/view.php b/lib/private/files/view.php index f466361bd02..096d8044b75 100644 --- a/lib/private/files/view.php +++ b/lib/private/files/view.php @@ -1044,7 +1044,22 @@ class View { if ($subCache->getStatus('') === Cache\Cache::NOT_FOUND) { $subScanner = $subStorage->getScanner(''); - $subScanner->scanFile(''); + try { + $subScanner->scanFile(''); + } catch (\OCP\Files\StorageNotAvailableException $e) { + continue; + } catch (\OCP\Files\StorageInvalidException $e) { + continue; + } catch (\Exception $e) { + // sometimes when the storage is not available it can be any exception + \OCP\Util::writeLog( + 'core', + 'Exception while scanning storage "' . $subStorage->getId() . '": ' . + get_class($e) . ': ' . $e->getMessage(), + \OCP\Util::ERROR + ); + continue; + } } $rootEntry = $subCache->get(''); |