[BUGFIX] Allow recursive folder deletion 17/35317/2
authorHelmut Hummel <helmut.hummel@typo3.org>
Thu, 4 Dec 2014 22:44:40 +0000 (23:44 +0100)
committerMarkus Klein <klein.t3@reelworx.at>
Thu, 11 Dec 2014 20:03:29 +0000 (21:03 +0100)
Remove the useless check for the number of existing
files in the ExtendedFileUtility.
We now let FAL try to delete recursively by default.
It will tell us, if the permissions do not suffice
for the current user.

Resolves: #63580
Releases: master, 6.2
Change-Id: Iec7ab95d493ce3594a4131b45e5bcb77de9e21b6
Reviewed-on: http://review.typo3.org/35317
Reviewed-by: Markus Klein <klein.t3@reelworx.at>
Tested-by: Markus Klein <klein.t3@reelworx.at>
typo3/sysext/core/Classes/Resource/Driver/AbstractHierarchicalFilesystemDriver.php
typo3/sysext/core/Classes/Resource/Driver/LocalDriver.php
typo3/sysext/core/Classes/Resource/ResourceStorage.php
typo3/sysext/core/Classes/Utility/File/ExtendedFileUtility.php

index 4b5f5d6..8957346 100644 (file)
@@ -55,6 +55,7 @@ abstract class AbstractHierarchicalFilesystemDriver extends AbstractDriver {
         *
         * @param string $fileIdentifier The file path (including the file name!)
         * @return string
+        * @throws \TYPO3\CMS\Core\Resource\Exception\InvalidPathException
         */
        protected function canonicalizeAndCheckFileIdentifier($fileIdentifier) {
                if ($fileIdentifier !== '') {
index a6b5715..0803211 100644 (file)
@@ -580,6 +580,7 @@ class LocalDriver extends AbstractHierarchicalFilesystemDriver {
         *
         * @param string $fileIdentifier
         * @return string
+        * @throws \TYPO3\CMS\Core\Resource\Exception\InvalidPathException
         */
        protected function getAbsolutePath($fileIdentifier) {
                $relativeFilePath = ltrim($this->canonicalizeAndCheckFileIdentifier($fileIdentifier), '/');
@@ -1017,6 +1018,7 @@ class LocalDriver extends AbstractHierarchicalFilesystemDriver {
         * @param boolean $deleteRecursively
         * @return boolean
         * @throws \TYPO3\CMS\Core\Resource\Exception\FileOperationErrorException
+        * @throws \TYPO3\CMS\Core\Resource\Exception\InvalidPathException
         */
        public function deleteFolder($folderIdentifier, $deleteRecursively = FALSE) {
                $folderPath = $this->getAbsolutePath($folderIdentifier);
index adf6daa..0039efd 100644 (file)
@@ -1890,6 +1890,10 @@ class ResourceStorage implements ResourceStorageInterface {
         * @param Folder $folderObject
         * @param bool $deleteRecursively
         * @throws \RuntimeException
+        * @throws \TYPO3\CMS\Core\Resource\Exception\InsufficientFolderAccessPermissionsException
+        * @throws \TYPO3\CMS\Core\Resource\Exception\InsufficientUserPermissionsException
+        * @throws \TYPO3\CMS\Core\Resource\Exception\FileOperationErrorException
+        * @throws \TYPO3\CMS\Core\Resource\Exception\InvalidPathException
         * @return bool
         */
        public function deleteFolder($folderObject, $deleteRecursively = FALSE) {
index 775d3e9..9242a3f 100644 (file)
@@ -447,21 +447,11 @@ class ExtendedFileUtility extends \TYPO3\CMS\Core\Utility\File\BasicFileUtility
                        }
                } else {
                        try {
-                               /** @var $fileObject \TYPO3\CMS\Core\Resource\FolderInterface */
-                               if ($fileObject->getFileCount() > 0) {
-                                       // render a message that the folder could not be deleted because it still contains files
-                                       $flashMessage = GeneralUtility::makeInstance(
-                                               '\\TYPO3\\CMS\\Core\\Messaging\\FlashMessage',
-                                               sprintf($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:message.description.folderNotDeletedHasFiles'), $fileObject->getName()),
-                                               $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:message.header.folderNotDeletedHasFiles'),
-                                               \TYPO3\CMS\Core\Messaging\FlashMessage::WARNING,
-                                               TRUE
-                                       );
-                                       $this->addFlashMessage($flashMessage);
-                               } else {
-                                       $result = $fileObject->delete(TRUE);
-
+                               /** @var \TYPO3\CMS\Core\Resource\Folder $fileObject */
+                               $result = $fileObject->delete(TRUE);
+                               if ($result) {
                                        // notify the user that the folder was deleted
+                                       /** @var \TYPO3\CMS\Core\Messaging\FlashMessage $flashMessage */
                                        $flashMessage = GeneralUtility::makeInstance(
                                                '\\TYPO3\\CMS\\Core\\Messaging\\FlashMessage',
                                                sprintf($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:message.description.folderDeleted'), $fileObject->getName()),
@@ -473,13 +463,14 @@ class ExtendedFileUtility extends \TYPO3\CMS\Core\Utility\File\BasicFileUtility
                                        // Log success
                                        $this->writelog(4, 0, 3, 'Directory "%s" deleted', array($fileObject->getIdentifier()));
                                }
-
+                       } catch (\TYPO3\CMS\Core\Resource\Exception\InsufficientUserPermissionsException $e) {
+                               $this->writelog(4, 1, 120, 'Could not delete directory! Is directory "%s" empty? (You are not allowed to delete directories recursively).', array($fileObject->getIdentifier()));
                        } catch (\TYPO3\CMS\Core\Resource\Exception\InsufficientFolderAccessPermissionsException $e) {
                                $this->writelog(4, 1, 123, 'You are not allowed to access the directory', array($fileObject->getIdentifier()));
                        } catch (\TYPO3\CMS\Core\Resource\Exception\NotInMountPointException $e) {
                                $this->writelog(4, 1, 121, 'Target was not within your mountpoints! T="%s"', array($fileObject->getIdentifier()));
-                       } catch (\RuntimeException $e) {
-                               $this->writelog(4, 1, 120, 'Could not delete directory! Write-permission problem? Is directory "%s" empty? (You are not allowed to delete directories recursively).', array($fileObject->getIdentifier()));
+                       } catch (\TYPO3\CMS\Core\Resource\Exception\FileOperationErrorException $e) {
+                               $this->writelog(4, 1, 120, 'Could not delete directory "%s"! Write-permission problem?', array($fileObject->getIdentifier()));
                        }
                }
                return $result;