[BUGFIX] Fix warning during extension installation 31/28731/3
authorHelmut Hummel <helmut.hummel@typo3.org>
Mon, 24 Mar 2014 23:48:26 +0000 (00:48 +0100)
committerErnesto Baschny <ernst@cron-it.de>
Tue, 25 Mar 2014 01:00:05 +0000 (02:00 +0100)
During unpacking of an extension in the installation
process it can happen that the extension data
contains folders in the file list.

These folders need to be removed from the list
in order to avoid warnings when trying to write
directories as files.

Also remove duplicates from folders before
creating them.

Besides fix some (non related) comparisons to
strict comparisons on the go.

Resolves: #57261
Releases: 6.2
Change-Id: Ib6821a0a438ebc9441b8fa2ee3fbd7869f23ec7f
Reviewed-on: https://review.typo3.org/28731
Reviewed-by: Philipp Gampe
Tested-by: Philipp Gampe
Reviewed-by: Ernesto Baschny
Tested-by: Ernesto Baschny
typo3/sysext/extensionmanager/Classes/Utility/Connection/TerUtility.php
typo3/sysext/extensionmanager/Classes/Utility/FileHandlingUtility.php
typo3/sysext/extensionmanager/Tests/Unit/Utility/FileHandlingUtilityTest.php

