[BUGFIX] Prevent endless loop in recycler folder detection 02/57002/2
authorAlexander Stehlik <alexander.stehlik@gmail.com>
Wed, 16 May 2018 21:16:22 +0000 (23:16 +0200)
committerMarkus Klein <markus.klein@typo3.org>
Fri, 18 May 2018 12:41:09 +0000 (14:41 +0200)
Compare folder identifiers instead of folder objects because
objects pointing to the same folder might still be different
object instances.

Change-Id: I78e21b9e68fbaae245d12ac4efb96312b246a847
Releases: master, 8.7
Resolves: #85019
Reviewed-on: https://review.typo3.org/57002
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Markus Klein <markus.klein@typo3.org>
Tested-by: Markus Klein <markus.klein@typo3.org>
typo3/sysext/core/Classes/Resource/ResourceStorage.php
typo3/sysext/core/Tests/Functional/Resource/ResourceStorageTest.php

index 983bea0..6271af9 100644 (file)
@@ -3069,7 +3069,7 @@ class ResourceStorage implements ResourceStorageInterface
                     break;
                 }
             }
-        } while ($recyclerFolder === null && $folder !== $rootFolder);
+        } while ($recyclerFolder === null && $folder->getCombinedIdentifier() !== $rootFolder->getCombinedIdentifier());
 
         return $recyclerFolder;
     }
index 183df4f..e3df2e9 100644 (file)
@@ -91,7 +91,7 @@ class ResourceStorageTest extends \TYPO3\TestingFramework\Core\Functional\Functi
         $subject = (new StorageRepository())->findByUid(1);
         $subject->setEvaluatePermissions(true);
 
-        // read_only = true -> no write access for user, so checkinf for second argument true should assert false
+        // read_only = true -> no write access for user, so checking for second argument true should assert false
         $subject->addFileMount('/' . $fileMountFolder . '/', ['read_only' => $isFileMountReadOnly]);
         $this->assertSame($expectedResult, $subject->isWithinFileMountBoundaries($file, $checkWriteAccess));
     }
@@ -210,4 +210,44 @@ class ResourceStorageTest extends \TYPO3\TestingFramework\Core\Functional\Functi
         $this->expectExceptionCode(1325689164);
         $subject->createFolder('newFolder', new Folder($subject, '/foo/', 'foo'));
     }
+
+    /**
+     * @test
+     */
+    public function deleteFileMovesFileToRecyclerFolderIfAvailable()
+    {
+        $this->importDataSet('PACKAGE:typo3/testing-framework/Resources/Core/Functional/Fixtures/sys_file_storage.xml');
+        $this->setUpBackendUserFromFixture(1);
+        $subject = (new StorageRepository())->findByUid(1);
+
+        GeneralUtility::mkdir_deep(PATH_site . 'fileadmin/foo');
+        GeneralUtility::mkdir_deep(PATH_site . 'fileadmin/_recycler_');
+        file_put_contents(PATH_site . 'fileadmin/foo/bar.txt', 'myData');
+        clearstatcache();
+
+        $file = ResourceFactory::getInstance()->getFileObjectFromCombinedIdentifier('1:/foo/bar.txt');
+        $subject->deleteFile($file);
+
+        $this->assertTrue(file_exists(PATH_site . 'fileadmin/_recycler_/bar.txt'));
+        $this->assertFalse(file_exists(PATH_site . 'fileadmin/foo/bar.txt'));
+    }
+
+    /**
+     * @test
+     */
+    public function deleteFileUnlinksFileIfNoRecyclerFolderAvailable()
+    {
+        $this->importDataSet('PACKAGE:typo3/testing-framework/Resources/Core/Functional/Fixtures/sys_file_storage.xml');
+        $this->setUpBackendUserFromFixture(1);
+        $subject = (new StorageRepository())->findByUid(1);
+
+        GeneralUtility::mkdir_deep(PATH_site . 'fileadmin/foo');
+        file_put_contents(PATH_site . 'fileadmin/foo/bar.txt', 'myData');
+        clearstatcache();
+
+        $file = ResourceFactory::getInstance()->getFileObjectFromCombinedIdentifier('1:/foo/bar.txt');
+        $subject->deleteFile($file);
+
+        $this->assertFalse(file_exists(PATH_site . 'fileadmin/foo/bar.txt'));
+    }
 }