Bug #64113
closedGeneralUtility::writeFile() fails if directory not existing
0%
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
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), '/').'/'); }
Updated by Boris Günther almost 10 years ago
The LanguagePack-ZIP-File
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.
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.
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.