Skip to content

Commit 58b70be

Browse files
committed
Fix log file name escape colon symbol. Fix musllinux detect.
Minor changes in pre-compiled binary hash check
1 parent 997ba5d commit 58b70be

File tree

2 files changed

+25
-66
lines changed

2 files changed

+25
-66
lines changed

lib/Service/PythonService.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,12 +113,12 @@ public function run(
113113
}
114114
if ($nonBlocking) {
115115
if ($binary) {
116-
$logFile = $cwd . 'logs/' . date('d-m-Y_H:i:s', time()) . '.log';
116+
$logFile = $cwd . 'logs/' . date('d-m-Y_H-i-s', time()) . '.log';
117117
} else {
118118
$appDataDir = $this->ncDataFolder . '/appdata_' . $this->ncInstanceId . '/' . $appId . '/';
119119
$pyBitecodeEnvVar = 'PYTHONBYTECODEBASE="' . $appDataDir . '" ';
120120
$envVariables = $pyBitecodeEnvVar . $envVariables;
121-
$logFile = $appDataDir . 'logs/' . date('d-m-Y_H:i:s', time()) . '.log';
121+
$logFile = $appDataDir . 'logs/' . date('d-m-Y_H-i-s', time()) . '.log';
122122
}
123123
$cmd = $envVariables . 'nohup ' . $cmd . ' > ' . $logFile . ' 2>' . $logFile . ' &';
124124
exec($cmd);

lib/Service/UtilsService.php

Lines changed: 23 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -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;
@@ -314,87 +314,46 @@ public function downloadPythonBinary(
314314
/**
315315
* @codeCoverageIgnore
316316
*
317+
* Compare binary hash from release. If hash not exists return `true` (download anyway)
318+
*
319+
* @param string $url
317320
* @param string $binaryPath
318-
* @param array $binariesFolder,
319-
* @param string $filanem
320321
*
321322
* @return bool
322323
*/
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) {
329325
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) {
346330
return $currentBinaryHash != $newBinaryHash['binaryHash'];
347-
} else {
348-
// revert back old hash file
349-
copy($binaryPath . '.sha256.old', $binaryPath . '.sha256');
350-
unlink($binaryPath . '.sha256.old');
351331
}
352332
}
353-
return false;
333+
return true;
354334
}
355335

356336
/**
357-
* Perform cURL download binary's sha256 sum file
337+
* Perform cURL to get binary's sha256 sum
358338
*
359339
* @codeCoverageIgnore
360340
*
361341
* @param string $url url to the binary hashsum file
362-
* @param array $binariesFolder appdata binaries folder
363-
* @param string $filename downloaded checksum filename
364342
*
365343
* @return array
366344
*/
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 {
379346
$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+
];
398357
}
399358

400359
/**

0 commit comments

Comments
 (0)