Merge pull request #1 from livindra/railway/code-change-qKrwFx

Fix storage:link symlink conflicts during deployment
This commit is contained in:
livindra 2026-05-05 14:20:38 +07:00 committed by GitHub
commit 78c34dcb39
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
18 changed files with 91 additions and 0 deletions

2
.gitignore vendored
View File

@ -16,6 +16,8 @@
/public/build
/public/hot
/public/storage
/public/profile
/public/laporan
/storage/*.key
/storage/pail
/vendor

View File

@ -0,0 +1,83 @@
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
class StorageLinkSafe extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'storage:link-safe';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Create symbolic links for storage without failing if they already exist';
/**
* Execute the console command.
*/
public function handle(): int
{
$links = config('filesystems.links', [
public_path('storage') => storage_path('app/public'),
]);
foreach ($links as $link => $target) {
if (is_link($link)) {
$this->line("The [{$link}] link already exists. Skipping.");
continue;
}
if (is_dir($link)) {
$this->warn("A directory already exists at [{$link}]. Removing it before creating the symlink.");
$this->removeDirectory($link);
}
if (file_exists($link)) {
$this->warn("A file already exists at [{$link}]. Removing it before creating the symlink.");
unlink($link);
}
if (!is_dir($target)) {
mkdir($target, 0755, true);
}
symlink($target, $link);
$this->info("The [{$link}] link has been connected to [{$target}].");
}
$this->info('Storage links created successfully.');
return self::SUCCESS;
}
/**
* Recursively remove a directory and its contents.
*/
protected function removeDirectory(string $dir): void
{
if (!is_dir($dir)) {
return;
}
$items = array_diff(scandir($dir), ['.', '..']);
foreach ($items as $item) {
$path = $dir . DIRECTORY_SEPARATOR . $item;
if (is_dir($path) && !is_link($path)) {
$this->removeDirectory($path);
} else {
unlink($path);
}
}
rmdir($dir);
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.2 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 90 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 448 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 244 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 244 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 448 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 344 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 244 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.9 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 448 KiB

View File

@ -1,2 +1,8 @@
*
!.gitignore
!profile/
!laporan/
profile/*
!profile/.gitkeep
laporan/*
!laporan/.gitkeep

View File

View File