index bebcc15..02c0a81 100644 (file)
@@ -60,7 +60,7 @@ class TerUtility {
                if ($t3x === FALSE) {
                        throw new \TYPO3\CMS\Extensionmanager\Exception\ExtensionManagerException(sprintf('The T3X file "%s" could not be fetched. Possible reasons: network problems, allow_url_fopen is off,' . ' cURL is not enabled in Install Tool.', $mirrorUrl), 1334426097);
                }
-               if ($md5 == $expectedMd5) {
+               if ($md5 === $expectedMd5) {
                        // Fetch and return:
                        $extensionData = $this->decodeExchangeData($t3x);
                } else {
@@ -121,7 +121,7 @@ class TerUtility {
                                throw new \TYPO3\CMS\Extensionmanager\Exception\ExtensionManagerException('Decoding Error: No decompressor available for compressed content. gzcompress()/gzuncompress() ' . 'functions are not available!', 1344761814);
                        }
                }
-               if (md5($parts[2]) == $parts[0]) {
+               if (md5($parts[2]) === $parts[0]) {
                        $output = unserialize($parts[2]);
                        if (!is_array($output)) {
                                throw new \TYPO3\CMS\Extensionmanager\Exception\ExtensionManagerException('Error: Content could not be unserialized to an array. Strange (since MD5 hashes match!)', 1344761938);
index 1a70bed..311042b 100644 (file)
@@ -58,6 +58,7 @@ class FileHandlingUtility implements \TYPO3\CMS\Core\SingletonInterface {
                $extensionDir = $this->makeAndClearExtensionDir($extensionData['extKey'], $pathType);
                $files = $this->extractFilesArrayFromExtensionData($extensionData);
                $directories = $this->extractDirectoriesFromExtensionData($files);
+               $files = array_diff_key($files, array_flip($directories));
                $this->createDirectoriesForExtensionFiles($directories, $extensionDir);
                $this->writeExtensionFiles($files, $extensionDir);
                $this->writeEmConfToFile($extensionData, $extensionDir, $extension);
@@ -73,9 +74,11 @@ class FileHandlingUtility implements \TYPO3\CMS\Core\SingletonInterface {
                $directories = array();
                foreach ($files as $filePath => $file) {
                        preg_match('/(.*)\\//', $filePath, $matches);
-                       $directories[] = $matches[0];
+                       if (!empty($matches[0])) {
+                               $directories[] = $matches[0];
+                       }
                }
-               return $directories;
+               return array_unique($directories);
        }
 
        /**
index 0f3fb3d..0c756a3 100644 (file)
@@ -242,6 +242,73 @@ class FileHandlingUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
         * @test
         * @return void
         */
+       public function unpackExtensionFromExtensionDataArrayStripsDirectoriesFromFilesArray() {
+               $extensionData = array(
+                       'extKey' => 'test'
+               );
+               $files = array(
+                       'ChangeLog' => array(
+                               'name' => 'ChangeLog',
+                               'size' => 4559,
+                               'mtime' => 1219448527,
+                               'is_executable' => FALSE,
+                               'content' => 'some content to write'
+                       ),
+                       'doc/' => array(
+                               'name' => 'doc/',
+                               'size' => 0,
+                               'mtime' => 1219448527,
+                               'is_executable' => FALSE,
+                               'content' => ''
+                       ),
+                       'doc/ChangeLog' => array(
+                               'name' => 'ChangeLog',
+                               'size' => 4559,
+                               'mtime' => 1219448527,
+                               'is_executable' => FALSE,
+                               'content' => 'some content to write'
+                       ),
+               );
+               $cleanedFiles = array(
+                       'ChangeLog' => array(
+                               'name' => 'ChangeLog',
+                               'size' => 4559,
+                               'mtime' => 1219448527,
+                               'is_executable' => FALSE,
+                               'content' => 'some content to write'
+                       ),
+                       'doc/ChangeLog' => array(
+                               'name' => 'ChangeLog',
+                               'size' => 4559,
+                               'mtime' => 1219448527,
+                               'is_executable' => FALSE,
+                               'content' => 'some content to write'
+                       ),
+               );
+               $directories = array(
+                       'doc/',
+                       'mod/doc/'
+               );
+
+               $fileHandlerMock = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Utility\\FileHandlingUtility', array(
+                       'makeAndClearExtensionDir',
+                       'writeEmConfToFile',
+                       'extractFilesArrayFromExtensionData',
+                       'extractDirectoriesFromExtensionData',
+                       'createDirectoriesForExtensionFiles',
+                       'writeExtensionFiles'
+               ));
+               $fileHandlerMock->expects($this->once())->method('extractFilesArrayFromExtensionData')->will($this->returnValue($files));
+               $fileHandlerMock->expects($this->once())->method('extractDirectoriesFromExtensionData')->will($this->returnValue($directories));
+               $fileHandlerMock->expects($this->once())->method('createDirectoriesForExtensionFiles')->with($directories);
+               $fileHandlerMock->expects($this->once())->method('writeExtensionFiles')->with($cleanedFiles);
+               $fileHandlerMock->_call('unpackExtensionFromExtensionDataArray', $extensionData);
+       }
+
+       /**
+        * @test
+        * @return void
+        */
        public function extractFilesArrayFromExtensionDataReturnsFileArray() {
                $extensionData = array(
                        'key' => 'test',
@@ -289,6 +356,20 @@ class FileHandlingUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
         */
        public function extractDirectoriesFromExtensionDataExtractsDirectories() {
                $files = array(
+                       'ChangeLog' => array(
+                               'name' => 'ChangeLog',
+                               'size' => 4559,
+                               'mtime' => 1219448527,
+                               'is_executable' => FALSE,
+                               'content' => 'some content to write'
+                       ),
+                       'doc/' => array(
+                               'name' => 'doc/',
+                               'size' => 0,
+                               'mtime' => 1219448527,
+                               'is_executable' => FALSE,
+                               'content' => ''
+                       ),
                        'doc/ChangeLog' => array(
                                'name' => 'ChangeLog',
                                'size' => 4559,
@@ -296,6 +377,13 @@ class FileHandlingUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
                                'is_executable' => FALSE,
                                'content' => 'some content to write'
                        ),
+                       'doc/README' => array(
+                               'name' => 'README',
+                               'size' => 4566,
+                               'mtime' => 1219448533,
+                               'is_executable' => FALSE,
+                               'content' => 'FEEL FREE TO ADD SOME DOCUMENTATION HERE'
+                       ),
                        'mod/doc/README' => array(
                                'name' => 'README',
                                'size' => 4566,
@@ -306,8 +394,11 @@ class FileHandlingUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
                );
                $fileHandlerMock = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Utility\\FileHandlingUtility', array('makeAndClearExtensionDir'));
                $extractedDirectories = $fileHandlerMock->_call('extractDirectoriesFromExtensionData', $files);
-               $this->assertContains('doc/', $extractedDirectories);
-               $this->assertContains('mod/doc/', $extractedDirectories);
+               $expected = array(
+                       'doc/',
+                       'mod/doc/'
+               );
+               $this->assertSame($expected, array_values($extractedDirectories));
        }
 
        /**