Skip to content

Commit

Permalink
Fix create-project regression when using path repos with relative pat…
Browse files Browse the repository at this point in the history
…hs, fixes #12150
  • Loading branch information
Seldaek committed Oct 28, 2024
1 parent fa5b361 commit e12cfa0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
8 changes: 2 additions & 6 deletions src/Composer/Command/CreateProjectCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -424,21 +424,16 @@ protected function installRootPackage(InputInterface $input, IOInterface $io, Co
throw new \InvalidArgumentException($errorMessage .'.');
}

$oldCwd = Platform::getCwd();
// handler Ctrl+C aborts gracefully
@mkdir($directory, 0777, true);
if (false !== ($realDir = realpath($directory))) {
$signalHandler = SignalHandler::create([SignalHandler::SIGINT, SignalHandler::SIGTERM, SignalHandler::SIGHUP], function (string $signal, SignalHandler $handler) use ($realDir, $oldCwd) {
chdir($oldCwd);
$signalHandler = SignalHandler::create([SignalHandler::SIGINT, SignalHandler::SIGTERM, SignalHandler::SIGHUP], function (string $signal, SignalHandler $handler) use ($realDir) {
$this->getIO()->writeError('Received '.$signal.', aborting', true, IOInterface::DEBUG);
$fs = new Filesystem();
$fs->removeDirectory($realDir);
$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
if ($package instanceof AliasPackage && $package->getPrettyVersion() === VersionParser::DEFAULT_BRANCH_ALIAS) {
Expand Down Expand Up @@ -472,6 +467,7 @@ protected function installRootPackage(InputInterface $input, IOInterface $io, Co
$installedFromVcs = 'source' === $package->getInstallationSource();

$io->writeError('<info>Created project in ' . $directory . '</info>');
chdir($directory);

// 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
Expand Down
9 changes: 8 additions & 1 deletion src/Composer/Downloader/FileDownloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,14 @@ public function install(PackageInterface $package, string $path, bool $output =
$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->rename($this->getFileName($package, $path), $path . '/' . $this->getDistPath($package, PATHINFO_BASENAME));

Expand Down

0 comments on commit e12cfa0

Please sign in to comment.