Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: dpkg-deb: error: control directory has bad permissions 756 (must… #347

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/installer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 [
Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -267,3 +282,4 @@ module.exports = async data => {

module.exports.Installer = DebianInstaller
module.exports.transformVersion = transformVersion
module.exports.setDirectoryPermissions = setDirectoryPermissions
19 changes: 19 additions & 0 deletions test/installer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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('..')
Expand Down Expand Up @@ -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')
}
)
})