diff --git a/src/backend/utils.ts b/src/backend/utils.ts index d78d0b29e8..e9a796b1e0 100644 --- a/src/backend/utils.ts +++ b/src/backend/utils.ts @@ -34,7 +34,8 @@ import { GITHUB_API, isMac, configStore, - isLinux + isLinux, + isSnap } from './constants' import { logError, @@ -1348,10 +1349,57 @@ interface ExtractOptions { } async function extractFiles({ path, destination, strip = 0 }: ExtractOptions) { - return decompress(path, destination, { - plugins: [decompressTargz(), decompressTarxz()], - strip - }) + if (!isSnap && (path.endsWith('.tar.xz') || path.endsWith('.tar.gz'))) { + try { + await extractNative(path, destination, strip) + } catch (error) { + logError(`Error: ${error}`, LogPrefix.Backend) + } + } else { + try { + await extractDecompress(path, destination, strip) + } catch (error) { + logError(`Error: ${error}`, LogPrefix.Backend) + } + } +} + +async function extractNative(path: string, destination: string, strip: number) { + logInfo( + `Extracting ${path} to ${destination} using native tar`, + LogPrefix.Backend + ) + const { code, stderr } = await spawnAsync('tar', [ + '-xf', + path, + '-C', + destination, + `--strip-components=${strip}` + ]) + if (code !== 0) { + logError(`Extracting Error: ${stderr}`, LogPrefix.Backend) + return { status: 'error', error: stderr } + } + return { status: 'done', installPath: destination } +} + +async function extractDecompress( + path: string, + destination: string, + strip: number +) { + logInfo( + `Extracting ${path} to ${destination} using decompress`, + LogPrefix.Backend + ) + try { + await decompress(path, destination, { + plugins: [decompressTargz(), decompressTarxz()], + strip + }) + } catch (error) { + logError(`Error: ${error}`, LogPrefix.Backend) + } } export {