@@ -190,8 +190,8 @@ public function isVideosSupported(): bool {
190190 }
191191
192192 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 ' )) {
195195 return true ;
196196 }
197197 return false ;
@@ -274,9 +274,7 @@ public function downloadPythonBinary(
274274 }
275275 $ file_name = $ filename . '.gz ' ;
276276 $ save_file_loc = $ dir . $ file_name ;
277- $ shouldDownloadBinary = $ this ->compareBinaryHash (
278- $ url , $ dir . $ filename , $ binariesFolder , $ filename
279- );
277+ $ shouldDownloadBinary = $ this ->compareBinaryHash ($ url , $ dir . $ filename );
280278 if (!file_exists ($ dir . $ filename ) || ($ update && $ shouldDownloadBinary )) {
281279 $ cURL = curl_init ($ url );
282280 $ fp = fopen ($ save_file_loc , 'wb ' );
@@ -314,87 +312,46 @@ public function downloadPythonBinary(
314312 /**
315313 * @codeCoverageIgnore
316314 *
315+ * Compare binary hash from release. If hash not exists return `true` (download anyway)
316+ *
317+ * @param string $url
317318 * @param string $binaryPath
318- * @param array $binariesFolder,
319- * @param string $filanem
320319 *
321320 * @return bool
322321 */
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 ) {
329323 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 ) {
346328 return $ currentBinaryHash != $ newBinaryHash ['binaryHash ' ];
347- } else {
348- // revert back old hash file
349- copy ($ binaryPath . '.sha256.old ' , $ binaryPath . '.sha256 ' );
350- unlink ($ binaryPath . '.sha256.old ' );
351329 }
352330 }
353- return false ;
331+ return true ;
354332 }
355333
356334 /**
357- * Perform cURL download binary's sha256 sum file
335+ * Perform cURL to get binary's sha256 sum
358336 *
359337 * @codeCoverageIgnore
360338 *
361339 * @param string $url url to the binary hashsum file
362- * @param array $binariesFolder appdata binaries folder
363- * @param string $filename downloaded checksum filename
364340 *
365341 * @return array
366342 */
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 {
379344 $ 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+ ];
398355 }
399356
400357 /**
0 commit comments