fix for bug #64343
authorMichael Wallner <mike@php.net>
Mon, 30 Mar 2015 09:25:40 +0000 (11:25 +0200)
committerMichael Wallner <mike@php.net>
Mon, 30 Mar 2015 09:26:30 +0000 (11:26 +0200)
src/pharext/Packager.php
src/pharext/Task/PaxFixup.php [new file with mode: 0644]

index 8b7ad226ed48de9b15a6458c3a8c7053ea3169b1..53fbca23bc498d67661a797f95cc3232d1ac84b3 100644 (file)
@@ -165,8 +165,15 @@ class Packager implements Command
         * @return string extracted directory
         */
        private function extract($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;
diff --git a/src/pharext/Task/PaxFixup.php b/src/pharext/Task/PaxFixup.php
new file mode 100644 (file)
index 0000000..ce4c2b5
--- /dev/null
@@ -0,0 +1,42 @@
+<?php
+
+namespace pharext\Task;
+
+use pharext\Exception;
+use pharext\Task;
+use pharext\Tempfile;
+
+class PaxFixup implements Task
+{
+       private $source;
+
+       public function __construct($source) {
+               $this->source = $source;
+       }
+
+       private function openArchive($source) {
+               $hdr = file_get_contents($source, false, null, 0, 3);
+               if ($hdr === "\x1f\x8b\x08") {
+                       $fd = fopen("compress.zlib://$source", "r");
+               } elseif ($hdr === "BZh") {
+                       $fd = fopen("compress.bzip2://$source", "r");
+               } else {
+                       $fd = fopen($source, "r");
+               }
+               if (!is_resource($fd)) {
+                       throw new Exception;
+               }
+               return $fd;
+       }
+
+       public function run($verbose = false) {
+               if ($verbose !== false) {
+                       printf("Fixing up a tarball with global pax header ...\n");
+               }
+               $temp = new Tempfile("paxfix");
+               stream_copy_to_stream($this->openArchive($this->source),
+                       $temp->getStream(), -1, 1024);
+               $temp->closeStream();
+               return (new Extract((string) $temp))->run($verbose);
+       }
+}
\ No newline at end of file