diff options
author | Vincent Petry <pvince81@owncloud.com> | 2015-02-12 12:29:01 +0100 |
---|---|---|
committer | Thomas Müller <thomas.mueller@tmit.eu> | 2015-02-23 22:27:23 +0100 |
commit | 9f6dcb9d3e2f43f336dafeb739e04ba9614d9b5f (patch) | |
tree | fa72017a9bf76c526ddb3dfe0969f0584a4a7d67 /lib/private/files/storage/dav.php | |
parent | 66e3211fd8a57b0fb296d1dcc980272721e9f99d (diff) | |
download | nextcloud-server-9f6dcb9d3e2f43f336dafeb739e04ba9614d9b5f.tar.gz nextcloud-server-9f6dcb9d3e2f43f336dafeb739e04ba9614d9b5f.zip |
Sabre Update to 2.1
- VObject fixes for Sabre\VObject 3.3
- Remove VObject property workarounds
- Added prefetching for tags in sabre tags plugin
- Moved oc_properties logic to separate PropertyStorage backend (WIP)
- Fixed Sabre connector namespaces
- Improved files plugin to handle props on-demand
- Moved allowed props from server class to files plugin
- Fixed tags caching for files that are known to have no tags
(less queries)
- Added/fixed unit tests for Sabre FilesPlugin, TagsPlugin
- Replace OC\Connector\Sabre\Request with direct call to
httpRequest->setUrl()
- Fix exception detection in DAV client when using Sabre\DAV\Client
- Added setETag() on Node instead of using the static FileSystem
- Also preload tags/props when depth is infinity
Diffstat (limited to 'lib/private/files/storage/dav.php')
-rw-r--r-- | lib/private/files/storage/dav.php | 73 |
1 files changed, 39 insertions, 34 deletions
diff --git a/lib/private/files/storage/dav.php b/lib/private/files/storage/dav.php index 0d70f612ec0..477a3b499c0 100644 --- a/lib/private/files/storage/dav.php +++ b/lib/private/files/storage/dav.php @@ -38,7 +38,7 @@ namespace OC\Files\Storage; use OCP\Files\StorageInvalidException; use OCP\Files\StorageNotAvailableException; -use Sabre\DAV\Exception; +use Sabre\DAV\ClientHttpException; class DAV extends \OC\Files\Storage\Common { protected $password; @@ -104,6 +104,7 @@ class DAV extends \OC\Files\Storage\Common { ); $this->client = new \Sabre\DAV\Client($settings); + $this->client->setThrowExceptions(true); if ($this->secure === true && $this->certPath) { $this->client->addTrustedCertificates($this->certPath); @@ -152,9 +153,10 @@ class DAV extends \OC\Files\Storage\Common { } \OC\Files\Stream\Dir::register($id, $content); return opendir('fakedir://' . $id); - } catch (Exception\NotFound $e) { - return false; - } catch (\Sabre\DAV\Exception $e) { + } catch (ClientHttpException $e) { + if ($e->getHttpStatus() === 404) { + return false; + } $this->convertSabreException($e); return false; } catch (\Exception $e) { @@ -174,9 +176,10 @@ class DAV extends \OC\Files\Storage\Common { $responseType = $response["{DAV:}resourcetype"]->resourceType; } return (count($responseType) > 0 and $responseType[0] == "{DAV:}collection") ? 'dir' : 'file'; - } catch (Exception\NotFound $e) { - return false; - } catch (\Sabre\DAV\Exception $e) { + } catch (ClientHttpException $e) { + if ($e->getHttpStatus() === 404) { + return false; + } $this->convertSabreException($e); return false; } catch (\Exception $e) { @@ -192,9 +195,10 @@ class DAV extends \OC\Files\Storage\Common { try { $this->client->propfind($this->encodePath($path), array('{DAV:}resourcetype')); return true; //no 404 exception - } catch (Exception\NotFound $e) { - return false; - } catch (\Sabre\DAV\Exception $e) { + } catch (ClientHttpException $e) { + if ($e->getHttpStatus() === 404) { + return false; + } $this->convertSabreException($e); return false; } catch (\Exception $e) { @@ -311,9 +315,10 @@ class DAV extends \OC\Files\Storage\Common { if ($this->file_exists($path)) { try { $this->client->proppatch($this->encodePath($path), array('{DAV:}lastmodified' => $mtime)); - } catch (Exception\NotImplemented $e) { - return false; - } catch (\Sabre\DAV\Exception $e) { + } catch (ClientHttpException $e) { + if ($e->getHttpStatus() === 501) { + return false; + } $this->convertSabreException($e); return false; } catch (\Exception $e) { @@ -367,7 +372,7 @@ class DAV extends \OC\Files\Storage\Common { $this->removeCachedFile($path1); $this->removeCachedFile($path2); return true; - } catch (\Sabre\DAV\Exception $e) { + } catch (ClientHttpException $e) { $this->convertSabreException($e); return false; } catch (\Exception $e) { @@ -385,7 +390,7 @@ 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) { + } catch (ClientHttpException $e) { $this->convertSabreException($e); return false; } catch (\Exception $e) { @@ -404,11 +409,12 @@ class DAV extends \OC\Files\Storage\Common { 'mtime' => strtotime($response['{DAV:}getlastmodified']), 'size' => (int)isset($response['{DAV:}getcontentlength']) ? $response['{DAV:}getcontentlength'] : 0, ); - } catch (Exception\NotFound $e) { - return array(); - } catch (\Sabre\DAV\Exception $e) { + } catch (ClientHttpException $e) { + if ($e->getHttpStatus() === 404) { + return array(); + } $this->convertSabreException($e); - return false; + return array(); } 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); @@ -433,9 +439,10 @@ class DAV extends \OC\Files\Storage\Common { } else { return false; } - } catch (Exception\NotFound $e) { - return false; - } catch (\Sabre\DAV\Exception $e) { + } catch (ClientHttpException $e) { + if ($e->getHttpStatus() === 404) { + return false; + } $this->convertSabreException($e); return false; } catch (\Exception $e) { @@ -478,16 +485,13 @@ class DAV extends \OC\Files\Storage\Common { try { $response = $this->client->request($method, $this->encodePath($path), $body); return $response['statusCode'] == $expected; - } catch (Exception\NotFound $e) { - if ($method === 'DELETE') { + } catch (ClientHttpException $e) { + if ($e->getHttpStatus() === 404 && $method === 'DELETE') { return false; } $this->convertSabreException($e); return false; - } catch (\Sabre\DAV\Exception $e) { - $this->convertSabreException($e); - return false; } 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); @@ -591,9 +595,10 @@ class DAV extends \OC\Files\Storage\Common { $remoteMtime = strtotime($response['{DAV:}getlastmodified']); return $remoteMtime > $time; } - } catch (Exception\NotFound $e) { - return false; } catch (Exception $e) { + if ($e->getHttpStatus() === 404) { + return false; + } $this->convertSabreException($e); return false; } @@ -603,19 +608,19 @@ class DAV extends \OC\Files\Storage\Common { * Convert sabre DAV exception to a storage exception, * then throw it * - * @param \Sabre\Dav\Exception $e sabre exception + * @param ClientException $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) { + private function convertSabreException(ClientException $e) { \OCP\Util::writeLog('files_external', $e->getMessage(), \OCP\Util::ERROR); - if ($e instanceof \Sabre\DAV\Exception\NotAuthenticated) { + if ($e->getHttpStatus() === 401) { // either password was changed or was invalid all along throw new StorageInvalidException(get_class($e).': '.$e->getMessage()); - } else if ($e instanceof \Sabre\DAV\Exception\MethodNotAllowed) { - // ignore exception, false will be returned + } else if ($e->getHttpStatus() === 405) { + // ignore exception for MethodNotAllowed, false will be returned return; } |