Skip to content

Commit

Permalink
fix: use native methods unless its snap
Browse files Browse the repository at this point in the history
  • Loading branch information
flavioislima committed Nov 9, 2023
1 parent b6bfb5b commit 953d601
Showing 1 changed file with 53 additions and 5 deletions.
58 changes: 53 additions & 5 deletions src/backend/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ import {
GITHUB_API,
isMac,
configStore,
isLinux
isLinux,
isSnap
} from './constants'
import {
logError,
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 953d601

Please sign in to comment.