fix stream progress notification with resetting bytes_max
[pharext/pharext] / src / pharext / Packager.php
index 9acb5ebc848a229c62a7d0e7c74eec63bcbf13cc..cd1d43681d2d9a1167615c170365175cc3c5c9b4 100644 (file)
@@ -141,18 +141,23 @@ class Packager implements Command
         * @return string local source
         */
        private function download($source) {
-               $this->info("Fetching remote source %s ...\n", $source);
-               
                if ($this->args->git) {
                        $task = new Task\GitClone($source);
                } else {
-                       $task = new Task\StreamFetch($source, function($bytes_pct) {
-                               $this->info(" %3d%% [%s>%s] \r%s",
-                                       floor($bytes_pct*100),
-                                       str_repeat("=", round(50*$bytes_pct)),
-                                       str_repeat(" ", round(50*(1-$bytes_pct))),
-                                       $bytes_pct == 1 ? "\n":""
-                               );
+                       /* print newline only once */
+                       $done = false;
+                       $task = new Task\StreamFetch($source, function($bytes_pct) use(&$done) {
+                               if (!$done) {
+                                       $this->info(" %3d%% [%s>%s] \r",
+                                               floor($bytes_pct*100),
+                                               str_repeat("=", round(50*$bytes_pct)),
+                                               str_repeat(" ", round(50*(1-$bytes_pct)))
+                                       );
+                                       if ($bytes_pct == 1) {
+                                               $done = true;
+                                               printf("\n");
+                                       }
+                               }
                        });
                }
                $local = $task->run($this->verbosity());
@@ -167,10 +172,15 @@ class Packager implements Command
         * @return string extracted directory
         */
        private function extract($source) {
-               $this->debug("Extracting %s ...\n", $source);
-               
-               $task = new Task\Extract($source);
-               $dest = $task->run($this->verbosity());
+               try {
+                       $task = new Task\Extract($source);
+                       $dest = $task->run($this->verbosity());
+               } catch (\Exception $e) {
+                       if (false === strpos($e->getMessage(), "checksum mismatch")) {
+                               throw $e;
+                       }
+                       $dest = (new Task\PaxFixup($source))->run($this->verbosity());
+               }
                
                $this->cleanup[] = new Task\Cleanup($dest);
                return $dest;
@@ -191,8 +201,7 @@ class Packager implements Command
                        $source = $this->extract($source);
                        $this->cleanup[] = new Task\Cleanup($source);
                        
-                       if ($this->args->pecl) {
-                               $this->debug("Sanitizing PECL dir ...\n");
+                       if (!$this->args->git) {
                                $source = (new Task\PeclFixup($source))->run($this->verbosity());
                        }
                }
@@ -211,8 +220,10 @@ class Packager implements Command
                                $this->source = new SourceDir\Pecl($source);
                        } elseif ($this->args["git"]) {
                                $this->source = new SourceDir\Git($source);
-                       } elseif (is_file("$source/parext_package.php")) {
+                       } elseif (is_file("$source/pharext_package.php")) {
                                $this->source = include "$source/pharext_package.php";
+                       } else {
+                               $this->source = new SourceDir\Basic($source);
                        }
 
                        if (!$this->source instanceof SourceDir) {