@@ -34,7 +34,8 @@ import {
34
34
GITHUB_API ,
35
35
isMac ,
36
36
configStore ,
37
- isLinux
37
+ isLinux ,
38
+ isSnap
38
39
} from './constants'
39
40
import {
40
41
logError ,
@@ -1348,10 +1349,57 @@ interface ExtractOptions {
1348
1349
}
1349
1350
1350
1351
async function extractFiles ( { path, destination, strip = 0 } : ExtractOptions ) {
1351
- return decompress ( path , destination , {
1352
- plugins : [ decompressTargz ( ) , decompressTarxz ( ) ] ,
1353
- strip
1354
- } )
1352
+ if ( ! isSnap && ( path . endsWith ( '.tar.xz' ) || path . endsWith ( '.tar.gz' ) ) ) {
1353
+ try {
1354
+ await extractNative ( path , destination , strip )
1355
+ } catch ( error ) {
1356
+ logError ( [ 'Error:' , error ] , LogPrefix . Backend )
1357
+ }
1358
+ } else {
1359
+ try {
1360
+ await extractDecompress ( path , destination , strip )
1361
+ } catch ( error ) {
1362
+ logError ( [ 'Error:' , error ] , LogPrefix . Backend )
1363
+ }
1364
+ }
1365
+ }
1366
+
1367
+ async function extractNative ( path : string , destination : string , strip : number ) {
1368
+ logInfo (
1369
+ `Extracting ${ path } to ${ destination } using native tar` ,
1370
+ LogPrefix . Backend
1371
+ )
1372
+ const { code, stderr } = await spawnAsync ( 'tar' , [
1373
+ '-xf' ,
1374
+ path ,
1375
+ '-C' ,
1376
+ destination ,
1377
+ `--strip-components=${ strip } `
1378
+ ] )
1379
+ if ( code !== 0 ) {
1380
+ logError ( `Extracting Error: ${ stderr } ` , LogPrefix . Backend )
1381
+ return { status : 'error' , error : stderr }
1382
+ }
1383
+ return { status : 'done' , installPath : destination }
1384
+ }
1385
+
1386
+ async function extractDecompress (
1387
+ path : string ,
1388
+ destination : string ,
1389
+ strip : number
1390
+ ) {
1391
+ logInfo (
1392
+ `Extracting ${ path } to ${ destination } using decompress` ,
1393
+ LogPrefix . Backend
1394
+ )
1395
+ try {
1396
+ await decompress ( path , destination , {
1397
+ plugins : [ decompressTargz ( ) , decompressTarxz ( ) ] ,
1398
+ strip
1399
+ } )
1400
+ } catch ( error ) {
1401
+ logError ( [ 'Error:' , error ] , LogPrefix . Backend )
1402
+ }
1355
1403
}
1356
1404
1357
1405
export {
0 commit comments