thephpleague / flysystem

Abstraction for local and remote filesystems

Home Page:https://flysystem.thephpleague.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

The Flysystem delete() method always returns true

jjdevzinho opened this issue · comments

Bug in the delete() method

Description

The Flysystem delete() method always returns true, even if the file does not exist or the user does not have permission to delete it.

Reproduction

$file = "/path/to/file";

Storage::disk('s3')->delete($file);
Environment
PHP: 8.0
Laravel: 9.0
Flysystem: 3.0

This is by design, the method is responsible for ensuring it's deleted. If there are competing processes that both delete a file, having it already be gone is totally fine. It also prevents a call, which is good for performance. If you want to know if there was a file, check for file existence. The library optimises for performance instead of theoretical correctness in this case, or rather is declarative rather than imperative in how it executes.

This is by design, the method is responsible for ensuring it's deleted. If there are competing processes that both delete a file, having it already be gone is totally fine. It also prevents a call, which is good for performance. If you want to know if there was a file, check for file existence. The library optimises for performance instead of theoretical correctness in this case, or rather is declarative rather than imperative in how it executes.

Hi,

Thanks for the response.

I now understand that the behavior of always returning true is intentional. I understand the reason for optimizing for performance, but I still find it strange that the delete() method does not return false in some cases, such as when the file does not exist or the user does not have permission to delete it.

I would also like to point out that the current behavior of the delete() method is not clear to developers. It took me a while to notice that the method performs a file existence check before attempting to delete it.

This could lead to errors if the developer is not aware of the method's behavior. For example, the developer may assume that the file was deleted successfully, when in fact it is still present on the server.

It may be possible to improve the clarity of the delete() method's behavior by adding more detailed documentation or a warning in the code.

Thank you again for your time and attention.

@jjdevzinho you're describing Laravel behaviour, Flysystem's delete method returns void.