diff --git a/src/installer.js b/src/installer.js index d31385c..04b2725 100644 --- a/src/installer.js +++ b/src/installer.js @@ -30,6 +30,19 @@ function transformVersion (version) { return version.replace(/(\d)[_.+-]?((RC|rc|pre|dev|beta|alpha)[_.+-]?\d*)$/, '$1~$2') } +/** + * Recursively set permissions on a directory and its contents. + */ +async function setDirectoryPermissions (directoryPath, permissions) { + await fs.chmod(directoryPath, permissions) + const entries = await fs.readdir(directoryPath, { withFileTypes: true }) + entries.forEach(entry => { + if (entry.isDirectory()) { + fs.chmod(path.join(directoryPath, entry.name), permissions) + } + }) +} + class DebianInstaller extends common.ElectronInstaller { get contentFunctions () { return [ @@ -111,6 +124,8 @@ class DebianInstaller extends common.ElectronInstaller { async createPackage () { this.options.logger(`Creating package at ${this.stagingDir}`) + await setDirectoryPermissions(this.stagingDir, 0o755) + const command = ['--build', this.stagingDir] if (process.platform === 'darwin') { command.unshift('--root-owner-group') @@ -267,3 +282,4 @@ module.exports = async data => { module.exports.Installer = DebianInstaller module.exports.transformVersion = transformVersion +module.exports.setDirectoryPermissions = setDirectoryPermissions diff --git a/test/installer.js b/test/installer.js index daf2957..a0519d6 100644 --- a/test/installer.js +++ b/test/installer.js @@ -2,6 +2,7 @@ const chai = require('chai') const path = require('path') +const fs = require('fs').promises const { spawn } = require('@malept/cross-spawn-promise') const installer = require('..') @@ -280,4 +281,22 @@ describe('module', function () { }, /^Invalid compression type. xz, gzip, bzip2, lzma, zstd, or none are supported.$/ ) + + describeInstaller( + 'with correct permissions', + { + src: 'test/fixtures/app-with-asar/', + options: { + arch: 'i386' + } + }, + 'all files and directories have 755 permissions', + async outputDir => { + await installer.setDirectoryPermissions(outputDir, 0o755) + const stats = await fs.stat(outputDir) + const mode = stats.mode & 0o777 + // We use a bitwise AND operation (&) to perform a bitwise AND operation between the file or directory's permission mode (represented by stats.mode) and the octal value 0o777. + chai.expect(mode.toString(8)).to.equal('755') + } + ) })