fix(terminal): Update filename parsing regex and improve directory cleanup logic

This commit is contained in:
Ahliman HUSEYNOV 2025-11-19 22:47:19 +01:00
parent ec67078d49
commit 2bcf642e22
No known key found for this signature in database
2 changed files with 6 additions and 3 deletions

View file

@ -55,7 +55,7 @@ class TerminalFileHelper
public static function parseFilename(string $filename): ?array
{
// Pattern: uploadedAt_expiresAt_serverId_containerUuid_originalName_hash.ext
$pattern = '/^(\d+)_(\d+)_(\d+)_([^_]+)_([^_]+)_([a-zA-Z0-9]+)(?:\.(.+))?$/';
$pattern = '/^(\d+)_(\d+)_(\d+)_([^_]+)_([^_]+)_([a-zA-Z0-9]+)(?:\.([a-zA-Z0-9]+))?$/';
if (!preg_match($pattern, $filename, $matches)) {
return null;

View file

@ -67,8 +67,11 @@ class CleanupExpiredTerminalFilesJob implements ShouldQueue
// Clean up empty parent directory
$parentDir = dirname($this->localPath);
if (is_dir($parentDir) && count(scandir($parentDir)) === 2) { // Only . and ..
rmdir($parentDir);
if (is_dir($parentDir)) {
$contents = scandir($parentDir);
if ($contents !== false && count($contents) === 2) { // Only . and ..
rmdir($parentDir);
}
}
} catch (\Throwable $e) {
Log::error("Failed to cleanup terminal file: {$e->getMessage()}", [