Browse Source

Merge pull request #366 from chrisyue/master

Fix `packagist:dump` throw an exception when `web/packages.json` does not exist
Jordi Boggiano 11 years ago
parent
commit
3ee5ad4214
1 changed files with 12 additions and 7 deletions
  1. 12 7
      src/Packagist/WebBundle/Package/Dumper.php

+ 12 - 7
src/Packagist/WebBundle/Package/Dumper.php

@@ -82,11 +82,11 @@ class Dumper
     /**
      * Constructor
      *
-     * @param RegistryInterface $doctrine
-     * @param Filesystem $filesystem
+     * @param RegistryInterface     $doctrine
+     * @param Filesystem            $filesystem
      * @param UrlGeneratorInterface $router
-     * @param string $webDir web root
-     * @param string $cacheDir cache dir
+     * @param string                $webDir     web root
+     * @param string                $cacheDir   cache dir
      */
     public function __construct(RegistryInterface $doctrine, Filesystem $filesystem, UrlGeneratorInterface $router, $webDir, $cacheDir)
     {
@@ -101,7 +101,7 @@ class Dumper
     /**
      * Dump a set of packages to the web root
      *
-     * @param array $packageIds
+     * @param array   $packageIds
      * @param Boolean $force
      * @param Boolean $verbose
      */
@@ -121,6 +121,7 @@ class Dumper
         } while (is_dir($buildDir) && $retries--);
         if (is_dir($buildDir)) {
             echo 'Could not remove the build dir entirely, aborting';
+
             return false;
         }
         $this->fs->mkdir($buildDir);
@@ -291,8 +292,11 @@ class Dumper
         if (defined('PHP_WINDOWS_VERSION_BUILD')) {
             rename($webDir.'/p/packages.json', $webDir.'/packages.json');
         } else {
-            if (!is_link($webDir.'/packages.json')) {
-                unlink($webDir.'/packages.json');
+            $packagesJsonPath = $webDir.'/packages.json';
+            if (!is_link($packagesJsonPath)) {
+                if (file_exists($packagesJsonPath)) {
+                    unlink($packagesJsonPath);
+                }
                 symlink($webDir.'/p/packages.json', $webDir.'/packages.json');
             }
         }
@@ -408,6 +412,7 @@ class Dumper
     {
         if ($version->isDevelopment()) {
             $distribution = 16;
+
             return 'packages-dev-' . chr(abs(crc32($version->getName())) % $distribution + 97) . '.json';
         }