Skip to content

Commit dccfe97

Browse files
authored
Use internal OC TAR to unpack archive (#107)
* Use internal OC TAR to unpack archive * Fix Psalm * Fix psalm errors (replace str_contains to strpos function, available in PHP7)
1 parent 39e85eb commit dccfe97

File tree

2 files changed

+8
-13
lines changed

2 files changed

+8
-13
lines changed

lib/Service/UtilsService.php

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
namespace OCA\Cloud_Py_API\Service;
3030

3131
use bantu\IniGetWrapper\IniGetWrapper;
32+
use OC\Archive\TAR;
3233
use OCP\IConfig;
3334
use OCP\App\IAppManager;
3435

@@ -197,7 +198,7 @@ public function isVideosSupported(): bool {
197198

198199
public function isMuslLinux(): bool {
199200
exec('ldd --version 2>&1', $output, $result_code);
200-
if (count($output) > 0 && str_contains($output[0], 'musl')) {
201+
if (count($output) > 0 && strpos($output[0], 'musl') !== false) {
201202
return true;
202203
}
203204
return false;
@@ -209,11 +210,11 @@ public function isMuslLinux(): bool {
209210
public function getOsArch(): string {
210211
$arm64_names = ["aarch64", "armv8", "arm64"];
211212
$machineType = php_uname('m');
212-
if (str_contains($machineType, 'x86_64')) {
213+
if (strpos($machineType, 'x86_64') !== false) {
213214
return 'amd64';
214215
}
215216
foreach ($arm64_names as $arm64_name) {
216-
if (str_contains($machineType, $arm64_name)) {
217+
if (strpos($machineType, $arm64_name) !== false) {
217218
return 'arm64';
218219
}
219220
}
@@ -408,12 +409,10 @@ public function unTarGz(array $binariesFolder, string $src_filename): array {
408409
if (isset($binariesFolder['success']) && $binariesFolder['success']) {
409410
$dir = $binariesFolder['path'] . '/';
410411
$src_file = $dir . $src_filename;
411-
$phar = new \PharData($src_file);
412-
$extracted = $phar->extractTo($dir, null, true);
413-
$filename = $phar->getFilename();
412+
$archive = new TAR($src_file);
413+
$extracted = $archive->extract($dir);
414414
return [
415415
'extracted' => $extracted,
416-
'filename' => $filename
417416
];
418417
}
419418
return [

tests/psalm-baseline.xml

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,18 +37,14 @@
3737
<RedundantCondition occurrences="1">
3838
<code>isset($setting)</code>
3939
</RedundantCondition>
40-
<UndefinedClass occurrences="1">
40+
<UndefinedClass occurrences="2">
4141
<code>?DatabaseStatistics</code>
42+
<code>TAR</code>
4243
</UndefinedClass>
4344
<UndefinedDocblockClass occurrences="2">
4445
<code>$this-&gt;databaseStatistics</code>
4546
<code>DatabaseStatistics</code>
4647
</UndefinedDocblockClass>
47-
<UndefinedFunction occurrences="3">
48-
<code>str_contains($machineType, $arm64_name)</code>
49-
<code>str_contains($machineType, 'x86_64')</code>
50-
<code>str_contains($output[0], 'musl')</code>
51-
</UndefinedFunction>
5248
<UndefinedMagicMethod occurrences="4">
5349
<code>getValue</code>
5450
<code>getValue</code>

0 commit comments

Comments
 (0)