Skip to content

Commit

Permalink
Deep sign algorithm update
Browse files Browse the repository at this point in the history
Now to remove `.cstemp` files before code-signing to avoid known issue
  • Loading branch information
sethlu committed Feb 24, 2016
1 parent e40dfd6 commit 2d08347
Showing 1 changed file with 30 additions and 18 deletions.
48 changes: 30 additions & 18 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,17 @@ function flatApplication (opts, callback) {
})
}

function generateAppContentsPath (opts) {
return path.join(opts.app, 'Contents')
}

function generateAppFrameworksPath (opts) {
return path.join(opts.app, 'Contents', 'Frameworks')
return path.join(generateAppContentsPath(opts), 'Frameworks')
}

function signApplication (opts, callback) {
var operations = []
var appFrameworksPath = generateAppFrameworksPath(opts)
var appContentsPath = generateAppContentsPath(opts)

function walkSync (dirPath) {
fs.readdirSync(dirPath).forEach(function (name) {
Expand All @@ -71,45 +75,53 @@ function signApplication (opts, callback) {
if (stat.isFile()) {
switch (path.extname(filePath)) {
case '': // binary
switch (path.basename(filePath)) {
var baseName = path.basename(filePath)
switch (baseName) {
case 'PkgInfo':
case '.DS_Store':
return // ignore
return // ignore files
default:
if (baseName[0] === '.') return // reject hidden files
}
childObjectsPaths.push(filePath) // to be signed (1)
childPaths.push(filePath)
break
case '.dylib': // dynamic library
childObjectsPaths.push(filePath) // to be signed (1)
childPaths.push(filePath)
break
case '.cstemp': // temporary file generated from past codesign
// TODO: Remove before signing
operations.push(function (cb) {
fs.unlink(filePath, (err) => {
if (err) return cb(err)
cb()
})
console.log('Removing...', filePath)
})
break
default:
if (path.extname(filePath).includes(' ')) {
// Still consider the file as binary if extension seems invalid
childObjectsPaths.push(filePath) // to be signed (1)
childPaths.push(filePath)
}
}
} else if (stat.isDirectory() && !stat.isSymbolicLink()) {
switch (path.basename(filePath)) {
case '_CodeSignature':
case 'node_modules':
return // ignore directories
}
walkSync(filePath)
switch (path.extname(filePath)) {
case '.app': // application
childAppsPaths.push(filePath) // to be signed (3)
break
case '.framework': // framework
childFrameworksPaths.push(filePath) // to be signed (2)
childPaths.push(filePath)
break
}
walkSync(filePath)
}
})
}

var childPaths = [], childObjectsPaths = [], childFrameworksPaths = [], childAppsPaths = []
walkSync(appFrameworksPath)
childPaths = childPaths.concat(childObjectsPaths)
var childPaths = []
walkSync(appContentsPath)
if (opts.binaries) childPaths = childPaths.concat(opts.binaries)
childPaths = childPaths.concat(childFrameworksPaths)
childPaths = childPaths.concat(childAppsPaths)

if (opts.entitlements) {
if (opts.platform === 'mas') {
Expand Down

0 comments on commit 2d08347

Please sign in to comment.