mirror of
https://github.com/balena-io/etcher.git
synced 2025-07-24 03:36:36 +00:00
Pass the whole drive object to the writer
Currently we only pass the drive device. By passing all the object (containing the mountpoint, size, etc) we allow more control to the writer in how to treat the device before/during/after the burning process.
This commit is contained in:
parent
d0d384fb6f
commit
a6ec66d0b3
@ -65,7 +65,7 @@ app.controller('AppController', function($q, DriveScannerService, SelectionState
|
||||
|
||||
this.selectDrive = function(drive) {
|
||||
self.selection.setDrive(drive);
|
||||
console.debug('Drive selected: ' + drive);
|
||||
console.debug('Drive selected: ' + drive.device);
|
||||
};
|
||||
|
||||
this.platform = window.process.platform;
|
||||
@ -76,7 +76,7 @@ app.controller('AppController', function($q, DriveScannerService, SelectionState
|
||||
// otherwise Windows throws EPERM
|
||||
self.scanner.stop();
|
||||
|
||||
console.debug('Burning ' + image + ' to ' + drive);
|
||||
console.debug('Burning ' + image + ' to ' + drive.device);
|
||||
return self.writer.burn(image, drive).then(function() {
|
||||
console.debug('Done!');
|
||||
});
|
||||
@ -371,13 +371,15 @@ imageWriter.service('ImageWriterService', function($q, $timeout) {
|
||||
* This function is extracted for testing purposes.
|
||||
*
|
||||
* @param {String} image - image path
|
||||
* @param {String} drive - drive device
|
||||
* @param {Object} drive - drive
|
||||
* @param {Function} onProgress - in progress callback (state)
|
||||
*
|
||||
* @returns {Promise}
|
||||
*
|
||||
* @example
|
||||
* ImageWriter.performWrite('path/to/image.img', '/dev/disk2', function(state) {
|
||||
* ImageWriter.performWrite('path/to/image.img', {
|
||||
* device: '/dev/disk2'
|
||||
* }, function(state) {
|
||||
* console.log(state.percentage);
|
||||
* });
|
||||
*/
|
||||
@ -394,12 +396,14 @@ imageWriter.service('ImageWriterService', function($q, $timeout) {
|
||||
* This function will update `.progress` with the current writing percentage.
|
||||
*
|
||||
* @param {String} image - image path
|
||||
* @param {String} drive - drive device
|
||||
* @param {Object} drive - drive
|
||||
*
|
||||
* @returns {Promise}
|
||||
*
|
||||
* @example
|
||||
* ImageWriterService.burn('foo.img', '/dev/disk').then(function() {
|
||||
* ImageWriterService.burn('foo.img', {
|
||||
* device: '/dev/disk2'
|
||||
* }).then(function() {
|
||||
* console.log('Write completed!');
|
||||
* });
|
||||
*/
|
||||
@ -520,10 +524,12 @@ selectionState.service('SelectionStateService', function() {
|
||||
* @function
|
||||
* @public
|
||||
*
|
||||
* @param {String} drive - drive
|
||||
* @param {Object} drive - drive
|
||||
*
|
||||
* @example
|
||||
* SelectionStateService.setDrive('/dev/disk2');
|
||||
* SelectionStateService.setDrive({
|
||||
* device: '/dev/disk2'
|
||||
* });
|
||||
*/
|
||||
this.setDrive = function(drive) {
|
||||
selection.drive = drive;
|
||||
@ -548,7 +554,7 @@ selectionState.service('SelectionStateService', function() {
|
||||
* @function
|
||||
* @public
|
||||
*
|
||||
* @returns {String} drive
|
||||
* @returns {Object} drive
|
||||
*
|
||||
* @example
|
||||
* var drive = SelectionStateService.getDrive();
|
||||
|
@ -64,7 +64,7 @@ app.controller('AppController', function($q, DriveScannerService, SelectionState
|
||||
|
||||
this.selectDrive = function(drive) {
|
||||
self.selection.setDrive(drive);
|
||||
console.debug('Drive selected: ' + drive);
|
||||
console.debug('Drive selected: ' + drive.device);
|
||||
};
|
||||
|
||||
this.platform = window.process.platform;
|
||||
@ -75,7 +75,7 @@ app.controller('AppController', function($q, DriveScannerService, SelectionState
|
||||
// otherwise Windows throws EPERM
|
||||
self.scanner.stop();
|
||||
|
||||
console.debug('Burning ' + image + ' to ' + drive);
|
||||
console.debug('Burning ' + image + ' to ' + drive.device);
|
||||
return self.writer.burn(image, drive).then(function() {
|
||||
console.debug('Done!');
|
||||
});
|
||||
|
@ -108,13 +108,15 @@ imageWriter.service('ImageWriterService', function($q, $timeout) {
|
||||
* This function is extracted for testing purposes.
|
||||
*
|
||||
* @param {String} image - image path
|
||||
* @param {String} drive - drive device
|
||||
* @param {Object} drive - drive
|
||||
* @param {Function} onProgress - in progress callback (state)
|
||||
*
|
||||
* @returns {Promise}
|
||||
*
|
||||
* @example
|
||||
* ImageWriter.performWrite('path/to/image.img', '/dev/disk2', function(state) {
|
||||
* ImageWriter.performWrite('path/to/image.img', {
|
||||
* device: '/dev/disk2'
|
||||
* }, function(state) {
|
||||
* console.log(state.percentage);
|
||||
* });
|
||||
*/
|
||||
@ -131,12 +133,14 @@ imageWriter.service('ImageWriterService', function($q, $timeout) {
|
||||
* This function will update `.progress` with the current writing percentage.
|
||||
*
|
||||
* @param {String} image - image path
|
||||
* @param {String} drive - drive device
|
||||
* @param {Object} drive - drive
|
||||
*
|
||||
* @returns {Promise}
|
||||
*
|
||||
* @example
|
||||
* ImageWriterService.burn('foo.img', '/dev/disk').then(function() {
|
||||
* ImageWriterService.burn('foo.img', {
|
||||
* device: '/dev/disk2'
|
||||
* }).then(function() {
|
||||
* console.log('Write completed!');
|
||||
* });
|
||||
*/
|
||||
|
@ -45,10 +45,12 @@ selectionState.service('SelectionStateService', function() {
|
||||
* @function
|
||||
* @public
|
||||
*
|
||||
* @param {String} drive - drive
|
||||
* @param {Object} drive - drive
|
||||
*
|
||||
* @example
|
||||
* SelectionStateService.setDrive('/dev/disk2');
|
||||
* SelectionStateService.setDrive({
|
||||
* device: '/dev/disk2'
|
||||
* });
|
||||
*/
|
||||
this.setDrive = function(drive) {
|
||||
selection.drive = drive;
|
||||
@ -73,7 +75,7 @@ selectionState.service('SelectionStateService', function() {
|
||||
* @function
|
||||
* @public
|
||||
*
|
||||
* @returns {String} drive
|
||||
* @returns {Object} drive
|
||||
*
|
||||
* @example
|
||||
* var drive = SelectionStateService.getDrive();
|
||||
|
@ -54,7 +54,7 @@
|
||||
|
||||
<ul class="dropdown-menu">
|
||||
<li ng-repeat="drive in app.scanner.drives">
|
||||
<a href="#" ng-click="app.selectDrive(drive.device)">
|
||||
<a href="#" ng-click="app.selectDrive(drive)">
|
||||
|
||||
<!-- Show drive letter instead of phsycal drive name on Windows -->
|
||||
<span ng-if="app.platform == 'win32'">Drive {{ drive.mountpoint }}\ - {{ drive.size }}</span>
|
||||
@ -72,7 +72,7 @@
|
||||
|
||||
</div>
|
||||
<div ng-show="app.selection.hasDrive()">
|
||||
<span>{{ app.selection.getDrive() }}</span>
|
||||
<span>{{ app.selection.getDrive().device }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -59,13 +59,15 @@ exports.getImageStream = function(image) {
|
||||
* about the `state` object passed to `onProgress` callback.
|
||||
*
|
||||
* @param {String} image - path to image
|
||||
* @param {String} drive - drive device
|
||||
* @param {Object} drive - drive
|
||||
* @param {Function} onProgress - on progress callback (state)
|
||||
*
|
||||
* @returns {Promise}
|
||||
*
|
||||
* @example
|
||||
* writer.writeImage('path/to/image.img', '/dev/disk2', function(state) {
|
||||
* writer.writeImage('path/to/image.img', {
|
||||
* device: '/dev/disk2'
|
||||
* }, function(state) {
|
||||
* console.log(state.percentage);
|
||||
* }).then(function() {
|
||||
* console.log('Done!');
|
||||
@ -74,9 +76,9 @@ exports.getImageStream = function(image) {
|
||||
exports.writeImage = function(image, drive, onProgress) {
|
||||
'use strict';
|
||||
|
||||
return umount.umountAsync(drive).then(function() {
|
||||
return umount.umountAsync(drive.device).then(function() {
|
||||
var stream = exports.getImageStream(image);
|
||||
return imageWrite.write(drive, stream);
|
||||
return imageWrite.write(drive.device, stream);
|
||||
}).then(function(writer) {
|
||||
return new Promise(function(resolve, reject) {
|
||||
writer.on('progress', onProgress);
|
||||
@ -84,6 +86,6 @@ exports.writeImage = function(image, drive, onProgress) {
|
||||
writer.on('done', resolve);
|
||||
});
|
||||
}).then(function() {
|
||||
return umount.umountAsync(drive);
|
||||
return umount.umountAsync(drive.device);
|
||||
});
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user