Skip to content

Conversation

@pgrenaud
Copy link
Contributor

@pgrenaud pgrenaud commented Mar 4, 2021

This PR attempt to fix an issue that occur when the storage link already exists but is somehow broken. By "broken", I mean link that point to a non-existing target.

When running the storage:link command, we get an error message and the link is not updated.

$ php artisan storage:link

In Filesystem.php line 263:
                                        
  symlink(): No such file or directory  
                                        

To fix this issue, we add an additional check to detect and delete broken links when running the storage:link command.

Implementation details

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.

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.
@driesvints
Copy link
Member

@pgrenaud can you send this to 6.x instead please? Thanks

@driesvints driesvints closed this Mar 4, 2021
@pgrenaud
Copy link
Contributor Author

pgrenaud commented Mar 4, 2021

Ok! I have created #36470.

Note that this new patch wont apply easily on 8.x since features were added in the StorageLinkCommand class.

@driesvints
Copy link
Member

Okay, I'm re-opening this one as well so we can have the proper fix for 8.x as well. We'll handle the merge conflicts.

@driesvints driesvints reopened this Mar 4, 2021
@driesvints driesvints changed the title Delete existing links that are broken [8.x] Delete existing links that are broken Mar 4, 2021
@taylorotwell taylorotwell merged commit 1e19a56 into laravel:8.x Mar 5, 2021
@pgrenaud pgrenaud deleted the bugfix/remove-dead-symlinks branch May 21, 2021 15:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants