Skip to content

Commit c3e9ccc

Browse files
[FIX-macOS] Wine Downloader fails to extract files (#3227)
* fix: use native methods unless its snap * Update src/backend/utils.ts Co-authored-by: Mathis Dröge <[email protected]> * chore: pr comments --------- Co-authored-by: Flavio F Lima <[email protected]> Co-authored-by: Mathis Dröge <[email protected]>
1 parent 6b430d8 commit c3e9ccc

File tree

1 file changed

+53
-5
lines changed

1 file changed

+53
-5
lines changed

src/backend/utils.ts

Lines changed: 53 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ import {
3434
GITHUB_API,
3535
isMac,
3636
configStore,
37-
isLinux
37+
isLinux,
38+
isSnap
3839
} from './constants'
3940
import {
4041
logError,
@@ -1348,10 +1349,57 @@ interface ExtractOptions {
13481349
}
13491350

13501351
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+
}
13551403
}
13561404

13571405
export {

0 commit comments

Comments
 (0)