Issue Bug Rejected

#64113GeneralUtility::writeFile() fails if directory not existing

Boris Günther 01/04/15, 19:13 updated 01/08/15, 14:38

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

Reviews 0

No change resolves or names this issue in its commit message, and no comment links one.