Gaufrette icon indicating copy to clipboard operation
Gaufrette copied to clipboard

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

Open balvirsingh opened this issue 10 years ago • 4 comments

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

balvirsingh avatar Dec 26 '14 09:12 balvirsingh

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.

lemoinem avatar Dec 23 '15 18:12 lemoinem

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

akerouanton avatar Jan 19 '16 08:01 akerouanton

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.

thomask avatar Mar 11 '16 21:03 thomask

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

marekstodolny avatar Oct 25 '19 09:10 marekstodolny