[BUGFIX] Fix GeneralUtility::rmdir and usage in tests 95/20095/3
authorAnja Leichsenring <aleichsenring@ab-softlab.de>
Mon, 22 Apr 2013 21:13:39 +0000 (23:13 +0200)
committerChristian Kuhn <lolli@schwarzbu.ch>
Mon, 6 May 2013 18:23:44 +0000 (20:23 +0200)
rmdir() has some issues fixed by the patch, especially if
feeded with links:
* If target is a dead link, the link was not removed.
* If target is a link to a directory, only the link should be
  removed, but not the directory the link points to.
* If recursion is disabled, but a directory has sub files or
  directories, a warning might be raised, now suppressed
  with an @.

The method is now fully covered by tests and can handle files,
links and directories. It is now used in GeneralUtilityTest
itself to clean up any created file during tearDown, so a lot
of tests can be streamlined.

Fixes: #47459
Releases: 6.2
Change-Id: If58a6c2262165b84c4b674c1ae71fdddcbf56458
Reviewed-on: https://review.typo3.org/20095
Reviewed-by: Philipp Gampe
Tested-by: Philipp Gampe
Reviewed-by: Christian Kuhn
Tested-by: Christian Kuhn
typo3/sysext/core/Classes/Utility/GeneralUtility.php
typo3/sysext/core/Tests/Unit/Utility/GeneralUtilityTest.php

