[BUGFIX] Correct permissions of new files 36/21336/7
authorMichael Knabe <michael.knabe@e-net.info>
Tue, 11 Jun 2013 12:26:35 +0000 (14:26 +0200)
committerChristian Kuhn <lolli@schwarzbu.ch>
Thu, 20 Jun 2013 10:32:23 +0000 (12:32 +0200)
Set the correct file permissions of files created with
FAL according to the fileCreateMask.

Change-Id: I4d6562f926cd79a98c3d6b0545a14915c1d7a766
Resolves: #49029
Releases: 6.0, 6.1, 6.2
Reviewed-on: https://review.typo3.org/21336
Reviewed-by: Anja Leichsenring
Tested-by: Anja Leichsenring
Reviewed-by: Christian Kuhn
Tested-by: Christian Kuhn
typo3/sysext/core/Classes/Resource/Driver/LocalDriver.php
typo3/sysext/core/Tests/Unit/Resource/Driver/LocalDriverTest.php

index c1afc57..efffe40 100644 (file)
@@ -1110,8 +1110,8 @@ class LocalDriver extends \TYPO3\CMS\Core\Resource\Driver\AbstractDriver {
                        throw new \TYPO3\CMS\Core\Resource\Exception\InvalidFileNameException('Invalid characters in fileName "' . $fileName . '"', 1320572272);
                }
                $filePath = $parentFolder->getIdentifier() . $this->sanitizeFileName(ltrim($fileName, '/'));
-               // TODO set permissions of new file
                $result = touch($this->absoluteBasePath . $filePath);
+               GeneralUtility::fixPermissions($this->absoluteBasePath . ltrim($filePath, '/'));
                clearstatcache();
                if ($result !== TRUE) {
                        throw new \RuntimeException('Creating file ' . $filePath . ' failed.', 1320569854);
index f4ac018..b52e90e 100644 (file)
@@ -647,6 +647,30 @@ class LocalDriverTest extends \TYPO3\CMS\Core\Tests\Unit\Resource\BaseTestCase {
                $this->assertEquals(0, strlen($fileData));
        }
 
+       /**
+        * @test
+        */
+       public function createFileFixesPermissionsOnCreatedFile() {
+               if (TYPO3_OS == 'WIN') {
+                       $this->markTestSkipped('createdFilesHaveCorrectRights() tests not available on Windows');
+               }
+
+               // No one will use this as his default file create mask so we hopefully don't get any false positives
+               $testpattern = '0046';
+               $GLOBALS['TYPO3_CONF_VARS']['BE']['fileCreateMask'] = $testpattern;
+
+               $this->addToMount(
+                       array(
+                               'someDir' => array()
+                       )
+               );
+               /** @var $fixture \TYPO3\CMS\Core\Resource\Driver\LocalDriver */
+               list($basedir, $fixture) = $this->prepareRealTestEnvironment();
+               mkdir($basedir . '/someDir');
+               $fixture->createFile('testfile.txt', $fixture->getFolder('/someDir'));
+               $this->assertEquals($testpattern, decoct(fileperms($basedir . '/someDir/testfile.txt') & 0777));
+       }
+
        /**********************************
         * File and directory listing
         **********************************/