@@ -190,8 +190,8 @@ public function isVideosSupported(): bool {
190
190
}
191
191
192
192
public function isMusliLinux (): bool {
193
- exec ('ldd --version ' , $ output , $ result_code );
194
- if ($ result_code == 0 && count ($ output ) > 0 && str_contains ($ output [0 ], 'musl ' )) {
193
+ exec ('ldd --version 2>&1 ' , $ output , $ result_code );
194
+ if (count ($ output ) > 0 && str_contains ($ output [0 ], 'musl ' )) {
195
195
return true ;
196
196
}
197
197
return false ;
@@ -274,9 +274,7 @@ public function downloadPythonBinary(
274
274
}
275
275
$ file_name = $ filename . '.gz ' ;
276
276
$ save_file_loc = $ dir . $ file_name ;
277
- $ shouldDownloadBinary = $ this ->compareBinaryHash (
278
- $ url , $ dir . $ filename , $ binariesFolder , $ filename
279
- );
277
+ $ shouldDownloadBinary = $ this ->compareBinaryHash ($ url , $ dir . $ filename );
280
278
if (!file_exists ($ dir . $ filename ) || ($ update && $ shouldDownloadBinary )) {
281
279
$ cURL = curl_init ($ url );
282
280
$ fp = fopen ($ save_file_loc , 'wb ' );
@@ -314,87 +312,46 @@ public function downloadPythonBinary(
314
312
/**
315
313
* @codeCoverageIgnore
316
314
*
315
+ * Compare binary hash from release. If hash not exists return `true` (download anyway)
316
+ *
317
+ * @param string $url
317
318
* @param string $binaryPath
318
- * @param array $binariesFolder,
319
- * @param string $filanem
320
319
*
321
320
* @return bool
322
321
*/
323
- public function compareBinaryHash (
324
- string $ url ,
325
- string $ binaryPath ,
326
- array $ binariesFolder ,
327
- string $ filename
328
- ) {
322
+ public function compareBinaryHash (string $ url , string $ binaryPath ) {
329
323
if (file_exists ($ binaryPath )) {
330
- // get current binary hash (from .sha256 file or directly from existing binary)
331
- if (file_exists ($ binaryPath . '.sha256 ' )) {
332
- $ currentBinaryHash = file_get_contents (
333
- $ binaryPath . '.sha256 ' , false , null , 0 , 64
334
- );
335
- } else {
336
- $ binaryData = file_get_contents ($ binaryPath );
337
- $ currentBinaryHash = hash ('sha256 ' , $ binaryData );
338
- }
339
- // download new binary sha256 hash from attached file to release
340
- copy ($ binaryPath . '.sha256 ' , $ binaryPath . '.sha256.old ' );
341
- $ newBinaryHash = $ this ->downloadBinaryHash (
342
- str_replace ('.gz ' , '.sha256 ' , $ url ), $ binariesFolder , $ filename
343
- );
344
- // should update binary if hashes not equial
345
- if ($ newBinaryHash ['success ' ]) {
324
+ $ binaryData = file_get_contents ($ binaryPath );
325
+ $ currentBinaryHash = hash ('sha256 ' , $ binaryData );
326
+ $ newBinaryHash = $ this ->downloadBinaryHash (str_replace ('.gz ' , '.sha256 ' , $ url ));
327
+ if ($ newBinaryHash ['success ' ] && strlen ($ newBinaryHash ['binaryHash ' ]) == 64 ) {
346
328
return $ currentBinaryHash != $ newBinaryHash ['binaryHash ' ];
347
- } else {
348
- // revert back old hash file
349
- copy ($ binaryPath . '.sha256.old ' , $ binaryPath . '.sha256 ' );
350
- unlink ($ binaryPath . '.sha256.old ' );
351
329
}
352
330
}
353
- return false ;
331
+ return true ;
354
332
}
355
333
356
334
/**
357
- * Perform cURL download binary's sha256 sum file
335
+ * Perform cURL to get binary's sha256 sum
358
336
*
359
337
* @codeCoverageIgnore
360
338
*
361
339
* @param string $url url to the binary hashsum file
362
- * @param array $binariesFolder appdata binaries folder
363
- * @param string $filename downloaded checksum filename
364
340
*
365
341
* @return array
366
342
*/
367
- public function downloadBinaryHash (
368
- string $ url ,
369
- array $ binariesFolder ,
370
- string $ filename
371
- ): array {
372
- if (isset ($ binariesFolder ['success ' ]) && $ binariesFolder ['success ' ]) {
373
- $ dir = $ binariesFolder ['path ' ] . '/ ' ;
374
- } else {
375
- return $ binariesFolder ; // Return getAppDataFolder result
376
- }
377
- $ file_name = $ filename . '.sha256 ' ;
378
- $ save_file_loc = $ dir . $ file_name ;
343
+ public function downloadBinaryHash (string $ url ): array {
379
344
$ cURL = curl_init ($ url );
380
- $ fp = fopen ($ save_file_loc , 'w ' );
381
- if ($ fp ) {
382
- curl_setopt_array ($ cURL , [
383
- CURLOPT_RETURNTRANSFER => true ,
384
- CURLOPT_FILE => $ fp ,
385
- CURLOPT_FOLLOWLOCATION => true ,
386
- CURLOPT_RANGE => 64 ,
387
- ]);
388
- $ binaryHash = curl_exec ($ cURL );
389
- curl_close ($ cURL );
390
- fclose ($ fp );
391
- return [
392
- 'success ' => true ,
393
- 'binaryHash ' => $ binaryHash ,
394
- 'binaryHashFilePath ' => $ save_file_loc ,
395
- ];
396
- }
397
- return ['success ' => false ];
345
+ curl_setopt_array ($ cURL , [
346
+ CURLOPT_RETURNTRANSFER => true ,
347
+ CURLOPT_RANGE => 64 ,
348
+ ]);
349
+ $ binaryHash = curl_exec ($ cURL );
350
+ curl_close ($ cURL );
351
+ return [
352
+ 'success ' => $ binaryHash != false ,
353
+ 'binaryHash ' => $ binaryHash ,
354
+ ];
398
355
}
399
356
400
357
/**
0 commit comments