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

Create target upfront #112

Merged
merged 6 commits into from
Oct 23, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions lib/appdmg.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,18 @@ module.exports = exports = function (options) {
**/

pipeline.addStep('Looking for target', function (next) {
fs.exists(global.target, function (exists) {
if (exists) {
next(new Error('Target already exists'))
} else {
next(null)
}
fs.writeFile(global.target, '', { flag: 'wx' }, function (err) {
if (err && err.code === 'EEXIST') return next(new Error('Target already exists'))
if (err) return next(err)

pipeline.addCleanupStep('unlink-target', 'Removing target image', function (next, hasErrored) {
if (hasErrored) {
fs.unlink(global.target, next)
} else {
next(null)
}
})
next(null)
})
})

Expand Down
1 change: 1 addition & 0 deletions lib/hdiutil.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ var util = require('./util')
exports.convert = function (source, format, target, cb) {
var args = []
args.push('convert', source)
args.push('-ov')
args.push('-format', format)
args.push('-imagekey', 'zlib-level=9')
args.push('-o', target)
Expand Down
5 changes: 4 additions & 1 deletion lib/pipeline.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ Pipeline.prototype._runStep = function (step, nextAction, cb) {
var next = function (err) {
if (err) {
that._progress({ type: 'step-end', status: 'error' })

that.hasErrored = true

that.runRemainingCleanups(function (err2) {
if (err2) console.error(err2)
cb(err)
Expand Down Expand Up @@ -67,7 +70,7 @@ Pipeline.prototype.runCleanup = function (id, cb) {
delete this.cleanupStore[id]
this.cleanupList.splice(idx, 1)

return fn(cb)
return fn(cb, this.hasErrored)
}

Pipeline.prototype.runRemainingCleanups = function (cb) {
Expand Down
2 changes: 1 addition & 1 deletion test/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ var path = require('path')
var temp = require('fs-temp')
var assert = require('assert')

var STEPS = 21
var STEPS = 22

function runAppdmg (opts, verify, cb) {
var progressCalled = 0
Expand Down