Skip to content

Commit

Permalink
Fixed bug temp zip file writing
Browse files Browse the repository at this point in the history
  • Loading branch information
wdiesveld committed May 8, 2020
1 parent fbcd4ac commit 44aec2e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
Binary file modified bin/tqc.phar
Binary file not shown.
15 changes: 10 additions & 5 deletions src/TinyQueries/Compiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,7 @@ public function compile(array $config, string $apiKey, bool $verbose = false)
}

$zip = new \ZipArchive();
$tag = md5(rand());
$zipFileName = 'upload-' . $tag . '.zip';
$zipFileName = tempnam(sys_get_temp_dir(), 'tq-');

if ($zip->open($zipFileName, \ZipArchive::CREATE)!==true) {
throw new \Exception("Cannot open $zipFileName");
Expand All @@ -143,7 +142,11 @@ public function compile(array $config, string $apiKey, bool $verbose = false)

self::addFolderRecursivelyToZip($zip, $config['compiler']['input']);

$zip->close();
$r = $zip->close();

if ($r !== true) {
throw new \Exception('Could not create zip file for upload ' . $zipFileName);
}

$postBody = [
'tq_code' => curl_file_create(realpath($zipFileName)),
Expand Down Expand Up @@ -197,8 +200,10 @@ public function compile(array $config, string $apiKey, bool $verbose = false)
}

$zip = new \ZipArchive();
$zipFileName = 'download-' . $tag . '.zip';
file_put_contents($zipFileName, $response[1]);
$r = file_put_contents($zipFileName, $response[1]);
if ($r === false) {
throw new \Exception('Error writing downloaded zip ' . $zipFileName);
}
$r = $zip->open($zipFileName);
if ($r !== true) {
throw new \Exception('Error opening ZIP coming from compiler - error code = ' . $r);
Expand Down

0 comments on commit 44aec2e

Please sign in to comment.