Skip to content

Commit 319f785

Browse files
bug #551 Compare paths by their realpath when checking locks (leongersen)
This PR was squashed before being merged into the 1.8-dev branch. Discussion ---------- Compare paths by their realpath when checking locks Use `realpath` to compare locked files before removal. Fixes #513 To test: ``` composer create-project symfony/skeleton example cd example/vendor/symfony/ rm -rf flex git clone https://github.com/leongersen/flex --branch issue-513 --single-branch cd ../../ composer require symfony/test-pack composer remove symfony/test-pack ``` Commits ------- 9ac4a0a Compare paths by their realpath when checking locks
2 parents 1abe394 + 9ac4a0a commit 319f785

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

src/Configurator/CopyFromRecipeConfigurator.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,12 @@ function (array $carry, array $package) {
4646
);
4747

4848
$removableFiles = $recipe->getFiles();
49-
foreach ($lockedFiles as $file) {
50-
if (isset($removableFiles[$file])) {
49+
50+
$lockedFiles = array_map('realpath', $lockedFiles);
51+
52+
// Compare file paths by their real path to abstract OS differences
53+
foreach (array_keys($removableFiles) as $file) {
54+
if (\in_array(realpath($file), $lockedFiles)) {
5155
unset($removableFiles[$file]);
5256
}
5357
}

tests/Configurator/CopyFromRecipeConfiguratorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ public function testUnconfigureKeepsLockedFiles()
104104
$this->assertFileExists($this->sourceFile);
105105

106106
$lock = new Lock(FLEX_TEST_DIR.'/test.lock');
107-
$lock->set('other-recipe', ['files' => [$this->targetFileRelativePath]]);
107+
$lock->set('other-recipe', ['files' => ['./'.$this->targetFileRelativePath]]);
108108

109109
$this->createConfigurator()->unconfigure($this->recipe, [$this->targetFileRelativePath], $lock);
110110

0 commit comments

Comments
 (0)