mirror of
https://github.com/balena-io/balena-cli.git
synced 2024-12-19 13:47:52 +00:00
Erase MBR before rescanning
This commit is contained in:
parent
8b0ce36955
commit
320981770e
@ -13,6 +13,32 @@ exports.rescanDrives = (callback) ->
|
||||
console.log("DISKPART RESULT: #{arguments}")
|
||||
return callback(error)
|
||||
|
||||
exports.eraseMBR = (devicePath, callback) ->
|
||||
return callback() if not IS_WINDOWS
|
||||
|
||||
bufferSize = 512
|
||||
|
||||
async.waterfall([
|
||||
|
||||
(callback) ->
|
||||
fs.open(devicePath, 'rs+', null, callback)
|
||||
|
||||
(fd, callback) ->
|
||||
buffer = new Buffer(bufferSize)
|
||||
buffer.fill(0)
|
||||
fs.write fd, buffer, 0, bufferSize, 0, (error, bytesWritten) ->
|
||||
return callback(error) if error?
|
||||
return callback(null, bytesWritten, fd)
|
||||
|
||||
(bytesWritten, fd, callback) ->
|
||||
if bytesWritten isnt bufferSize
|
||||
error = "Bytes written: #{bytesWritten}, expected #{bufferSize}"
|
||||
return callback(error)
|
||||
|
||||
fs.close(fd, callback)
|
||||
|
||||
], callback)
|
||||
|
||||
exports.writeImage = (devicePath, imagePath, options = {}, callback = _.noop) ->
|
||||
|
||||
if not fs.existsSync(imagePath)
|
||||
@ -39,6 +65,9 @@ exports.writeImage = (devicePath, imagePath, options = {}, callback = _.noop) ->
|
||||
|
||||
async.waterfall([
|
||||
|
||||
(callback) ->
|
||||
exports.eraseMBR(devicePath, callback)
|
||||
|
||||
(callback) ->
|
||||
exports.rescanDrives(callback)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user