/**
  * Gets the TYPO3 Locker object or creates an instance of it.
  *
  * @throws \RuntimeException
  * @return \TYPO3\CMS\Core\Locking\Locker|NULL Only NULL if we are in installer and typo3temp does not exist yet
  */
 protected function getLocker()
 {
     if (NULL === $this->lockObject) {
         $this->isLoadingLocker = TRUE;
         try {
             $this->lockObject = new Locker('ClassLoader-cache-classes', Locker::LOCKING_METHOD_SIMPLE);
         } catch (\RuntimeException $e) {
             // The RuntimeException in constructor happens if directory typo3temp/locks could not be created.
             // This usually happens during installation step 1 where typo3temp itself does not exist yet. In
             // this case we proceed without locking, otherwise a missing typo3temp directory indicates a
             // hard problem of the instance and we throw up.
             // @TODO: This solution currently conflicts with separation of concerns since the class loader
             // handles installation specific stuff. Find a better way to do this.
             if (defined('TYPO3_enterInstallScript') && TYPO3_enterInstallScript) {
                 // Installer is running => So work without Locking.
                 return NULL;
             } else {
                 throw $e;
             }
         }
         $this->lockObject->setEnableLogging(FALSE);
         $this->isLoadingLocker = FALSE;
     }
     return $this->lockObject;
 }
예제 #2
0
 /**
  * @test
  * @dataProvider invalidFileReferences
  */
 public function releaseDoesNotRemoveFilesNotWithinTypo3TempLocksDirectory($lockMethod, $file)
 {
     if (TYPO3_OS === 'WIN') {
         $this->markTestSkipped('releaseDoesNotRemoveFilesNotWithinTypo3TempLocksDirectory() test not available on Windows.');
     }
     // Create test file
     touch($file);
     if (!is_file($file)) {
         $this->markTestSkipped('releaseDoesNotRemoveFilesNotWithinTypo3TempLocksDirectory() skipped: Test file could not be created');
     }
     // Create instance, set lockfile to invalid path
     $instance = new Locker(999999999, $lockMethod);
     $instance->setEnableLogging(false);
     $t3libLockReflection = new \ReflectionClass(\TYPO3\CMS\Core\Locking\Locker::class);
     $t3libLockReflectionResourceProperty = $t3libLockReflection->getProperty('resource');
     $t3libLockReflectionResourceProperty->setAccessible(true);
     $t3libLockReflectionResourceProperty->setValue($instance, $file);
     $t3libLockReflectionAcquiredProperty = $t3libLockReflection->getProperty('isAcquired');
     $t3libLockReflectionAcquiredProperty->setAccessible(true);
     $t3libLockReflectionAcquiredProperty->setValue($instance, true);
     // Call release method
     $instance->release();
     // Check if file is still there and clean up
     $fileExists = is_file($file);
     if (is_file($file)) {
         unlink($file);
     }
     $this->assertTrue($fileExists);
 }