Skip to content

Commit 32c5b7a

Browse files
committed
Fix extraResources
1 parent c416d5a commit 32c5b7a

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

app/electron-client/electron-builder-config.cjs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,27 @@ function engineDistributionTarget(version) {
2222
return 'enso/dist/' + version
2323
}
2424

25+
/**
26+
* electron-builder preserves symlinks in extraResources, but Bazel uses them for sandboxing.
27+
* This function replaces symlinks with real files by copying their targets.
28+
*/
29+
async function replaceSymlinksWithFiles(root) {
30+
const entries = await fs.readdir(root, { withFileTypes: true })
31+
for (const entry of entries) {
32+
const full = path.join(root, entry.name)
33+
const st = await fs.lstat(full)
34+
if (st.isSymbolicLink()) {
35+
const linkTarget = await fs.readlink(full)
36+
const absTarget = path.resolve(path.dirname(full), linkTarget)
37+
const data = await fs.readFile(absTarget)
38+
await fs.unlink(full)
39+
await fs.writeFile(full, data, { mode: st.mode })
40+
} else if (st.isDirectory()) {
41+
await replaceSymlinksWithFiles(full)
42+
}
43+
}
44+
}
45+
2546
/**
2647
* AppImage is known to have sandboxing issues, for example:
2748
* https://github.com/enso-org/enso/issues/3801 or
@@ -151,5 +172,13 @@ module.exports = {
151172
if (context.electronPlatformName === 'linux') {
152173
await patchAppImage(context)
153174
}
175+
176+
const productName = context.packager.appInfo.productFilename
177+
const resourcesDir =
178+
process.platform === 'darwin' ?
179+
path.join(context.appOutDir, `${productName}.app`, 'Contents', 'Resources')
180+
: path.join(context.appOutDir, 'resources')
181+
const ensoDir = path.join(resourcesDir, 'enso')
182+
await replaceSymlinksWithFiles(ensoDir)
154183
},
155184
}

0 commit comments

Comments
 (0)