MaxServ / t3ext-fal_s3

S3 driver for FAL
GNU General Public License v2.0
13 stars 10 forks source link

Inconsistent runtime folderExistsCache #55

Closed shroom24 closed 1 year ago

shroom24 commented 4 years ago

I'm running into a problem when creating nested folders in a foreach loop.

/* @var processingFolder TYPO3\CMS\Core\Resource\Folder */
foreach ($nestedFolderNames as $folderName) {
    if ($processingFolder->hasFolder($folderName)) {
        $processingFolder = $processingFolder->getSubfolder($folderName);
    } else {
        $processingFolder = $processingFolder->createFolder($folderName);
    }
}

This ultimately calls the functions folderExists() and createFolder() in MaxServ\FalS3\Driver\AmazonS3Driver.

When a folder doesn't exist, the local runtime cache is updated with a false (line 377):

public function folderExists($folderIdentifier)
{
    ...

    if (!array_key_exists($path, $this->folderExistsCache)) {
        $this->folderExistsCache[$path] = is_dir($path);
    }

    ...
}

When then the folder is created with createFolder() the runtime cache doesn't get updated resulting in an error in the next loop of folderExist().

The persistent cache is taken care of but not the local runtime cache (line 284):

$this->flushCacheEntriesForFolder($parentFolderIdentifier);

This behaviour is easily fixed by unsetting the key in the local runtime cache after the creation of the folder

public function createFolder($newFolderName, $parentFolderIdentifier = '', $recursive = false)
{
    ...

    unset($this->folderExistsCache[$path]);

    return $identifier;
}

or even quicker with

$this->folderExistsCache[$path] = true;

I expect the same to be true for deleteFolder() but haven't tested it.

DerFrenk commented 1 year ago

Hi @shroom24,

Sorry for the late reply. We fixed this issue in https://github.com/MaxServ/t3ext-fal_s3/pull/65 :)