[BUGFIX] Warning in Locker if filepointer is no resource
authorChristian Kuhn <lolli@schwarzbu.ch>
Sun, 2 Sep 2012 19:58:18 +0000 (21:58 +0200)
committerChristian Kuhn <lolli@schwarzbu.ch>
Sun, 2 Sep 2012 20:05:35 +0000 (22:05 +0200)
The 'flock' locking calls flose() without checking if the filepointer
is actually a resource. This leads to warnings, triggered by
releaseDoesNotRemoveFilesNotWithinTypo3TempLocksDirectory().
Solution is to check for a valid resource before calling flock() and
fclose().

Change-Id: I2832f2e4ea3ce2780bd347bbb3bb64fa449ab388
Fixes: #40539
Releases: 6.0
Reviewed-on: http://review.typo3.org/14294
Reviewed-by: Christian Kuhn
Tested-by: Christian Kuhn
typo3/sysext/core/Classes/Locking/Locker.php
typo3/sysext/core/Tests/Unit/Locking/LockerTest.php

index fb37874..fa12490 100644 (file)
@@ -231,10 +231,12 @@ class Locker {
                        }
                        break;
                case 'flock':
-                       if (flock($this->filepointer, LOCK_UN) == FALSE) {
-                               $success = FALSE;
+                       if (is_resource($this->filepointer)) {
+                               if (flock($this->filepointer, LOCK_UN) == FALSE) {
+                                       $success = FALSE;
+                               }
+                               fclose($this->filepointer);
                        }
-                       fclose($this->filepointer);
                        if (\TYPO3\CMS\Core\Utility\GeneralUtility::isAllowedAbsPath($this->resource) && \TYPO3\CMS\Core\Utility\GeneralUtility::isFirstPartOfStr($this->resource, PATH_site . 'typo3temp/locks/')) {
                                @unlink($this->resource);
                        }
index c4a9c20..4f02b61 100644 (file)
@@ -76,7 +76,7 @@ class LockerTest extends \tx_phpunit_testcase {
 
        /**
         * @test
-        * @expectedException InvalidArgumentException
+        * @expectedException \InvalidArgumentException
         */
        public function constructorThrowsExceptionForNotExistingLockingMethod() {
                $instance = new \TYPO3\CMS\Core\Locking\Locker('999999999', 'foo');
@@ -218,7 +218,7 @@ class LockerTest extends \tx_phpunit_testcase {
         */
        public function releaseRemovesLockfileInTypo3TempLocks($lockMethod) {
                // Use a very high id to be unique
-               $instance = new \TYPO3\CMS\Core\Locking\Locker(999999999, 'simple');
+               $instance = new \TYPO3\CMS\Core\Locking\Locker(999999999, $lockMethod);
                // Disable logging
                $instance->setEnableLogging(FALSE);
                // File pointer to current lock file