Skip to content

Commit

Permalink
Delete existing links that are broken (#36470)
Browse files Browse the repository at this point in the history
When a link exists but is broken, `file_exists($link)` return false. And
when `symlink($link, $target)` is called on a broken link, a PHP Warning
is returned and the link is not updated. To fix this, we add an
additional check using `is_link($link)` (which return true, even if the
link is broken) to detect and delete broken links.
  • Loading branch information
pgrenaud authored Mar 5, 2021
1 parent a817662 commit 18daf46
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Illuminate/Foundation/Console/StorageLinkCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ public function handle()
return $this->error('The "public/storage" directory already exists.');
}

if (is_link(public_path('storage'))) {
$this->laravel->make('files')->delete(public_path('storage'));
}

$this->laravel->make('files')->link(
storage_path('app/public'), public_path('storage')
);
Expand Down

0 comments on commit 18daf46

Please sign in to comment.