Skip to content

Commit dfd3445

Browse files
committed
Resolve directories for copy from recipe in update case
1 parent ab0453b commit dfd3445

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

src/Configurator/CopyFromRecipeConfigurator.php

+16
Original file line numberDiff line numberDiff line change
@@ -37,18 +37,34 @@ public function unconfigure(Recipe $recipe, $config, Lock $lock)
3737
public function update(RecipeUpdate $recipeUpdate, array $originalConfig, array $newConfig): void
3838
{
3939
foreach ($recipeUpdate->getOriginalRecipe()->getFiles() as $filename => $data) {
40+
$filename = $this->resolveTargetFolder($filename, $originalConfig);
4041
$recipeUpdate->setOriginalFile($filename, $data['contents']);
4142
}
4243

4344
$files = [];
4445
foreach ($recipeUpdate->getNewRecipe()->getFiles() as $filename => $data) {
46+
$filename = $this->resolveTargetFolder($filename, $newConfig);
4547
$recipeUpdate->setNewFile($filename, $data['contents']);
4648

4749
$files[] = $this->getLocalFilePath($recipeUpdate->getRootDir(), $filename);
4850
}
51+
4952
$recipeUpdate->getLock()->add($recipeUpdate->getPackageName(), ['files' => $files]);
5053
}
5154

55+
/**
56+
* @param array<string, string> $config
57+
*/
58+
private function resolveTargetFolder(string $path, array $config): string {
59+
foreach ($config as $key => $target) {
60+
if (strpos($path, $key) === 0) {
61+
return $this->options->expandTargetDir($target) . substr($path, strlen($key));
62+
}
63+
}
64+
65+
return $path;
66+
}
67+
5268
private function getRemovableFilesFromRecipeAndLock(Recipe $recipe, Lock $lock): array
5369
{
5470
$lockedFiles = array_unique(

tests/Command/UpdateRecipesCommandTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ private function createCommandUpdateRecipes(): CommandTester
100100
$rfs = Factory::createRemoteFilesystem($this->io, $composer->getConfig());
101101
$rfs = new ParallelDownloader($this->io, $composer->getConfig(), $rfs->getOptions(), $rfs->isTlsDisabled());
102102
}
103-
$options = new Options(['root-dir' => FLEX_TEST_DIR]);
103+
$options = new Options(['root-dir' => FLEX_TEST_DIR, 'bin-dir' => 'bin/']);
104104
$command = new UpdateRecipesCommand(
105105
$flex,
106106
new Downloader($composer, $this->io, $rfs),

0 commit comments

Comments
 (0)