mirror of
https://github.com/balena-io/etcher.git
synced 2025-04-20 05:17:18 +00:00

Etcher currently elevates a child writer proxy that itself spawns the Etcher CLI in robot mode, parses the output, and proxies those messages to the GUI application over IPC. After these set of changes, Etcher elevates a single child writer process that directly communicates back with the GUI using IPC. The main purpose behind these changes is to simplify the overall architecture and fix various issues caused by the current complex child process tree. Here's a summary of the changes: - Stop wrapping the Etcher CLI to perform writing - Remove the robot option from the Etcher CLI (along with related documentation) - Elevate a new `child-write.js` standalone executable - Move the relevant bits of `lib/child-writer` to the `image-writer` GUI module - Remove the `lib/child-writer` directory - Add a new "Child died unexpectedly" Mixpanel event - Floor state percentage in the flash state model The above changes made is possible to tackle all the remaining issues where the writer process would remain alive even if the parent died. Change-Type: patch Changelog-Entry: Ensure the writer process dies when the GUI application is killed. See: https://github.com/resin-io/etcher/pull/1873 See: https://github.com/resin-io/etcher/pull/1843 Signed-off-by: Juan Cruz Viotti <jv@jviotti.com>
116 lines
3.1 KiB
JavaScript
116 lines
3.1 KiB
JavaScript
/*
|
|
* Copyright 2016 resin.io
|
|
*
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License.
|
|
* You may obtain a copy of the License at
|
|
*
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
* See the License for the specific language governing permissions and
|
|
* limitations under the License.
|
|
*/
|
|
|
|
'use strict'
|
|
|
|
const path = require('path')
|
|
const Bluebird = require('bluebird')
|
|
const visuals = require('resin-cli-visuals')
|
|
const form = require('resin-cli-form')
|
|
const writer = require('./writer')
|
|
const utils = require('./utils')
|
|
const options = require('./options')
|
|
const messages = require('../shared/messages')
|
|
const EXIT_CODES = require('../shared/exit-codes')
|
|
const errors = require('../shared/errors')
|
|
const permissions = require('../shared/permissions')
|
|
|
|
const ARGV_IMAGE_PATH_INDEX = 0
|
|
const imagePath = options._[ARGV_IMAGE_PATH_INDEX]
|
|
|
|
permissions.isElevated().then((elevated) => {
|
|
if (!elevated) {
|
|
throw errors.createUserError({
|
|
title: messages.error.elevationRequired(),
|
|
description: 'This tool requires special permissions to write to external drives'
|
|
})
|
|
}
|
|
|
|
return form.run([
|
|
{
|
|
message: 'Select drive',
|
|
type: 'drive',
|
|
name: 'drive'
|
|
},
|
|
{
|
|
message: 'This will erase the selected drive. Are you sure?',
|
|
type: 'confirm',
|
|
name: 'yes',
|
|
default: false
|
|
}
|
|
], {
|
|
override: {
|
|
drive: options.drive,
|
|
|
|
// If `options.yes` is `false`, pass `null`,
|
|
// otherwise the question will not be asked because
|
|
// `false` is a defined value.
|
|
yes: options.yes || null
|
|
|
|
}
|
|
})
|
|
}).then((answers) => {
|
|
if (!answers.yes) {
|
|
throw errors.createUserError({
|
|
title: 'Aborted',
|
|
description: 'We can\'t proceed without confirmation'
|
|
})
|
|
}
|
|
|
|
const progressBars = {
|
|
write: new visuals.Progress('Flashing'),
|
|
check: new visuals.Progress('Validating')
|
|
}
|
|
|
|
return writer.writeImage(imagePath, answers.drive, {
|
|
unmountOnSuccess: options.unmount,
|
|
validateWriteOnSuccess: options.check
|
|
}, (state) => {
|
|
progressBars[state.type].update(state)
|
|
}).then((results) => {
|
|
return {
|
|
imagePath,
|
|
flash: results
|
|
}
|
|
})
|
|
}).then((results) => {
|
|
return Bluebird.try(() => {
|
|
console.log(messages.info.flashComplete({
|
|
drive: results.flash.drive,
|
|
imageBasename: path.basename(results.imagePath)
|
|
}))
|
|
|
|
if (results.flash.checksum.crc32) {
|
|
console.log(`Checksum: ${results.flash.checksum.crc32}`)
|
|
}
|
|
|
|
return Bluebird.resolve()
|
|
}).then(() => {
|
|
process.exit(EXIT_CODES.SUCCESS)
|
|
})
|
|
}).catch((error) => {
|
|
return Bluebird.try(() => {
|
|
utils.printError(error)
|
|
return Bluebird.resolve()
|
|
}).then(() => {
|
|
if (error.code === 'EVALIDATION') {
|
|
process.exit(EXIT_CODES.VALIDATION_ERROR)
|
|
}
|
|
|
|
process.exit(EXIT_CODES.GENERAL_ERROR)
|
|
})
|
|
})
|