Issue Bug Closed

#88455Never attach random string if file already exists in folder

Thomas Walder 05/29/19, 15:44 updated 12/23/19, 22:49

Description

\TYPO3\CMS\Core\Utility\File\BasicFileUtility::getUniqueName

The inner condition never can be reached if $a equals $this->maxNumber. Result is, that “then we try unique-strings” never can be executed

for ($a = 1; $a < $this->maxNumber; $a++) {
    if ($a <= $this->maxNumber) {
        // First we try to append numbers
        $insert = '_' . sprintf('%02d', $a);
    } else {
        // .. then we try unique-strings...
        $insert = '_' . substr(md5(uniqid('', true)), 0, $this->uniquePrecision);
    }

Working Code

for ($a = 1; $a <= $this->maxNumber; $a++) {
    if ($a < $this->maxNumber) {
        // First we try to append numbers
        $insert = '_' . sprintf('%02d', $a);
    } else {
        // .. then we try unique-strings...
        $insert = '_' . substr(md5(uniqid('', true)), 0, $this->uniquePrecision);
    }

The change was made in 30282eef79e069fe78ea39e53df2fc003bc6c2f4 [!!!][TASK] Cleanup and remove old filefunc logic on 2016-01-08 by Benni Mack

Reviews 3