Skip to content

Commit 449b5c3

Browse files
authored
Merge pull request #865 from mook-as/mac-update-writable
Build: Ensure that resources are user-writable.
2 parents a4b6b72 + a0d2766 commit 449b5c3

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

scripts/build.mjs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,17 @@ class Builder {
7272
async package() {
7373
console.log('Packaging...');
7474
const args = process.argv.slice(2).filter(x => x !== '--serial');
75+
76+
// Ensure that all files to be packaged are user-writable. This is required
77+
// to correctly support Squirrel.Mac updating.
78+
for await (const [dir, entry] of buildUtils.walk(path.join(buildUtils.srcDir, 'resources'))) {
79+
const stat = await fs.lstat(path.join(dir, entry.name));
80+
81+
if ((stat.mode & 0o200) === 0) {
82+
await fs.chmod(path.join(dir, entry.name), stat.mode | 0o200);
83+
}
84+
}
85+
7586
// On Windows, electron-builder will run the installer to generate the
7687
// uninstall stub; however, we set the installer to be elevated, in order
7788
// to ensure that we can install WSL if necessary. To make it possible to

scripts/lib/build-utils.mjs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,25 @@ export default {
6464
return this.require('babel.config');
6565
},
6666

67+
/**
68+
* Recursively walk a directory, recursively returning the directory entries.
69+
* @param {String} [root] The directory to walk.
70+
* @returns {AsyncGenerator<[string, fs.Dirent], void, unknown>} Directory
71+
* entries and path of their containing folder.
72+
*/
73+
async *walk(root) {
74+
for await (const entry of await fs.promises.opendir(root)) {
75+
if (entry.isSymbolicLink()) {
76+
yield [root, entry];
77+
} else if (entry.isDirectory()) {
78+
yield [root, entry];
79+
yield * this.walk(path.join(root, entry.name));
80+
} else {
81+
yield [root, entry];
82+
}
83+
}
84+
},
85+
6786
/**
6887
* @typedef {Object} ObjectWithProcessChild - Any type holding a child process.
6988
* @property {childProcess.ChildProcess} child - The child process.

0 commit comments

Comments
 (0)