[Pkg-owncloud-commits] [owncloud] 55/107: Catch exception when querying direct download link

David Prévot taffit at moszumanska.debian.org
Thu Dec 17 19:40:36 UTC 2015


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch stable8
in repository owncloud.

commit 565d7b2b1244ae62afea397bcec5a4a19e89ea13
Author: Vincent Petry <pvince81 at owncloud.com>
Date:   Tue Dec 8 17:41:36 2015 +0100

    Catch exception when querying direct download link
---
 lib/private/connector/sabre/filesplugin.php | 12 +++++++++---
 tests/lib/connector/sabre/filesplugin.php   | 25 +++++++++++++++++++++++++
 2 files changed, 34 insertions(+), 3 deletions(-)

diff --git a/lib/private/connector/sabre/filesplugin.php b/lib/private/connector/sabre/filesplugin.php
index 7363677..9bb426e 100644
--- a/lib/private/connector/sabre/filesplugin.php
+++ b/lib/private/connector/sabre/filesplugin.php
@@ -31,6 +31,7 @@ use \Sabre\DAV\PropFind;
 use \Sabre\DAV\PropPatch;
 use \Sabre\HTTP\RequestInterface;
 use \Sabre\HTTP\ResponseInterface;
+use OCP\Files\StorageNotAvailableException;
 
 class FilesPlugin extends \Sabre\DAV\ServerPlugin {
 
@@ -188,9 +189,14 @@ class FilesPlugin extends \Sabre\DAV\ServerPlugin {
 		if ($node instanceof \OC\Connector\Sabre\File) {
 			$propFind->handle(self::DOWNLOADURL_PROPERTYNAME, function() use ($node) {
 				/** @var $node \OC\Connector\Sabre\File */
-				$directDownloadUrl = $node->getDirectDownload();
-				if (isset($directDownloadUrl['url'])) {
-					return $directDownloadUrl['url'];
+				try {
+					$directDownloadUrl = $node->getDirectDownload();
+					if (isset($directDownloadUrl['url'])) {
+						return $directDownloadUrl['url'];
+					}
+				} catch (StorageNotAvailableException $e) {
+					// return empty download link when storage not available
+					return false;
 				}
 				return false;
 			});
diff --git a/tests/lib/connector/sabre/filesplugin.php b/tests/lib/connector/sabre/filesplugin.php
index 97eef14..86478bf 100644
--- a/tests/lib/connector/sabre/filesplugin.php
+++ b/tests/lib/connector/sabre/filesplugin.php
@@ -2,6 +2,8 @@
 
 namespace Tests\Connector\Sabre;
 
+use OCP\Files\StorageNotAvailableException;
+
 /**
  * Copyright (c) 2015 Vincent Petry <pvince81 at owncloud.com>
  * This file is licensed under the Affero General Public License version 3 or
@@ -114,6 +116,29 @@ class FilesPlugin extends \Test\TestCase {
 		$this->assertEquals(array(self::SIZE_PROPERTYNAME), $propFind->get404Properties());
 	}
 
+	public function testGetPropertiesStorageNotAvailable() {
+		$node = $this->createTestNode('\OC\Connector\Sabre\File');
+
+		$propFind = new \Sabre\DAV\PropFind(
+			'/dummyPath',
+			array(
+				self::DOWNLOADURL_PROPERTYNAME,
+			),
+			0
+		);
+
+		$node->expects($this->once())
+			->method('getDirectDownload')
+			->will($this->throwException(new StorageNotAvailableException()));
+
+		$this->plugin->handleGetProperties(
+			$propFind,
+			$node
+		);
+
+		$this->assertEquals('', $propFind->get(self::DOWNLOADURL_PROPERTYNAME));
+	}
+
 	public function testGetPublicPermissions() {
 		$this->plugin = new \OC\Connector\Sabre\FilesPlugin($this->tree, $this->view, true);
 		$this->plugin->initialize($this->server);

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/owncloud.git



More information about the Pkg-owncloud-commits mailing list