1
0
Fork 0

Fix create-project regression when using path repos with relative paths, fixes #12150

pull/12178/head
Jordi Boggiano 2024-10-28 15:37:13 +01:00
parent fa5b361f34
commit e12cfa0c40
No known key found for this signature in database
2 changed files with 10 additions and 7 deletions

View File

@ -424,21 +424,16 @@ EOT
throw new \InvalidArgumentException($errorMessage .'.'); throw new \InvalidArgumentException($errorMessage .'.');
} }
$oldCwd = Platform::getCwd();
// handler Ctrl+C aborts gracefully // handler Ctrl+C aborts gracefully
@mkdir($directory, 0777, true); @mkdir($directory, 0777, true);
if (false !== ($realDir = realpath($directory))) { if (false !== ($realDir = realpath($directory))) {
$signalHandler = SignalHandler::create([SignalHandler::SIGINT, SignalHandler::SIGTERM, SignalHandler::SIGHUP], function (string $signal, SignalHandler $handler) use ($realDir, $oldCwd) { $signalHandler = SignalHandler::create([SignalHandler::SIGINT, SignalHandler::SIGTERM, SignalHandler::SIGHUP], function (string $signal, SignalHandler $handler) use ($realDir) {
chdir($oldCwd);
$this->getIO()->writeError('Received '.$signal.', aborting', true, IOInterface::DEBUG); $this->getIO()->writeError('Received '.$signal.', aborting', true, IOInterface::DEBUG);
$fs = new Filesystem(); $fs = new Filesystem();
$fs->removeDirectory($realDir); $fs->removeDirectory($realDir);
$handler->exitWithLastSignal(); $handler->exitWithLastSignal();
}); });
} }
if (!chdir($directory)) {
throw new \RuntimeException('Failed to chdir into the new project dir at '.$directory);
}
// avoid displaying 9999999-dev as version if default-branch was selected // avoid displaying 9999999-dev as version if default-branch was selected
if ($package instanceof AliasPackage && $package->getPrettyVersion() === VersionParser::DEFAULT_BRANCH_ALIAS) { if ($package instanceof AliasPackage && $package->getPrettyVersion() === VersionParser::DEFAULT_BRANCH_ALIAS) {
@ -472,6 +467,7 @@ EOT
$installedFromVcs = 'source' === $package->getInstallationSource(); $installedFromVcs = 'source' === $package->getInstallationSource();
$io->writeError('<info>Created project in ' . $directory . '</info>'); $io->writeError('<info>Created project in ' . $directory . '</info>');
chdir($directory);
// ensure that the env var being set does not interfere with create-project // ensure that the env var being set does not interfere with create-project
// as it is probably not meant to be used here, so we do not use it if a composer.json can be found // as it is probably not meant to be used here, so we do not use it if a composer.json can be found

View File

@ -350,7 +350,14 @@ class FileDownloader implements DownloaderInterface, ChangeReportInterface
$this->io->writeError(" - " . InstallOperation::format($package)); $this->io->writeError(" - " . InstallOperation::format($package));
} }
$this->filesystem->emptyDirectory($path); $vendorDir = $this->config->get('vendor-dir');
// clean up the target directory, unless it contains the vendor dir, as the vendor dir contains
// the file to be installed. This is the case when installing with create-project in the current directory
// but in that case we ensure the directory is empty already in ProjectInstaller so no need to empty it here.
if (false === strpos($this->filesystem->normalizePath($vendorDir), $this->filesystem->normalizePath($path.DIRECTORY_SEPARATOR))) {
$this->filesystem->emptyDirectory($path);
}
$this->filesystem->ensureDirectoryExists($path); $this->filesystem->ensureDirectoryExists($path);
$this->filesystem->rename($this->getFileName($package, $path), $path . '/' . $this->getDistPath($package, PATHINFO_BASENAME)); $this->filesystem->rename($this->getFileName($package, $path), $path . '/' . $this->getDistPath($package, PATHINFO_BASENAME));