diff --git a/lib/cli/writer.js b/lib/cli/writer.js index 164a0a41..f8a966bd 100644 --- a/lib/cli/writer.js +++ b/lib/cli/writer.js @@ -25,6 +25,13 @@ const imageStream = require('../image-stream'); const errors = require('../shared/errors'); const constraints = require('../shared/drive-constraints'); +/** + * @summary Timeout, in milliseconds, to wait before unmounting on success + * @constant + * @type {Number} + */ +const UNMOUNT_ON_SUCCESS_TIMEOUT_MS = 2000; + /** * @summary Write an image to a disk drive * @function @@ -108,7 +115,14 @@ exports.writeImage = (imagePath, drive, options, onProgress) => { return Bluebird.resolve(); } - return mountutils.unmountDiskAsync(drive.device); + // Closing a file descriptor on a drive containing mountable + // partitions causes macOS to mount the drive. If we try to + // unmount to quickly, then the drive might get re-mounted + // right afterwards. + return Bluebird.delay(UNMOUNT_ON_SUCCESS_TIMEOUT_MS) + .return(drive.device) + .then(mountutils.unmountDiskAsync); + }); }); });