Skip to content

Commit

Permalink
Fix #414 - Avoid multiple renamings for one folder
Browse files Browse the repository at this point in the history
  • Loading branch information
lochmueller committed Oct 27, 2024
1 parent 98f9542 commit ca188d8
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions Classes/Service/RemoveService.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace SFC\Staticfilecache\Service;

use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Utility\DebuggerUtility;

class RemoveService
{
Expand Down Expand Up @@ -67,10 +68,14 @@ public function subdirectories(string $absoluteDirName): self
public function directory(string $absoluteDirName): self
{
if (is_dir($absoluteDirName)) {
// @todo only rename, if there is no microtime at the end
$tempAbsoluteDir = rtrim($absoluteDirName, '/') . '_' . round(microtime(true) * 1000) . '/';
rename($absoluteDirName, $tempAbsoluteDir);
$this->removeDirs[] = $tempAbsoluteDir;
$alreadyRenamed = (bool) \preg_match('/.*([0-9]{11,14})$/', rtrim($absoluteDirName, '/'));
if ($alreadyRenamed) {
$this->removeDirs[] = $absoluteDirName;
} else {
$tempAbsoluteDir = rtrim($absoluteDirName, '/') . '_' . round(microtime(true) * 1000) . '/';
rename($absoluteDirName, $tempAbsoluteDir);
$this->removeDirs[] = $tempAbsoluteDir;
}
}

return $this;
Expand Down

0 comments on commit ca188d8

Please sign in to comment.