index 8f99407..aaea214 100644 (file)
@@ -2676,7 +2676,7 @@ Connection: close
                $path = preg_replace('|/$|', '', $path);
                if (file_exists($path)) {
                        $OK = TRUE;
-                       if (is_dir($path)) {
+                       if (!is_link($path) && is_dir($path)) {
                                if ($removeNonEmpty == TRUE && ($handle = opendir($path))) {
                                        while ($OK && FALSE !== ($file = readdir($handle))) {
                                                if ($file == '.' || $file == '..') {
@@ -2687,13 +2687,16 @@ Connection: close
                                        closedir($handle);
                                }
                                if ($OK) {
-                                       $OK = rmdir($path);
+                                       $OK = @rmdir($path);
                                }
                        } else {
-                               // If $dirname is a file, simply remove it
+                               // If $path is a file, simply remove it
                                $OK = unlink($path);
                        }
                        clearstatcache();
+               } elseif (is_link($path)) {
+                       $OK = unlink($path);
+                       clearstatcache();
                }
                return $OK;
        }
index 9bae3c7..8883360 100644 (file)
@@ -34,10 +34,7 @@ use TYPO3\CMS\Core\Utility;
 class GeneralUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
 
        /**
-        * Absolute path to files that must be removed
-        * after a test - handled in tearDown
-        *
-        * @var array
+        * @var array Files, directories and links to be deleted after a test
         */
        protected $testFilesToDelete = array();
 
@@ -53,7 +50,7 @@ class GeneralUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
        public function tearDown() {
                Utility\GeneralUtility::resetSingletonInstances($this->singletonInstances);
                foreach ($this->testFilesToDelete as $absoluteFileName) {
-                       Utility\GeneralUtility::unlink_tempfile($absoluteFileName);
+                       Utility\GeneralUtility::rmdir($absoluteFileName, TRUE);
                }
        }
 
@@ -208,14 +205,12 @@ class GeneralUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
                $GLOBALS['TYPO3_CONF_VARS']['GFX']['gif_compress'] = TRUE;
                // Copy file to unique filename in typo3temp, set target permissions and run method
                $testFilename = PATH_site . 'typo3temp/' . uniqid('test_') . '.gif';
+               $this->testFilesToDelete[] = $testFilename;
                @copy($fixtureGifFile, $testFilename);
                $GLOBALS['TYPO3_CONF_VARS']['BE']['fileCreateMask'] = '0777';
                Utility\GeneralUtility::gif_compress($testFilename, 'IM');
-               // Get actual permissions and clean up
                clearstatcache();
-               $resultFilePermissions = substr(decoct(fileperms($testFilename)), 2);
-               Utility\GeneralUtility::unlink_tempfile($testFilename);
-               $this->assertEquals($resultFilePermissions, '0777');
+               $this->assertEquals('0777', substr(decoct(fileperms($testFilename)), 2));
        }
 
        /**
@@ -232,13 +227,11 @@ class GeneralUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
                // Copy file to unique filename in typo3temp, set target permissions and run method
                $testFilename = PATH_site . 'typo3temp/' . uniqid('test_') . '.gif';
                @copy($fixtureGifFile, $testFilename);
+               $this->testFilesToDelete[] = $testFilename;
                $GLOBALS['TYPO3_CONF_VARS']['BE']['fileCreateMask'] = '0777';
                Utility\GeneralUtility::gif_compress($testFilename, 'GD');
-               // Get actual permissions and clean up
                clearstatcache();
-               $resultFilePermissions = substr(decoct(fileperms($testFilename)), 2);
-               Utility\GeneralUtility::unlink_tempfile($testFilename);
-               $this->assertEquals($resultFilePermissions, '0777');
+               $this->assertEquals('0777', substr(decoct(fileperms($testFilename)), 2));
        }
 
        ///////////////////////////////
@@ -259,13 +252,11 @@ class GeneralUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
                // Copy file to unique filename in typo3temp, set target permissions and run method
                $testFilename = PATH_site . 'typo3temp/' . uniqid('test_') . '.png';
                @copy($fixturePngFile, $testFilename);
+               $this->testFilesToDelete[] = $testFilename;
                $GLOBALS['TYPO3_CONF_VARS']['BE']['fileCreateMask'] = '0777';
                $newGifFile = Utility\GeneralUtility::png_to_gif_by_imagemagick($testFilename);
-               // Get actual permissions and clean up
                clearstatcache();
-               $resultFilePermissions = substr(decoct(fileperms($newGifFile)), 2);
-               Utility\GeneralUtility::unlink_tempfile($newGifFile);
-               $this->assertEquals($resultFilePermissions, '0777');
+               $this->assertEquals('0777', substr(decoct(fileperms($newGifFile)), 2));
        }
 
        ///////////////////////////////
@@ -285,11 +276,9 @@ class GeneralUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
                // Set target permissions and run method
                $GLOBALS['TYPO3_CONF_VARS']['BE']['fileCreateMask'] = '0777';
                $newPngFile = Utility\GeneralUtility::read_png_gif($testGifFile, TRUE);
-               // Get actual permissions and clean up
+               $this->testFilesToDelete[] = $newPngFile;
                clearstatcache();
-               $resultFilePermissions = substr(decoct(fileperms($newPngFile)), 2);
-               Utility\GeneralUtility::unlink_tempfile($newPngFile);
-               $this->assertEquals($resultFilePermissions, '0777');
+               $this->assertEquals(substr(decoct(fileperms($newPngFile)), 2), '0777');
        }
 
        ///////////////////////////
@@ -785,9 +774,9 @@ class GeneralUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
                        'array is not part of string' => array('string', array()),
                        'string is not part of array' => array(array(), 'string'),
                        'NULL is not part of string' => array('string', NULL),
-                       'string is not part of array' => array(NULL, 'string'),
+                       'string is not part of NULL' => array(NULL, 'string'),
                        'NULL is not part of array' => array(array(), NULL),
-                       'array is not part of string' => array(NULL, array()),
+                       'array is not part of NULL' => array(NULL, array()),
                        'empty string is not part of empty string' => array('', ''),
                        'NULL is not part of empty string' => array('', NULL),
                        'false is not part of empty string' => array('', FALSE),
@@ -1868,7 +1857,6 @@ class GeneralUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
                @copy($fixtureFile, $testFilename);
                Utility\GeneralUtility::unlink_tempfile($testFilename);
                $fileExists = file_exists($testFilename);
-               @unlink($testFilename);
                $this->assertFalse($fileExists);
        }
 
@@ -1881,7 +1869,6 @@ class GeneralUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
                @copy($fixtureFile, $testFilename);
                Utility\GeneralUtility::unlink_tempfile($testFilename);
                $fileExists = file_exists($testFilename);
-               @unlink($testFilename);
                $this->assertFalse($fileExists);
        }
 
@@ -1893,7 +1880,6 @@ class GeneralUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
                $testFilename = PATH_site . 'typo3temp/' . uniqid('test_') . '.gif';
                @copy($fixtureFile, $testFilename);
                $returnValue = Utility\GeneralUtility::unlink_tempfile($testFilename);
-               @unlink($testFilename);
                $this->assertTrue($returnValue);
        }
 
@@ -2675,17 +2661,14 @@ class GeneralUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
                // Create and prepare test directory
                $directory = PATH_site . 'typo3temp/' . uniqid('test_');
                Utility\GeneralUtility::mkdir($directory);
+               $this->testFilesToDelete[] = $directory;
                chmod($directory, 1551);
                // Set target permissions and run method
                $GLOBALS['TYPO3_CONF_VARS']['BE']['folderCreateMask'] = '0770';
                $fixPermissionsResult = Utility\GeneralUtility::fixPermissions($directory);
-               // Get actual permissions and clean up
                clearstatcache();
-               $resultDirectoryPermissions = substr(decoct(fileperms($directory)), 1);
-               Utility\GeneralUtility::rmdir($directory);
-               // Test if everything was ok
                $this->assertTrue($fixPermissionsResult);
-               $this->assertEquals('0770', $resultDirectoryPermissions);
+               $this->assertEquals('0770', substr(decoct(fileperms($directory)), 1));
        }
 
        /**
@@ -2698,17 +2681,15 @@ class GeneralUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
                // Create and prepare test directory
                $directory = PATH_site . 'typo3temp/' . uniqid('test_');
                Utility\GeneralUtility::mkdir($directory);
+               $this->testFilesToDelete[] = $directory;
                chmod($directory, 1551);
                // Set target permissions and run method
                $GLOBALS['TYPO3_CONF_VARS']['BE']['folderCreateMask'] = '0770';
                $fixPermissionsResult = Utility\GeneralUtility::fixPermissions($directory . '/');
                // Get actual permissions and clean up
                clearstatcache();
-               $resultDirectoryPermissions = substr(decoct(fileperms($directory)), 1);
-               Utility\GeneralUtility::rmdir($directory);
-               // Test if everything was ok
                $this->assertTrue($fixPermissionsResult);
-               $this->assertEquals('0770', $resultDirectoryPermissions);
+               $this->assertEquals('0770', substr(decoct(fileperms($directory)), 1));
        }
 
        /**
@@ -2721,17 +2702,15 @@ class GeneralUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
                // Create and prepare test directory
                $directory = PATH_site . 'typo3temp/' . uniqid('.test_');
                Utility\GeneralUtility::mkdir($directory);
+               $this->testFilesToDelete[] = $directory;
                chmod($directory, 1551);
                // Set target permissions and run method
                $GLOBALS['TYPO3_CONF_VARS']['BE']['folderCreateMask'] = '0770';
                $fixPermissionsResult = Utility\GeneralUtility::fixPermissions($directory);
                // Get actual permissions and clean up
                clearstatcache();
-               $resultDirectoryPermissions = substr(decoct(fileperms($directory)), 1);
-               Utility\GeneralUtility::rmdir($directory);
-               // Test if everything was ok
                $this->assertTrue($fixPermissionsResult);
-               $this->assertEquals('0770', $resultDirectoryPermissions);
+               $this->assertEquals('0770', substr(decoct(fileperms($directory)), 1));
        }
 
        /**
@@ -2744,6 +2723,7 @@ class GeneralUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
                // Create and prepare test directory and file structure
                $baseDirectory = PATH_site . 'typo3temp/' . uniqid('test_');
                Utility\GeneralUtility::mkdir($baseDirectory);
+               $this->testFilesToDelete[] = $baseDirectory;
                chmod($baseDirectory, 1751);
                Utility\GeneralUtility::writeFileToTypo3tempDir($baseDirectory . '/file', '42');
                chmod($baseDirectory . '/file', 482);
@@ -2773,14 +2753,6 @@ class GeneralUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
                $resultBarDirectoryPermissions = substr(decoct(fileperms($baseDirectory . '/.bar')), 1);
                $resultBarFilePermissions = substr(decoct(fileperms($baseDirectory . '/.bar/.file')), 2);
                $resultBarFile2Permissions = substr(decoct(fileperms($baseDirectory . '/.bar/..file2')), 2);
-               // Clean up
-               unlink($baseDirectory . '/file');
-               unlink($baseDirectory . '/foo/file');
-               unlink($baseDirectory . '/.bar/.file');
-               unlink($baseDirectory . '/.bar/..file2');
-               Utility\GeneralUtility::rmdir($baseDirectory . '/foo');
-               Utility\GeneralUtility::rmdir($baseDirectory . '/.bar');
-               Utility\GeneralUtility::rmdir($baseDirectory);
                // Test if everything was ok
                $this->assertTrue($fixPermissionsResult);
                $this->assertEquals('0770', $resultBaseDirectoryPermissions);
@@ -2801,16 +2773,13 @@ class GeneralUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
                }
                // Create and prepare test file
                $filename = PATH_site . 'typo3temp/../typo3temp/' . uniqid('test_');
+               $this->testFilesToDelete[] = $filename;
                touch($filename);
                chmod($filename, 482);
                // Set target permissions and run method
                $GLOBALS['TYPO3_CONF_VARS']['BE']['fileCreateMask'] = '0660';
                $fixPermissionsResult = Utility\GeneralUtility::fixPermissions($filename);
-               // Get actual permissions and clean up
                clearstatcache();
-               $resultFilePermissions = substr(decoct(fileperms($filename)), 2);
-               unlink($filename);
-               // Test if everything was ok
                $this->assertFalse($fixPermissionsResult);
        }
 
@@ -2823,17 +2792,14 @@ class GeneralUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
                }
                $filename = 'typo3temp/' . uniqid('test_');
                Utility\GeneralUtility::writeFileToTypo3tempDir(PATH_site . $filename, '42');
+               $this->testFilesToDelete[] = PATH_site . $filename;
                chmod(PATH_site . $filename, 482);
                // Set target permissions and run method
                $GLOBALS['TYPO3_CONF_VARS']['BE']['fileCreateMask'] = '0660';
                $fixPermissionsResult = Utility\GeneralUtility::fixPermissions($filename);
-               // Get actual permissions and clean up
                clearstatcache();
-               $resultFilePermissions = substr(decoct(fileperms(PATH_site . $filename)), 2);
-               unlink(PATH_site . $filename);
-               // Test if everything was ok
                $this->assertTrue($fixPermissionsResult);
-               $this->assertEquals('0660', $resultFilePermissions);
+               $this->assertEquals('0660', substr(decoct(fileperms(PATH_site . $filename)), 2));
        }
 
        /**
@@ -2863,14 +2829,13 @@ class GeneralUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
                }
                $directory = PATH_site . 'typo3temp/' . uniqid('test_');
                Utility\GeneralUtility::mkdir($directory);
+               $this->testFilesToDelete[] = $directory;
                chmod($directory, 1551);
                unset($GLOBALS['TYPO3_CONF_VARS']['BE']['folderCreateMask']);
                $fixPermissionsResult = Utility\GeneralUtility::fixPermissions($directory);
                clearstatcache();
-               $resultDirectoryPermissions = substr(decoct(fileperms($directory)), 1);
-               Utility\GeneralUtility::rmdir($directory);
                $this->assertTrue($fixPermissionsResult);
-               $this->assertEquals('0755', $resultDirectoryPermissions);
+               $this->assertEquals('0755', substr(decoct(fileperms($directory)), 1));
        }
 
        ///////////////////////////////
@@ -2882,11 +2847,10 @@ class GeneralUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
        public function mkdirCreatesDirectory() {
                $directory = PATH_site . 'typo3temp/' . uniqid('test_');
                $mkdirResult = Utility\GeneralUtility::mkdir($directory);
+               $this->testFilesToDelete[] = $directory;
                clearstatcache();
-               $directoryCreated = is_dir($directory);
-               @rmdir($directory);
                $this->assertTrue($mkdirResult);
-               $this->assertTrue($directoryCreated);
+               $this->assertTrue(is_dir($directory));
        }
 
        /**
@@ -2895,11 +2859,10 @@ class GeneralUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
        public function mkdirCreatesHiddenDirectory() {
                $directory = PATH_site . 'typo3temp/' . uniqid('.test_');
                $mkdirResult = Utility\GeneralUtility::mkdir($directory);
+               $this->testFilesToDelete[] = $directory;
                clearstatcache();
-               $directoryCreated = is_dir($directory);
-               @rmdir($directory);
                $this->assertTrue($mkdirResult);
-               $this->assertTrue($directoryCreated);
+               $this->assertTrue(is_dir($directory));
        }
 
        /**
@@ -2908,11 +2871,10 @@ class GeneralUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
        public function mkdirCreatesDirectoryWithTrailingSlash() {
                $directory = PATH_site . 'typo3temp/' . uniqid('test_') . '/';
                $mkdirResult = Utility\GeneralUtility::mkdir($directory);
+               $this->testFilesToDelete[] = $directory;
                clearstatcache();
-               $directoryCreated = is_dir($directory);
-               @rmdir($directory);
                $this->assertTrue($mkdirResult);
-               $this->assertTrue($directoryCreated);
+               $this->assertTrue(is_dir($directory));
        }
 
        /**
@@ -2926,10 +2888,10 @@ class GeneralUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
                $oldUmask = umask(19);
                $GLOBALS['TYPO3_CONF_VARS']['BE']['folderCreateMask'] = '0772';
                Utility\GeneralUtility::mkdir($directory);
+               $this->testFilesToDelete[] = $directory;
                clearstatcache();
                $resultDirectoryPermissions = substr(decoct(fileperms($directory)), 1);
                umask($oldUmask);
-               rmdir($directory);
                $this->assertEquals($resultDirectoryPermissions, '0772');
        }
 
@@ -2948,10 +2910,10 @@ class GeneralUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
                        $GLOBALS['TYPO3_CONF_VARS']['BE']['createGroup'] = $swapGroup;
                        $directory = uniqid('mkdirtest_');
                        Utility\GeneralUtility::mkdir(PATH_site . 'typo3temp/' . $directory);
+                       $this->testFilesToDelete[] = PATH_site . 'typo3temp/' . $directory;
                        clearstatcache();
                        $resultDirectoryGroupInfo = posix_getgrgid(filegroup(PATH_site . 'typo3temp/' . $directory));
                        $resultDirectoryGroup = $resultDirectoryGroupInfo['name'];
-                       @rmdir((PATH_site . 'typo3temp/' . $directory));
                        $this->assertEquals($resultDirectoryGroup, $swapGroup);
                }
        }
@@ -2992,9 +2954,8 @@ class GeneralUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
        public function mkdirDeepCreatesDirectory() {
                $directory = 'typo3temp/' . uniqid('test_');
                Utility\GeneralUtility::mkdir_deep(PATH_site, $directory);
-               $isDirectoryCreated = is_dir(PATH_site . $directory);
-               rmdir(PATH_site . $directory);
-               $this->assertTrue($isDirectoryCreated);
+               $this->testFilesToDelete[] = PATH_site . $directory;
+               $this->assertTrue(is_dir(PATH_site . $directory));
        }
 
        /**
@@ -3004,10 +2965,8 @@ class GeneralUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
                $directory = 'typo3temp/' . uniqid('test_');
                $subDirectory = $directory . '/foo';
                Utility\GeneralUtility::mkdir_deep(PATH_site, $subDirectory);
-               $isDirectoryCreated = is_dir(PATH_site . $subDirectory);
-               rmdir(PATH_site . $subDirectory);
-               rmdir(PATH_site . $directory);
-               $this->assertTrue($isDirectoryCreated);
+               $this->testFilesToDelete[] = PATH_site . $directory;
+               $this->assertTrue(is_dir(PATH_site . $subDirectory));
        }
 
        /**
@@ -3021,11 +2980,10 @@ class GeneralUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
                $oldUmask = umask(19);
                $GLOBALS['TYPO3_CONF_VARS']['BE']['folderCreateMask'] = '0777';
                Utility\GeneralUtility::mkdir_deep(PATH_site . 'typo3temp/', $directory);
+               $this->testFilesToDelete[] = PATH_site . 'typo3temp/' . $directory;
                clearstatcache();
-               $resultDirectoryPermissions = substr(decoct(fileperms(PATH_site . 'typo3temp/' . $directory)), -3, 3);
-               @rmdir((PATH_site . 'typo3temp/' . $directory));
                umask($oldUmask);
-               $this->assertEquals($resultDirectoryPermissions, '777');
+               $this->assertEquals('777', substr(decoct(fileperms(PATH_site . 'typo3temp/' . $directory)), -3, 3));
        }
 
        /**
@@ -3040,12 +2998,10 @@ class GeneralUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
                $GLOBALS['TYPO3_CONF_VARS']['BE']['folderCreateMask'] = '0777';
                $oldUmask = umask(19);
                Utility\GeneralUtility::mkdir_deep(PATH_site . 'typo3temp/', $subDirectory);
+               $this->testFilesToDelete[] = PATH_site . 'typo3temp/' . $directory;
                clearstatcache();
-               $resultDirectoryPermissions = substr(decoct(fileperms(PATH_site . 'typo3temp/' . $directory)), -3, 3);
-               @rmdir((PATH_site . 'typo3temp/' . $subDirectory));
-               @rmdir((PATH_site . 'typo3temp/' . $directory));
                umask($oldUmask);
-               $this->assertEquals($resultDirectoryPermissions, '777');
+               $this->assertEquals('777', substr(decoct(fileperms(PATH_site . 'typo3temp/' . $directory)), -3, 3));
        }
 
        /**
@@ -3059,12 +3015,10 @@ class GeneralUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
                $existingDirectory = uniqid('test_existing_') . '/';
                $newSubDirectory = uniqid('test_new_');
                @mkdir(($baseDirectory . $existingDirectory));
+               $this->testFilesToDelete[] = $baseDirectory . $existingDirectory;
                chmod($baseDirectory . $existingDirectory, 482);
                Utility\GeneralUtility::mkdir_deep($baseDirectory, $existingDirectory . $newSubDirectory);
-               $resultExistingDirectoryPermissions = substr(decoct(fileperms($baseDirectory . $existingDirectory)), 2);
-               @rmdir($baseDirectory, ($existingDirectory . $newSubDirectory));
-               @rmdir($baseDirectory, $existingDirectory);
-               $this->assertEquals($resultExistingDirectoryPermissions, '0742');
+               $this->assertEquals('0742', substr(decoct(fileperms($baseDirectory . $existingDirectory)), 2));
        }
 
        /**
@@ -3076,10 +3030,10 @@ class GeneralUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
                        $GLOBALS['TYPO3_CONF_VARS']['BE']['createGroup'] = $swapGroup;
                        $directory = uniqid('mkdirdeeptest_');
                        Utility\GeneralUtility::mkdir_deep(PATH_site . 'typo3temp/', $directory);
+                       $this->testFilesToDelete[] = PATH_site . 'typo3temp/' . $directory;
                        clearstatcache();
                        $resultDirectoryGroupInfo = posix_getgrgid(filegroup(PATH_site . 'typo3temp/' . $directory));
                        $resultDirectoryGroup = $resultDirectoryGroupInfo['name'];
-                       @rmdir((PATH_site . 'typo3temp/' . $directory));
                        $this->assertEquals($resultDirectoryGroup, $swapGroup);
                }
        }
@@ -3094,11 +3048,10 @@ class GeneralUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
                        $directory = uniqid('mkdirdeeptest_');
                        $subDirectory = $directory . '/bar';
                        Utility\GeneralUtility::mkdir_deep(PATH_site . 'typo3temp/', $subDirectory);
+                       $this->testFilesToDelete[] = PATH_site . 'typo3temp/' . $directory;
                        clearstatcache();
                        $resultDirectoryGroupInfo = posix_getgrgid(filegroup(PATH_site . 'typo3temp/' . $directory));
                        $resultDirectoryGroup = $resultDirectoryGroupInfo['name'];
-                       @rmdir((PATH_site . 'typo3temp/' . $subDirectory));
-                       @rmdir((PATH_site . 'typo3temp/' . $directory));
                        $this->assertEquals($resultDirectoryGroup, $swapGroup);
                }
        }
@@ -3113,11 +3066,10 @@ class GeneralUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
                        $directory = uniqid('mkdirdeeptest_');
                        $subDirectory = $directory . '/bar';
                        Utility\GeneralUtility::mkdir_deep(PATH_site . 'typo3temp/', $subDirectory);
+                       $this->testFilesToDelete[] = PATH_site . 'typo3temp/' . $directory;
                        clearstatcache();
                        $resultDirectoryGroupInfo = posix_getgrgid(filegroup(PATH_site . 'typo3temp/' . $subDirectory));
                        $resultDirectoryGroup = $resultDirectoryGroupInfo['name'];
-                       @rmdir((PATH_site . 'typo3temp/' . $subDirectory));
-                       @rmdir((PATH_site . 'typo3temp/' . $directory));
                        $this->assertEquals($resultDirectoryGroup, $swapGroup);
                }
        }
@@ -3161,6 +3113,129 @@ class GeneralUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
        }
 
        ///////////////////////////////
+       // Tests concerning rmdir
+       ///////////////////////////////
+
+       /**
+        * @test
+        */
+       public function rmdirRemovesFile() {
+               $file = PATH_site . 'typo3temp/' . uniqid('file_');
+               touch($file);
+               Utility\GeneralUtility::rmdir($file);
+               $this->assertFalse(file_exists($file));
+       }
+
+       /**
+        * @test
+        */
+       public function rmdirReturnTrueIfFileWasRemoved() {
+               $file = PATH_site . 'typo3temp/' . uniqid('file_');
+               touch($file);
+               $this->assertTrue(Utility\GeneralUtility::rmdir($file));
+       }
+
+       /**
+        * @test
+        */
+       public function rmdirReturnFalseIfNoFileWasRemoved() {
+               $file = PATH_site . 'typo3temp/' . uniqid('file_');
+               $this->assertFalse(Utility\GeneralUtility::rmdir($file));
+       }
+
+       /**
+        * @test
+        */
+       public function rmdirRemovesDirectory() {
+               $directory = PATH_site . 'typo3temp/' . uniqid('directory_');
+               mkdir($directory);
+               Utility\GeneralUtility::rmdir($directory);
+               $this->assertFalse(file_exists($directory));
+       }
+
+       /**
+        * @test
+        */
+       public function rmdirRemovesDirectoryWithTrailingSlash() {
+               $directory = PATH_site . 'typo3temp/' . uniqid('directory_') . '/';
+               mkdir($directory);
+               Utility\GeneralUtility::rmdir($directory);
+               $this->assertFalse(file_exists($directory));
+       }
+
+       /**
+        * @test
+        */
+       public function rmdirDoesNotRemoveDirectoryWithFilesAndReturnsFalseIfRecursiveDeletionIsOff() {
+               $directory = PATH_site . 'typo3temp/' . uniqid('directory_') . '/';
+               mkdir($directory);
+               $file = uniqid('file_');
+               touch($directory . $file);
+               $this->testFilesToDelete[] = $directory;
+               $return = Utility\GeneralUtility::rmdir($directory);
+               $this->assertTrue(file_exists($directory));
+               $this->assertTrue(file_exists($directory . $file));
+               $this->assertFalse($return);
+       }
+
+       /**
+        * @test
+        */
+       public function rmdirRemovesDirectoriesRecursiveAndReturnsTrue() {
+               $directory = PATH_site . 'typo3temp/' . uniqid('directory_') . '/';
+               mkdir($directory);
+               mkdir($directory . 'sub/');
+               touch($directory . 'sub/file');
+               $return = Utility\GeneralUtility::rmdir($directory, TRUE);
+               $this->assertFalse(file_exists($directory));
+               $this->assertTrue($return);
+       }
+
+       /**
+        * @test
+        */
+       public function rmdirRemovesLinkToDirectory() {
+               if (TYPO3_OS === 'WIN') {
+                       $this->markTestSkipped('Test not available on Windows OS.');
+               }
+               $existingDirectory = PATH_site . 'typo3temp/' . uniqid('notExists_') . '/';
+               mkdir($existingDirectory);
+               $this->testFilesToDelete[] = $existingDirectory;
+               $symlinkName = 'typo3temp/' . uniqid('link_');
+               symlink($existingDirectory, $symlinkName);
+               Utility\GeneralUtility::rmdir($symlinkName, TRUE);
+               $this->assertFalse(is_link($symlinkName));
+       }
+
+       /**
+        * @test
+        */
+       public function rmdirRemovesDeadLinkToDirectory() {
+               if (TYPO3_OS === 'WIN') {
+                       $this->markTestSkipped('Test not available on Windows OS.');
+               }
+               $notExistingDirectory = PATH_site . 'typo3temp/' . uniqid('notExists_') . '/';
+               $symlinkName = 'typo3temp/' . uniqid('link_');
+               symlink($notExistingDirectory, $symlinkName);
+               Utility\GeneralUtility::rmdir($symlinkName, TRUE);
+               $this->assertFalse(is_link($symlinkName));
+       }
+
+       /**
+        * @test
+        */
+       public function rmdirRemovesDeadLinkToFile() {
+               if (TYPO3_OS === 'WIN') {
+                       $this->markTestSkipped('Test not available on Windows OS.');
+               }
+               $notExistingFile = PATH_site . 'typo3temp/' . uniqid('notExists_');
+               $symlinkName = 'typo3temp/' . uniqid('link_');
+               symlink($notExistingFile, $symlinkName);
+               Utility\GeneralUtility::rmdir($symlinkName, TRUE);
+               $this->assertFalse(is_link($symlinkName));
+       }
+
+       ///////////////////////////////
        // Tests concerning unQuoteFilenames
        ///////////////////////////////
        /**
@@ -3430,7 +3505,6 @@ class GeneralUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
                        'distrubuted ../ with trailing /' => array('dir1/../dir2/dir3/../', 'dir2/'),
                        'distributed ../ without trailing /' => array('dir1/../dir2/dir3/..', 'dir2'),
                        'multiple distributed and consecutive ../ together' => array('dir1/dir2/dir3/dir4/../../dir5/dir6/dir7/../dir8/', 'dir1/dir2/dir5/dir6/dir8/'),
-                       'multiple distributed and consecutive ../ together' => array('dir1/dir2/dir3/dir4/../../dir5/dir6/dir7/../dir8/', 'dir1/dir2/dir5/dir6/dir8/'),
                        'dirname with leading ..' => array('dir1/..dir2/dir3/', 'dir1/..dir2/dir3/'),
                        'dirname with trailing ..' => array('dir1/dir2../dir3/', 'dir1/dir2../dir3/'),
                        'more times upwards than downwards in directory' => array('dir1/../../', '../'),
@@ -3775,10 +3849,9 @@ class GeneralUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
                $GLOBALS['TYPO3_CONF_VARS']['BE']['fileCreateMask'] = '0777';
                // Call method, get actual permissions and clean up
                Utility\GeneralUtility::syslog('testLog', 'test', Utility\GeneralUtility::SYSLOG_SEVERITY_NOTICE);
+               $this->testFilesToDelete[] = $testLogFilename;
                clearstatcache();
-               $resultFilePermissions = substr(decoct(fileperms($testLogFilename)), 2);
-               Utility\GeneralUtility::unlink_tempfile($testLogFilename);
-               $this->assertEquals($resultFilePermissions, '0777');
+               $this->assertEquals('0777', substr(decoct(fileperms($testLogFilename)), 2));
        }
 
        /**
@@ -3795,10 +3868,10 @@ class GeneralUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
                $GLOBALS['TYPO3_CONF_VARS']['BE']['fileCreateMask'] = '0777';
                // Call method, get actual permissions and clean up
                Utility\GeneralUtility::deprecationLog('foo');
+               $this->testFilesToDelete[] = $deprecationLogFilename;
                clearstatcache();
                $resultFilePermissions = substr(decoct(fileperms($deprecationLogFilename)), 2);
-               @unlink($deprecationLogFilename);
-               $this->assertEquals($resultFilePermissions, '0777');
+               $this->assertEquals('0777', $resultFilePermissions);
        }
 
        ///////////////////////////////////////////////////