Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[8.x] Allow symlink recreation in storage:link command #37501

Merged
merged 3 commits into from
May 27, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions src/Illuminate/Foundation/Console/StorageLinkCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ class StorageLinkCommand extends Command
*
* @var string
*/
protected $signature = 'storage:link {--relative : Create the symbolic link using relative paths}';
protected $signature = 'storage:link
{--relative : Create the symbolic link using relative paths}
{--force : Recreate already existing symbolic links}';

/**
* The console command description.
Expand All @@ -28,9 +30,10 @@ class StorageLinkCommand extends Command
public function handle()
{
$relative = $this->option('relative');
$force = $this->option('force');

foreach ($this->links() as $link => $target) {
if (file_exists($link)) {
if (file_exists($link) && ! $this->removableSymlink($link, $force)) {
$this->error("The [$link] link already exists.");
continue;
}
Expand Down Expand Up @@ -61,4 +64,16 @@ protected function links()
return $this->laravel['config']['filesystems.links'] ??
[public_path('storage') => storage_path('app/public')];
}

/**
* Checks that the provided path is a symlink and force option is turned on.
*
* @param string $link
* @param bool $force
* @return bool
*/
protected function removableSymlink(string $link, bool $force): bool
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Boolean methods often are prefixed with is or has:

Suggested change
protected function removableSymlink(string $link, bool $force): bool
protected function isRemovableSymlink(string $link, bool $force): bool

{
return is_link($link) && $force;
}
}