Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX-macOS] Wine Downloader fails to extract files #3227

Merged
merged 4 commits into from
Nov 21, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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'))) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if the second condition makes sense here. decompress will also only work with these two file types (since we manually pass the two plugins for them to it)
So something like

if (!path.endsWith('.tar.xz') && !path.endsWith('.tar.gz')) {
  logError(['Unsupported archive:', path], LogPrefix.Backend)
  return
}

if (!isSnap)
// ...

might be more accurate

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it fails if we pass a different archive. I just think this way is safer, but might be too much or not needed like you said.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is safer right now, actually. I doubt those plugins are designed to work with archives not intended for them (and them failing might lead to a crash instead of just an error message, as seen here), so bailing out early should be the safer option

Regardless, as far as I know we currently don't feed other archive formats to this function, so for now this doesn't really matter

try {
await extractNative(path, destination, strip)
} catch (error) {
logError(`Error: ${error}`, LogPrefix.Backend)
flavioislima marked this conversation as resolved.
Show resolved Hide resolved
}
} else {
try {
await extractDecompress(path, destination, strip)
} catch (error) {
logError(`Error: ${error}`, LogPrefix.Backend)
CommandMC marked this conversation as resolved.
Show resolved Hide resolved
}
}
}

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)
CommandMC marked this conversation as resolved.
Show resolved Hide resolved
}
}

export {
Expand Down