Skip to content

Commit

Permalink
bug #779 do not try to write a cache entry if there is no cache key (…
Browse files Browse the repository at this point in the history
…themasch)

This PR was merged into the 1.13-dev branch.

Discussion
----------

do not try to write a cache entry if there is no cache key

Writing to the cache with an empty key will fail with "failed to open stream: Is a directory", so do not try to do that.

We noticed this when cloudflare - or the backend service - responded with a "last-modified" header for our CI servers (AWS) but not for our local system. This triggered the condition to become true and it tries to write a cache file without a filename.

I hope this is the correct place to fix it, but from what I see, this code should not try to write a cache with am empty key, correct?

Here is how a `composer install` failed for us (because of this?):
```
  [ErrorException]
  file_put_contents(/tmp/composer/cache/repo/https---flex.symfony.com/): failed to open stream: Is a directory
```

Commits
-------

e4bb94d do not write a cache entry if there is no cache key
  • Loading branch information
fabpot committed Aug 3, 2021
2 parents 2597d0d + e4bb94d commit d81196c
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/Downloader.php
Expand Up @@ -293,7 +293,7 @@ private function parseJson(string $json, string $url, string $cacheKey, array $l
}

$response = new Response($data, $lastHeaders);
if ($response->getHeader('last-modified')) {
if ($response->getHeader('last-modified') && $cacheKey) {
$this->cache->write($cacheKey, json_encode($response));
}

Expand Down

0 comments on commit d81196c

Please sign in to comment.