Commit 40c58a78 authored by Helmut Hummel's avatar Helmut Hummel Committed by Frans Saris
Browse files

[BUGFIX] Allow recursive folder deletion

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/35060


Reviewed-by: default avatarMarkus Klein <klein.t3@reelworx.at>
Tested-by: default avatarMarkus Klein <klein.t3@reelworx.at>
Reviewed-by: default avatarStefan Neufeind <typo3.neufeind@speedpartner.de>
Reviewed-by: default avatarHelmut Hummel <helmut.hummel@typo3.org>
Tested-by: default avatarHelmut Hummel <helmut.hummel@typo3.org>
Reviewed-by: Frans Saris's avatarFrans Saris <franssaris@gmail.com>
Tested-by: Frans Saris's avatarFrans Saris <franssaris@gmail.com>
parent 28f6b864
......@@ -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 !== '') {
......
......@@ -581,6 +581,7 @@ class LocalDriver extends AbstractHierarchicalFilesystemDriver {
*
* @param string $fileIdentifier
* @return string
* @throws Exception\InvalidPathException
*/
protected function getAbsolutePath($fileIdentifier) {
$relativeFilePath = ltrim($this->canonicalizeAndCheckFileIdentifier($fileIdentifier), '/');
......@@ -1018,6 +1019,7 @@ class LocalDriver extends AbstractHierarchicalFilesystemDriver {
* @param bool $deleteRecursively
* @return bool
* @throws Exception\FileOperationErrorException
* @throws Exception\InvalidPathException
*/
public function deleteFolder($folderIdentifier, $deleteRecursively = FALSE) {
$folderPath = $this->getAbsolutePath($folderIdentifier);
......
......@@ -1842,6 +1842,10 @@ class ResourceStorage implements ResourceStorageInterface {
* @param Folder $folderObject
* @param bool $deleteRecursively
* @throws \RuntimeException
* @throws Exception\InsufficientFolderAccessPermissionsException
* @throws Exception\InsufficientUserPermissionsException
* @throws Exception\FileOperationErrorException
* @throws Exception\InvalidPathException
* @return bool
*/
public function deleteFolder($folderObject, $deleteRecursively = FALSE) {
......
......@@ -390,21 +390,11 @@ class ExtendedFileUtility extends 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(
FlashMessage::class,
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'),
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 FlashMessage $flashMessage */
$flashMessage = GeneralUtility::makeInstance(
FlashMessage::class,
sprintf($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:message.description.folderDeleted'), $fileObject->getName()),
......@@ -416,13 +406,14 @@ class ExtendedFileUtility extends 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;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment