|
1 | | -import { statOrNull } from "builder-util" |
2 | | -import { Node, readAsar } from "./asar" |
| 1 | +import * as asar from "@electron/asar" |
| 2 | +import { FilesystemEntry, FilesystemFileEntry } from "@electron/asar/lib/filesystem" |
3 | 3 |
|
4 | | -/** @internal */ |
5 | | -export async function checkFileInArchive(asarFile: string, relativeFile: string, messagePrefix: string) { |
| 4 | +export function checkFileInArchive(asarFile: string, relativeFile: string, messagePrefix: string) { |
6 | 5 | function error(text: string) { |
7 | 6 | return new Error(`${messagePrefix} "${relativeFile}" in the "${asarFile}" ${text}`) |
8 | 7 | } |
9 | | - |
10 | | - let fs |
| 8 | + let stat: FilesystemEntry |
11 | 9 | try { |
12 | | - fs = await readAsar(asarFile) |
| 10 | + stat = asar.statFile(asarFile, relativeFile, false) |
13 | 11 | } catch (e: any) { |
14 | | - throw error(`is corrupted: ${e}`) |
15 | | - } |
16 | | - |
17 | | - let stat: Node | null |
18 | | - try { |
19 | | - stat = fs.getFile(relativeFile) |
20 | | - } catch (_e: any) { |
21 | | - const fileStat = await statOrNull(asarFile) |
22 | | - if (fileStat == null) { |
23 | | - throw error(`does not exist. Seems like a wrong configuration.`) |
| 12 | + if (e.message.includes("Cannot read properties of undefined (reading 'link')")) { |
| 13 | + throw error("does not exist. Seems like a wrong configuration.") |
24 | 14 | } |
25 | | - |
26 | | - // asar throws error on access to undefined object (info.link) |
27 | | - stat = null |
28 | | - } |
29 | | - |
30 | | - if (stat == null) { |
31 | | - throw error(`does not exist. Seems like a wrong configuration.`) |
| 15 | + throw error(`is corrupted: ${e}`) |
32 | 16 | } |
33 | | - if (stat.size === 0) { |
| 17 | + if ((stat as FilesystemFileEntry).size === 0) { |
34 | 18 | throw error(`is corrupted: size 0`) |
35 | 19 | } |
| 20 | + return stat |
36 | 21 | } |
0 commit comments