prepare public symlink
All checks were successful
CI/CD Pipeline / deploy (push) Successful in 24s
CI/CD Pipeline / promote_stable (push) Successful in 2s

This commit is contained in:
2026-02-26 19:08:37 +01:00
parent 7b22d89dfd
commit 41387be802
12 changed files with 182 additions and 14 deletions

View File

@@ -8,6 +8,7 @@ use Illuminate\Http\Request;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Str;
use RuntimeException;
use Symfony\Component\Process\Process;
class SystemUpdateController extends Controller
@@ -113,7 +114,7 @@ class SystemUpdateController extends Controller
$append('Syncing files...');
$usedRsync = false;
$rsyncPath = trim((string) shell_exec('command -v rsync'));
$protectedPaths = ['custom', 'public/custom'];
$protectedPaths = ['storage', 'public/storage', 'custom', 'public/custom'];
if ($rsyncPath !== '') {
$usedRsync = true;
$rsync = new Process([
@@ -149,6 +150,8 @@ class SystemUpdateController extends Controller
File::copyDirectory($sourceDir, base_path());
}
$this->ensurePublicStorageLink();
$append('Installing composer dependencies...');
$composer = new Process(['composer', 'install', '--no-dev', '--optimize-autoloader'], base_path());
$composer->setTimeout(600);
@@ -212,4 +215,39 @@ class SystemUpdateController extends Controller
], 500);
}
}
private function ensurePublicStorageLink(): void
{
$storagePublic = storage_path('app/public');
$publicStorage = public_path('storage');
if (file_exists($storagePublic) && !is_dir($storagePublic)) {
@rename($storagePublic, $storagePublic.'.bak.'.date('Ymd_His'));
}
if (!is_dir($storagePublic) && !@mkdir($storagePublic, 0775, true) && !is_dir($storagePublic)) {
throw new RuntimeException('Failed to prepare storage/app/public directory.');
}
if (is_link($publicStorage)) {
$target = readlink($publicStorage);
$resolved = $target !== false ? realpath(dirname($publicStorage).DIRECTORY_SEPARATOR.$target) : false;
$expected = realpath($storagePublic);
if ($resolved !== $expected) {
@unlink($publicStorage);
}
} elseif (is_dir($publicStorage)) {
File::copyDirectory($publicStorage, $storagePublic);
File::deleteDirectory($publicStorage);
} elseif (file_exists($publicStorage)) {
@rename($publicStorage, $publicStorage.'.bak.'.date('Ymd_His'));
}
if (!is_link($publicStorage) && !@symlink($storagePublic, $publicStorage)) {
throw new RuntimeException('Failed to recreate public/storage symlink.');
}
foreach (['avatars', 'logos', 'favicons', 'rank-badges'] as $dir) {
File::ensureDirectoryExists($storagePublic.DIRECTORY_SEPARATOR.$dir);
}
}
}