Don't use drivelist directly

Use etcher-sdk's drive scanner instead.

Change-Type: patch
This commit is contained in:
Alexis Svinartchouk 2019-02-14 19:10:32 +01:00
parent 3b6fe7b548
commit 082c77586f
3 changed files with 16 additions and 25 deletions

View File

@ -123,11 +123,15 @@ class FileSelector extends React.PureComponent {
files: [],
}
if (props.constraintpath) {
files.getConstraintDevice(props.constraintpath, (error, device) => {
debug('FileSelector:getConstraintDevice', error || device)
this.setState({ constraint: device })
})
}
componentDidMount() {
if (this.props.constraintpath) {
const device = files.getConstraintDevice(this.props.constraintpath)
debug('FileSelector:getConstraintDevice', device)
if (device !== undefined) {
this.setState({ constraint: device.drive })
}
}
}

View File

@ -19,7 +19,8 @@
const Bluebird = require('bluebird')
const fs = Bluebird.promisifyAll(require('fs'))
const path = require('path')
const drivelist = require('drivelist')
const driveScanner = require('../modules/drive-scanner')
/* eslint-disable lodash/prefer-lodash-method */
/* eslint-disable no-undefined */
@ -143,26 +144,13 @@ exports.splitPath = (fullpath, subpaths = []) => {
/**
* @summary Get constraint path device
* @param {String} pathname - device path
* @param {Function} callback - callback(error, constraintDevice)
* @returns {Drive} drive - drive object
* @example
* files.getConstraintDevice('/dev/disk2', (error, device) => {
* // ...
* })
* const device = files.getConstraintDevice('/dev/disk2')
*/
exports.getConstraintDevice = (pathname, callback) => {
drivelist.list((error, devices) => {
if (error) {
callback()
return
}
const constraintDevice = devices.find((device) => {
return device.device === pathname ||
device.devicePath === pathname
})
callback(null, constraintDevice)
})
exports.getConstraintDevice = (pathname) => {
// This supposes the drive scanner is ready
return driveScanner.getBy('device', pathname) || driveScanner.getBy('devicePath', pathname)
}
exports.FileEntry = FileEntry

View File

@ -47,7 +47,6 @@
"command-join": "^2.0.0",
"d3": "^4.13.0",
"debug": "^3.1.0",
"drivelist": "^6.4.2",
"electron-is-running-in-asar": "^1.0.0",
"etcher-sdk": "^1.0.3",
"flexboxgrid": "^6.3.0",