From 082c77586f60772cb53302f3ed16232545bdd375 Mon Sep 17 00:00:00 2001 From: Alexis Svinartchouk Date: Thu, 14 Feb 2019 19:10:32 +0100 Subject: [PATCH] Don't use drivelist directly Use etcher-sdk's drive scanner instead. Change-Type: patch --- .../file-selector/file-selector.jsx | 14 ++++++---- lib/gui/app/models/files.js | 26 +++++-------------- package.json | 1 - 3 files changed, 16 insertions(+), 25 deletions(-) diff --git a/lib/gui/app/components/file-selector/file-selector/file-selector.jsx b/lib/gui/app/components/file-selector/file-selector/file-selector.jsx index e456aa5f..f216c1df 100644 --- a/lib/gui/app/components/file-selector/file-selector/file-selector.jsx +++ b/lib/gui/app/components/file-selector/file-selector/file-selector.jsx @@ -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 }) + } } } diff --git a/lib/gui/app/models/files.js b/lib/gui/app/models/files.js index 81082c26..ceb0a343 100644 --- a/lib/gui/app/models/files.js +++ b/lib/gui/app/models/files.js @@ -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 diff --git a/package.json b/package.json index 5d4c572f..8b7374ee 100644 --- a/package.json +++ b/package.json @@ -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",