Project

General

Profile

Actions

Bug #64113

closed

GeneralUtility::writeFile() fails if directory not existing

Added by Boris Günther almost 10 years ago. Updated almost 10 years ago.

Status:
Rejected
Priority:
Must have
Assignee:
-
Category:
-
Target version:
-
Start date:
2015-01-04
Due date:
% Done:

0%

Estimated time:
TYPO3 Version:
6.2
PHP Version:
5.5
Tags:
Complexity:
Is Regression:
No
Sprint Focus:

Description

Hello TYPO3-Team,

I found a possible bug in \TYPO3\CMS\Core\Utility\GeneralUtility::writeFile();.

Problem:

The method does not check if the parent directory exists and therefore gets an error when trying to fopen() the file.

Solution:

Adding this snippet at beginning of the method fixes the problem:

// Create the folder if missing
if(!is_dir(dirname($file))) {
    //Get creation mask
    $targetDirectoryPermissions = isset($GLOBALS['TYPO3_CONF_VARS']['BE']['folderCreateMask']) ? octdec($GLOBALS['TYPO3_CONF_VARS']['BE']['folderCreateMask']) : octdec('0755');

    //Create folder
    if(mkdir(dirname($file), 0777, true) !== true) {
        return FALSE;
    }
}

Reproducibility:

The error occurs only when updating extension languages against a custom translation server.

Environment:

PHP: 5.5.14
TYPO3: 6.2.9


Files

trb_tool_translation-l10n-de.zip (474 Bytes) trb_tool_translation-l10n-de.zip Boris Günther, 2015-01-04 19:23
Actions #1

Updated by Boris Günther almost 10 years ago

Shorter Solution:

// Create the folder if missing
if(!is_dir(dirname($file))) {
    self::mkdir_deep(rtrim(dirname($file), '/').'/');
}
Actions #3

Updated by Markus Klein almost 10 years ago

  • Status changed from New to Needs Feedback

writeFile() does not care about the directory, nor does the name suggest any directory handling.
If there's a bug with missing directories the surrounding code has to be adjusted.

I don't understand your usecase though, so please describe your usecase in more detail (and maybe tell us what the uploaded file is about).
Thanks.

Actions #4

Updated by Boris Günther almost 10 years ago

Markus Klein wrote:

writeFile() does not care about the directory, nor does the name suggest any directory handling.
If there's a bug with missing directories the surrounding code has to be adjusted.

I don't understand your usecase though, so please describe your usecase in more detail (and maybe tell us what the uploaded file is about).
Thanks.

Dear Markus,

you are right - the function does not suggest - it´d just have been some kind of comfort / fallback if it would do.

Meanwhile I found the reason why the error occured and was able to fix it.

I am developing a custom translation server which also creates the language-pack ZIP-Files.
My fault was that I did not add an directory entry for the file and therefore TYPO3 did not call the mkdir method in TER-Connection class (I think it was there...).

The uploaded file can be found in bug`s history #2.

From my side the problem is solved - but perhaps you´d like to adjust the core to create the directory even if the dir entry in the zip is missing.

Actions #5

Updated by Markus Klein almost 10 years ago

  • Status changed from Needs Feedback to Rejected

Well, I would prefer to have exactly 1 way of doing things. Also only 1 data structure that is accepted.
So I would leave things as they are.

Actions

Also available in: Atom PDF