From: Michael Wallner Date: Mon, 30 Mar 2015 09:25:40 +0000 (+0200) Subject: fix for bug #64343 X-Git-Tag: v3.0.0~5 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=3d815714b67ce0ab66c9e075edf8d0afb82d33ad;p=pharext%2Fpharext fix for bug #64343 --- diff --git a/src/pharext/Packager.php b/src/pharext/Packager.php index 8b7ad22..53fbca2 100644 --- a/src/pharext/Packager.php +++ b/src/pharext/Packager.php @@ -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 index 0000000..ce4c2b5 --- /dev/null +++ b/src/pharext/Task/PaxFixup.php @@ -0,0 +1,42 @@ +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