KnpLabs / Gaufrette

PHP library that provides a filesystem abstraction layer − will be a feast for your files!
http://knplabs.github.io/Gaufrette
MIT License
2.47k stars 355 forks source link

Could not remove the "default/0001/01/70d43d74fb22538adbdc981eb6b6e3e4b318dca6.png" key. #318

Open balvirsingh opened 9 years ago

balvirsingh commented 9 years ago

Hi,

In my project we are using this bundle for some file uploading functionality, I dont have much knowledge about this, before it was working fine but I am facing this error. When I update new image then it works fine but when update same image with new upload again then this error come. I tried to solve it but unable to find the issue.

please help to resolve this issue.

Could not remove the "default/0001/01/70d43d74fb22538adbdc981eb6b6e3e4b318dca6.png" key.

I saw it gives exception from this file. /vendor/knplabs/gaufrette/src/Gaufrette/Filesystem.php

/**
 * Deletes the file matching the specified key
 *
 * @param string $key
 * @throws \RuntimeException when cannot read file
 *
 * @return boolean
 */
public function delete($key)
{
    $this->assertHasFile($key);

    if ($this->adapter->delete($key)) {
        return true;
    }

    throw new \RuntimeException(sprintf('Could not remove the "%s" key.', $key));
}

snapshot332

lemoinem commented 8 years ago

Hello,

This issue has been a year old already...

I really think we shouldn't throw an exception if a file we want to delete doesn't exist. It already doesn't exist, so everything's fine.

Do you think we could replace the $this->assertHasFile($key); by if (!$this->has($key)) { return true; }?

I'm ready to submit a PR.

akerouanton commented 8 years ago

Hello @balvirsingh, @lemoinem,

Sorry for the very late response on this issue. Can you provide more details please ? Which adapters do you use ? Do you have the same problem with another adapter ? It would be awesome if you provide a snippet reproducing the bug.

Thanks

thomask commented 8 years ago

Have been running into this issue as well. Without having had time to investigate the issue, my hunch is that this happens when using the cache adapter and deleting a file that hasn't been cached locally yet. I hope I'll have some time to investigate this over the weekend.

marekstodolny commented 5 years ago

Hey, any updates on this? I have this issue when using a remote filesystem with a local cache.

It looks like it tries to remove a file that wasn't cached - and also throws a very generic RuntimeException:

https://github.com/KnpLabs/Gaufrette/blob/2216a72aa72b2fe1581bd521381f1247e9ceae9d/src/Gaufrette/Filesystem.php#L145

My reasoning is that there is nothing that checks if cache is set. In case of a local cache the fact that a file exists is equivalent to a cache entry. If so, then any failure due to a file being not accessible should be treated as non-fatal.

Configuration looks like this:

knp_gaufrette:
    stream_wrapper: ~
    adapters:
        homepage_images_cache:
            cache:
                source: homepage_images_adapter__s3
                cache: homepage_images_adapter__local
                ttl: 7200
        homepage_images_adapter__s3:
            aws_s3:
                service_id: 'app.aws_s3.client'
                bucket_name: "%env(resolve:AWS_S3_BUCKET)%"
                detect_content_type: true