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

Storage::delete does not return accurate result #15142

Closed
thunberg opened this issue Aug 30, 2016 · 3 comments
Closed

Storage::delete does not return accurate result #15142

thunberg opened this issue Aug 30, 2016 · 3 comments

Comments

@thunberg
Copy link

Storage::delete with the local driver always returns true:

    public function delete($paths)
    {
        $paths = is_array($paths) ? $paths : func_get_args();

        foreach ($paths as $path) {
            try {
                $this->driver->delete($path);
            } catch (FileNotFoundException $e) {
                //
            }
        }

        return true;
    }

This is not helpful when attempting to first confirm an object's associated file upload was successfully deleted before deleting the object itself.

Since the local filesystem driver already returns the correct result:

    public function delete($path)
    {
        $location = $this->applyPathPrefix($path);

        return unlink($location);
    }

Why can't we change the delete function in FilesystemAdapter to:

    public function delete($paths)
    {
        $paths = is_array($paths) ? $paths : func_get_args();

        $success = true;

        foreach ($paths as $path) {
            try {
                $success = $this->driver->delete($path);
            } catch (FileNotFoundException $e) {
                $success = false;
            }
        }

        return $success;
    }

I'm relatively new to Laravel, so apologies if I've missed a more appropriate way to handle this -- thank you either way.

@srmklive
Copy link
Contributor

I would suggest that you do it like this:

if ($this->driver->has($path)) {
    $this->driver->delete($path);
}

@thunberg
Copy link
Author

Thank you for the reply, but that doesn't handle the case when a delete fails.

@thunberg
Copy link
Author

thunberg commented Sep 7, 2016

Thank you for the fix.

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

No branches or pull requests

3 participants