From 759897e7e855fcac6654c89f40a4283c3d2df1fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Abi=20=D8=A3=D8=A8?= Date: Fri, 28 May 2021 04:07:23 +0700 Subject: [PATCH] Update cache dir on macOS to follow OS guidelines (now $HOME/Library/Caches/Composer) (#9898) Co-authored-by: Jordi Boggiano --- doc/06-config.md | 7 ++++--- src/Composer/Factory.php | 9 +++++++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/doc/06-config.md b/doc/06-config.md index ad350e850..bca15316d 100644 --- a/doc/06-config.md +++ b/doc/06-config.md @@ -213,9 +213,10 @@ versions. See also [COMPOSER_HOME](03-cli.md#composer-home). ## cache-dir Defaults to `C:\Users\\AppData\Local\Composer` on Windows, -`$XDG_CACHE_HOME/composer` on unix systems that follow the XDG Base Directory -Specifications, and `$home/cache` on other unix systems. Stores all the caches -used by Composer. See also [COMPOSER_HOME](03-cli.md#composer-home). +`/Users//Library/Caches/composer` on macOS, `$XDG_CACHE_HOME/composer` +on unix systems that follow the XDG Base Directory Specifications, and +`$home/cache` on other unix systems. Stores all the caches used by Composer. +See also [COMPOSER_HOME](03-cli.md#composer-home). ## cache-files-dir diff --git a/src/Composer/Factory.php b/src/Composer/Factory.php index cd6662c30..aa89f0cf8 100644 --- a/src/Composer/Factory.php +++ b/src/Composer/Factory.php @@ -121,6 +121,15 @@ class Factory } $userDir = self::getUserDir(); + if (PHP_OS === 'Darwin') { + // Migrate existing cache dir in old location if present + if (is_dir($home . '/cache') && !is_dir($userDir . '/Library/Caches/composer')) { + Silencer::call('rename', $home . '/cache', $userDir . '/Library/Caches/composer'); + } + + return $userDir . '/Library/Caches/composer'; + } + if ($home === $userDir . '/.composer' && is_dir($home . '/cache')) { return $home . '/cache'; }