Skip to content

Commit e0402fc

Browse files
committed
Merge branch 'force-storage-link' into 8.x
2 parents 41c47ef + 3e547d2 commit e0402fc

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

src/Illuminate/Foundation/Console/StorageLinkCommand.php

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ class StorageLinkCommand extends Command
1111
*
1212
* @var string
1313
*/
14-
protected $signature = 'storage:link {--relative : Create the symbolic link using relative paths}';
14+
protected $signature = 'storage:link
15+
{--relative : Create the symbolic link using relative paths}
16+
{--force : Recreate existing symbolic links}';
1517

1618
/**
1719
* The console command description.
@@ -30,7 +32,7 @@ public function handle()
3032
$relative = $this->option('relative');
3133

3234
foreach ($this->links() as $link => $target) {
33-
if (file_exists($link)) {
35+
if (file_exists($link) && ! $this->removableSymlink($link, $this->option('force'))) {
3436
$this->error("The [$link] link already exists.");
3537
continue;
3638
}
@@ -61,4 +63,16 @@ protected function links()
6163
return $this->laravel['config']['filesystems.links'] ??
6264
[public_path('storage') => storage_path('app/public')];
6365
}
66+
67+
/**
68+
* Determine if the provided path is a symlink that can be removed.
69+
*
70+
* @param string $link
71+
* @param bool $force
72+
* @return bool
73+
*/
74+
protected function removableSymlink(string $link, bool $force): bool
75+
{
76+
return is_link($link) && $force;
77+
}
6478
}

0 commit comments

Comments
 (0)