Skip to content

Commit

Permalink
Properly handle replace situations in storages
Browse files Browse the repository at this point in the history
  • Loading branch information
chEbba committed Oct 27, 2012
1 parent 4b52c30 commit 9d7e52d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/Composer/Storage/ArchiveStorage.php
Expand Up @@ -75,12 +75,12 @@ public function storePackage(PackageInterface $package, $sourceDir)
throw new \RuntimeException('Can not initialize directory structure in ' . $dir);
}

if (file_exists($fileName)) {
@unlink($fileName);
$tempFileName = sys_get_temp_dir().'/'.uniqid(basename($fileName));
$this->compressor->compressDir($sourceDir, $tempFileName);
if (!@rename($tempFileName, $fileName)) {
throw new \RuntimeException(sprintf('Can not rename file from %s to %s.', $tempFileName, $fileName));
}

$this->compressor->compressDir($sourceDir, $fileName);

return $this->createDistribution($fileName);
}

Expand Down
4 changes: 4 additions & 0 deletions src/Composer/Storage/RepositoryStorage.php
Expand Up @@ -71,6 +71,10 @@ public function storePackage(PackageInterface $package, $sourceDir)

$packageCopy = self::convertPackage($package, $dist);

// Remove old package from repository in a replace situation
if ($this->repository->hasPackage($package)) {
$this->repository->removePackage($package);
}
$this->repository->addPackage($packageCopy);
$this->repository->write();

Expand Down

0 comments on commit 9d7e52d

Please sign in to comment.