Skip to content

Commit

Permalink
Merge pull request #865 from mook-as/mac-update-writable
Browse files Browse the repository at this point in the history
Build: Ensure that resources are user-writable.
  • Loading branch information
mattfarina authored Oct 27, 2021
2 parents a4b6b72 + a0d2766 commit 449b5c3
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
11 changes: 11 additions & 0 deletions scripts/build.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,17 @@ class Builder {
async package() {
console.log('Packaging...');
const args = process.argv.slice(2).filter(x => x !== '--serial');

// Ensure that all files to be packaged are user-writable. This is required
// to correctly support Squirrel.Mac updating.
for await (const [dir, entry] of buildUtils.walk(path.join(buildUtils.srcDir, 'resources'))) {
const stat = await fs.lstat(path.join(dir, entry.name));

if ((stat.mode & 0o200) === 0) {
await fs.chmod(path.join(dir, entry.name), stat.mode | 0o200);
}
}

// On Windows, electron-builder will run the installer to generate the
// uninstall stub; however, we set the installer to be elevated, in order
// to ensure that we can install WSL if necessary. To make it possible to
Expand Down
19 changes: 19 additions & 0 deletions scripts/lib/build-utils.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,25 @@ export default {
return this.require('babel.config');
},

/**
* Recursively walk a directory, recursively returning the directory entries.
* @param {String} [root] The directory to walk.
* @returns {AsyncGenerator<[string, fs.Dirent], void, unknown>} Directory
* entries and path of their containing folder.
*/
async *walk(root) {
for await (const entry of await fs.promises.opendir(root)) {
if (entry.isSymbolicLink()) {
yield [root, entry];
} else if (entry.isDirectory()) {
yield [root, entry];
yield * this.walk(path.join(root, entry.name));
} else {
yield [root, entry];
}
}
},

/**
* @typedef {Object} ObjectWithProcessChild - Any type holding a child process.
* @property {childProcess.ChildProcess} child - The child process.
Expand Down

0 comments on commit 449b5c3

Please sign in to comment.