From c3e9cccfc7e12e58d19840ca33ec273fde90673e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fl=C3=A1vio=20Fearn?= <26871415+flavioislima@users.noreply.github.com> Date: Tue, 21 Nov 2023 20:59:17 +0000 Subject: [PATCH] [FIX-macOS] Wine Downloader fails to extract files (#3227) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: use native methods unless its snap * Update src/backend/utils.ts Co-authored-by: Mathis Dröge * chore: pr comments --------- Co-authored-by: Flavio F Lima Co-authored-by: Mathis Dröge --- src/backend/utils.ts | 58 ++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 53 insertions(+), 5 deletions(-) diff --git a/src/backend/utils.ts b/src/backend/utils.ts index d78d0b29e8..ae64a96e02 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 {