[BUGFIX] Catch exceptions for inaccessible storages 17/42017/5
authorPhilipp Gampe <philipp.gampe@typo3.org>
Sun, 1 Feb 2015 10:46:51 +0000 (11:46 +0100)
committerMarkus Klein <markus.klein@typo3.org>
Wed, 12 Aug 2015 23:45:26 +0000 (01:45 +0200)
A storage might be (temporary or permanently) not available in the
current file system. Then it should be displayed as inaccessible
(offline).
Catch all exceptions while trying to fetch permissions for any related
folders.
Only display paste icons for browsable storages.

Resolves: #64714
Releases: master, 6.2
Change-Id: I803d1d2dad919fefebf9b37c60b40a7a440bc6d5
Reviewed-on: http://review.typo3.org/42017
Reviewed-by: Philipp Gampe <philipp.gampe@typo3.org>
Tested-by: Philipp Gampe <philipp.gampe@typo3.org>
Reviewed-by: Daniel Goerz <ervaude@gmail.com>
Reviewed-by: Markus Klein <markus.klein@typo3.org>
Tested-by: Markus Klein <markus.klein@typo3.org>
typo3/sysext/backend/Classes/Utility/IconUtility.php
typo3/sysext/backend/Tests/Unit/Utility/IconUtilityTest.php
typo3/sysext/core/Classes/Resource/Driver/LocalDriver.php
typo3/sysext/core/Classes/Resource/Exception/ResourcePermissionsUnavailableException.php [new file with mode: 0644]
typo3/sysext/core/Classes/Resource/Folder.php
typo3/sysext/core/Classes/Resource/ResourceStorage.php

index 2ec6f03..9d73d87 100644 (file)
@@ -786,6 +786,7 @@ class IconUtility {
 
                                // if locked add overlay
                                if ($resource instanceof \TYPO3\CMS\Core\Resource\InaccessibleFolder ||
+                                       !$resource->getStorage()->isBrowsable() ||
                                        !$resource->getStorage()->checkFolderActionPermission('add', $resource)
                                ) {
                                        $overlays['status-overlay-locked'] = array();
index ce7cf9a..038fdb7 100644 (file)
@@ -79,6 +79,7 @@ class IconUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
                        new \TYPO3\CMS\Core\Resource\Folder($mockedStorage, '/', '/')
                ));
                $mockedStorage->expects($this->any())->method('checkFolderActionPermission')->will($this->returnValue(TRUE));
+               $mockedStorage->expects($this->any())->method('isBrowsable')->will($this->returnValue(TRUE));
                return new \TYPO3\CMS\Core\Resource\Folder($mockedStorage, $identifier, $identifier);
        }
 
index 2279af0..d68553c 100644 (file)
@@ -1077,13 +1077,16 @@ class LocalDriver extends AbstractHierarchicalFilesystemDriver {
         *
         * @param string $identifier
         * @return array
-        * @throws \RuntimeException
+        * @throws \TYPO3\CMS\Core\Resource\Exception\ResourcePermissionsUnavailableException
         */
        public function getPermissions($identifier) {
                $path = $this->getAbsolutePath($identifier);
                $permissionBits = fileperms($path);
                if ($permissionBits === FALSE) {
-                       throw new \RuntimeException('Error while fetching permissions for ' . $path, 1319455097);
+                       throw new \TYPO3\CMS\Core\Resource\Exception\ResourcePermissionsUnavailableException(
+                               'Error while fetching permissions for ' . $path,
+                               1319455097
+                       );
                }
                return array(
                        'r' => (bool)is_readable($path),
diff --git a/typo3/sysext/core/Classes/Resource/Exception/ResourcePermissionsUnavailableException.php b/typo3/sysext/core/Classes/Resource/Exception/ResourcePermissionsUnavailableException.php
new file mode 100644 (file)
index 0000000..cfa7073
--- /dev/null
@@ -0,0 +1,23 @@
+<?php
+namespace TYPO3\CMS\Core\Resource\Exception;
+
+/*
+ * This file is part of the TYPO3 CMS project.
+ *
+ * It is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License, either version 2
+ * of the License, or any later version.
+ *
+ * For the full copyright and license information, please read the
+ * LICENSE.txt file that was distributed with this source code.
+ *
+ * The TYPO3 project - inspiring people to share!
+ */
+
+/**
+ * An exception when something is wrong with fetching the permissions for a file or a folder.
+ *
+ * Extending \RuntimeException for backwards compatibility.
+ */
+class ResourcePermissionsUnavailableException extends \RuntimeException {
+}
index 1599382..c160f0e 100644 (file)
@@ -370,7 +370,11 @@ class Folder implements FolderInterface {
         * @return boolean
         */
        public function checkActionPermission($action) {
-               return $this->getStorage()->checkFolderActionPermission($action, $this);
+               try {
+                       return $this->getStorage()->checkFolderActionPermission($action, $this);
+               } catch (Exception\ResourcePermissionsUnavailableException $e) {
+                       return FALSE;
+               }
        }
 
        /**
index e18e7c7..15bb468 100644 (file)
@@ -2660,6 +2660,10 @@ class ResourceStorage implements ResourceStorageInterface {
                                $this->processingFolder = GeneralUtility::makeInstance(
                                        'TYPO3\\CMS\\Core\\Resource\\InaccessibleFolder', $this, $processingFolder, $processingFolder
                                );
+                       } catch(Exception\ResourcePermissionsUnavailableException $e) {
+                               $this->processingFolder = GeneralUtility::makeInstance(
+                                       'TYPO3\\CMS\\Core\\Resource\\InaccessibleFolder', $this, $processingFolder, $processingFolder
+                               );
                        }
                }
                return $this->processingFolder;