]> source.dussan.org Git - nextcloud-server.git/commitdiff
Catch exception when querying direct download link
authorVincent Petry <pvince81@owncloud.com>
Wed, 9 Dec 2015 16:31:14 +0000 (17:31 +0100)
committerMorris Jobke <hey@morrisjobke.de>
Thu, 10 Dec 2015 15:17:44 +0000 (16:17 +0100)
apps/dav/lib/connector/sabre/filesplugin.php
apps/dav/tests/unit/connector/sabre/filesplugin.php

index 1c78e9dc8455d4fbfd4f83dd47eb9600527d4927..aa756281745e46e24836144463dcbe0c2b467ffc 100644 (file)
@@ -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 {
 
@@ -225,9 +226,13 @@ class FilesPlugin extends \Sabre\DAV\ServerPlugin {
                if ($node instanceof \OCA\DAV\Connector\Sabre\File) {
                        $propFind->handle(self::DOWNLOADURL_PROPERTYNAME, function() use ($node) {
                                /** @var $node \OCA\DAV\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 false;
                                }
                                return false;
                        });
index b33c8340f726a41efc64c120f2cd2ba253f85403..642fc3258cd2cb802f11331e5e5747a66077255e 100644 (file)
@@ -2,6 +2,8 @@
 
 namespace OCA\DAV\Tests\Unit\Connector\Sabre;
 
+use OCP\Files\StorageNotAvailableException;
+
 /**
  * Copyright (c) 2015 Vincent Petry <pvince81@owncloud.com>
  * This file is licensed under the Affero General Public License version 3 or
@@ -143,6 +145,29 @@ class FilesPlugin extends \Test\TestCase {
                $this->assertEquals(array(self::SIZE_PROPERTYNAME), $propFind->get404Properties());
        }
 
+       public function testGetPropertiesStorageNotAvailable() {
+               $node = $this->createTestNode('\OCA\DAV\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(null, $propFind->get(self::DOWNLOADURL_PROPERTYNAME));
+       }
+
        public function testGetPublicPermissions() {
                $this->plugin = new \OCA\DAV\Connector\Sabre\FilesPlugin($this->tree, $this->view, true);
                $this->plugin->initialize($this->server);