How to get rid of Composer error mkdir(): Not a directory when using param --no-cache with some dependencies?

Viewed 1473

Composer with param --no-cache error mkdir(): Not a directory, installing hirak/prestissimo for accelerating instalation

[ErrorException] mkdir(): Not a directory
1 Answers

It's somehow a standard behavior due to composer documentation --no-cache "Disables the use of the cache directory. Same as setting the COMPOSER_CACHE_DIR env var to /dev/null", prestissimo relies on composer cache dir even when it's run with no cache, and I debugged it via composer github source code, and it failed at prestissimo class in root CopyRequest.php method createDir, line 103

 private function createDir($fileName)
    {
        $targetdir = dirname($fileName);
        if (!file_exists($targetdir)) {
            if (!mkdir($targetdir, 0775, true)) {
                throw new FetchException(
                    'The file could not be written to ' . $fileName
                );
            }
        }
    }

target dir is in case of supplying --no-cache param set to '/dev/null/something/long/path' perhaps composer --debug option would give more trace info, maybe not

Conclusion:

Even when I reverted back to the old composer.lock I got the same error in Yii 1, getting framework from the cache, maybe a span of minor versions is gotten from the cache, so I wanted to see if clearing cache would get the correct state from history as reverting even with cache to the past did not seem to help - one might say not cached version should be the same as the cached one, but to be completely sure (not always every developer increases version with every commit - moreover on Bamboo CI artifact reverting de facto clearing cache helped), furthermore with cache parallel downloading with prestissimo has no usage.

So in order to remove or bypass composer cache, I had to manually erase it via linux command line erasing global composer cache directory.

The bug is mentioned in prestissimo library https://github.com/hirak/prestissimo/issues/199

Other workaround: composer clear-cache

Related