Skip to content

Commit

Permalink
Avoid emptying the directory before extracting an archive into it, ch…
Browse files Browse the repository at this point in the history
…eck that it is empty instead
  • Loading branch information
Seldaek committed Mar 28, 2020
1 parent 6679dde commit 7325169
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/Composer/Downloader/ArchiveDownloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ public function install(PackageInterface $package, $path, $output = true)
$this->io->writeError('Extracting archive', false);
}

$this->filesystem->emptyDirectory($path);
$this->filesystem->ensureDirectoryExists($path);
if (!$this->filesystem->isDirEmpty($path)) {
throw new \RuntimeException('Expected empty path to extract '.$package.' into but directory exists: '.$path);
}

$temporaryDir = $this->config->get('vendor-dir').'/composer/'.substr(md5(uniqid('', true)), 0, 8);
$fileName = $this->getFileName($package, $path);
Expand Down

1 comment on commit 7325169

@Seldaek
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In Composer 2, custom installers extending from LibraryInstaller should be aware that it MAY return PromiseInterface instances when calling parent::install/update/uninstall/installCode/removeCode. Update your plugin code to look like the above to handle this correctly.

Please sign in to comment.