diff --git a/CHANGELOG.md b/CHANGELOG.md
index 733de9b7e..e76593076 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,6 +1,6 @@
### [2.2.15] 2022-07-01
- * Fixed support for read-only caches where the filesystem is not writable (#10906)
+ * Fixed support for `cache-read-only` where the filesystem is not writable (#10906)
* Fixed type error when using `allow-plugins: true` (#10909)
* Fixed @putenv scripts receiving arguments passed to the command (#10846)
* Fixed support for spaces in paths with binary proxies on Windows (#10836)
diff --git a/src/Composer/Cache.php b/src/Composer/Cache.php
index 1390e09b1..61ae44f82 100644
--- a/src/Composer/Cache.php
+++ b/src/Composer/Cache.php
@@ -104,7 +104,7 @@ class Cache
|| !is_writable($this->root)
)
) {
- $this->io->writeError('Cannot create cache directory ' . $this->root . ', or directory is not writable. Proceeding without cache');
+ $this->io->writeError('Cannot create cache directory ' . $this->root . ', or directory is not writable. Proceeding without cache. See also cache-read-only config if your filesystem is read-only.');
$this->enabled = false;
}
}
@@ -265,7 +265,7 @@ class Cache
*/
public function remove($file)
{
- if ($this->isEnabled()) {
+ if ($this->isEnabled() && !$this->readOnly) {
$file = Preg::replace('{[^'.$this->allowlist.']}i', '-', $file);
if (file_exists($this->root . $file)) {
return $this->filesystem->unlink($this->root . $file);
@@ -280,7 +280,7 @@ class Cache
*/
public function clear()
{
- if ($this->isEnabled()) {
+ if ($this->isEnabled() && !$this->readOnly) {
$this->filesystem->emptyDirectory($this->root);
return true;
@@ -314,7 +314,7 @@ class Cache
*/
public function gc($ttl, $maxSize)
{
- if ($this->isEnabled()) {
+ if ($this->isEnabled() && !$this->readOnly) {
$expire = new \DateTime();
$expire->modify('-'.$ttl.' seconds');