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
Changes from 1 commit
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
16 changes: 8 additions & 8 deletions lib/appdmg.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,14 @@ module.exports = exports = function (options) {
fs.writeFile(global.target, '', { flag: 'wx' }, function (err) {
if (err && err.code === 'EEXIST') return next(new Error('Target already exists'))

pipeline.addCleanupStep('unlink-target', 'Removing target image', function (next, hasErrored) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

err could potentially be non-null here in which case the file won't exists. Maybe add if (err) return next(err) before?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually, it might be that if fs.writeFile returns an err, we do not know if the file is there or not. In that case we should always unlink it, but ignore any ENOENT errors...

Not super important to get this done now though, if you're short on time 👍

if (hasErrored) {
fs.unlink(global.target, next)
} else {
next(null)
}
})

next(err)
})
})
Expand Down Expand Up @@ -409,14 +417,6 @@ module.exports = exports = function (options) {
**/

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

var format = global.opts.format || 'UDZO'

hdiutil.convert(global.temporaryImagePath, format, global.target, next)
Expand Down