Skip to content

Commit 9a12eda

Browse files
committed
Fix issue #608: patching fails when --no-cache is passed
1 parent c7d82a4 commit 9a12eda

File tree

3 files changed

+52
-1
lines changed

3 files changed

+52
-1
lines changed

src/Downloader.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,16 @@ public function __construct(Composer $composer, IOInterface $io, array $disabled
2626
$this->io = $io;
2727
$this->disabledDownloaders = $disabledDownloaders;
2828

29-
$this->cacheDir = $composer->getConfig()->get('cache-dir') . '/patches';
29+
// If --no-cache is passed to Composer, we need a different location to
30+
// download patches to. When --no-cache is passed, $composer_cache is
31+
// set to /dev/null.
32+
$composer_cache = $composer->getConfig()->get('cache-dir');
33+
if (!is_dir($composer_cache)) {
34+
$composer_cache = sys_get_temp_dir();
35+
}
36+
37+
// If the cache directory doesn't exist, create it.
38+
$this->cacheDir = $composer_cache . '/patches';
3039
if (!is_dir($this->cacheDir)) {
3140
mkdir($this->cacheDir);
3241
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"name": "cweagans/composer-patches-test-project",
3+
"description": "Project for use in cweagans/composer-patches acceptance tests.",
4+
"type": "project",
5+
"license": "BSD-3-Clause",
6+
"repositories": [
7+
{
8+
"type": "path",
9+
"url": "../../../../"
10+
}
11+
],
12+
"require": {
13+
"cweagans/composer-patches": "*@dev",
14+
"cweagans/composer-patches-testrepo": "~1.0"
15+
},
16+
"extra": {
17+
"patches": {
18+
"cweagans/composer-patches-testrepo": {
19+
"Add a file": "https://patch-diff.githubusercontent.com/raw/cweagans/composer-patches-testrepo/pull/1.patch"
20+
}
21+
}
22+
},
23+
"config": {
24+
"preferred-install": "source",
25+
"allow-plugins": {
26+
"cweagans/composer-patches": true
27+
}
28+
}
29+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
/**
4+
* @var \Codeception\Scenario $scenario
5+
*/
6+
7+
use cweagans\Composer\Tests\AcceptanceTester;
8+
9+
$I = new AcceptanceTester($scenario);
10+
$I->wantTo('modify a package using a patch downloaded from the internet (with "composer --no-cache")');
11+
$I->amInPath(codecept_data_dir('fixtures/apply-git-patch-from-web-no-cache'));
12+
$I->runComposerCommand('install', ['-vvv', '--no-cache']);
13+
$I->canSeeFileFound('./vendor/cweagans/composer-patches-testrepo/src/OneMoreTest.php');

0 commit comments

Comments
 (0)