@@ -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 ;
@@ -314,87 +314,46 @@ public function downloadPythonBinary(
314
314
/**
315
315
* @codeCoverageIgnore
316
316
*
317
+ * Compare binary hash from release. If hash not exists return `true` (download anyway)
318
+ *
319
+ * @param string $url
317
320
* @param string $binaryPath
318
- * @param array $binariesFolder,
319
- * @param string $filanem
320
321
*
321
322
* @return bool
322
323
*/
323
- public function compareBinaryHash (
324
- string $ url ,
325
- string $ binaryPath ,
326
- array $ binariesFolder ,
327
- string $ filename
328
- ) {
324
+ public function compareBinaryHash (string $ url , string $ binaryPath ) {
329
325
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 ' ]) {
326
+ $ binaryData = file_get_contents ($ binaryPath );
327
+ $ currentBinaryHash = hash ('sha256 ' , $ binaryData );
328
+ $ newBinaryHash = $ this ->downloadBinaryHash (str_replace ('.gz ' , '.sha256 ' , $ url ));
329
+ if ($ newBinaryHash ['success ' ] && strlen ($ newBinaryHash ['binaryHash ' ]) == 64 ) {
346
330
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
331
}
352
332
}
353
- return false ;
333
+ return true ;
354
334
}
355
335
356
336
/**
357
- * Perform cURL download binary's sha256 sum file
337
+ * Perform cURL to get binary's sha256 sum
358
338
*
359
339
* @codeCoverageIgnore
360
340
*
361
341
* @param string $url url to the binary hashsum file
362
- * @param array $binariesFolder appdata binaries folder
363
- * @param string $filename downloaded checksum filename
364
342
*
365
343
* @return array
366
344
*/
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 ;
345
+ public function downloadBinaryHash (string $ url ): array {
379
346
$ 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 ];
347
+ curl_setopt_array ($ cURL , [
348
+ CURLOPT_RETURNTRANSFER => true ,
349
+ CURLOPT_RANGE => 64 ,
350
+ ]);
351
+ $ binaryHash = curl_exec ($ cURL );
352
+ curl_close ($ cURL );
353
+ return [
354
+ 'success ' => $ binaryHash != false ,
355
+ 'binaryHash ' => $ binaryHash ,
356
+ ];
398
357
}
399
358
400
359
/**
0 commit comments