Merge pull request #2631 from balena-io/dont-use-drivelist-directly

Dont use drivelist directly
This commit is contained in:
Alexis Svinartchouk 2019-02-15 14:16:41 +01:00 committed by GitHub
commit b1ab3834b6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 31 additions and 61 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

49
npm-shrinkwrap.json generated
View File

@ -4530,13 +4530,12 @@
"dev": true
},
"drivelist": {
"version": "6.4.6",
"resolved": "https://registry.npmjs.org/drivelist/-/drivelist-6.4.6.tgz",
"integrity": "sha512-FVeQE8GQppabnXm5J3tz3+nNZUWBixLYl2jGuLnCI/LhpopOj6+/fvPMgaWXC/SW/gceVALCx/EBRk8HiXqB5w==",
"version": "7.0.1",
"resolved": "https://registry.npmjs.org/drivelist/-/drivelist-7.0.1.tgz",
"integrity": "sha512-p5f4sLknSMpg923Vj1xBlxj3uzaKTAOFy7ywkGXFD5+yp8aWd0aAPgTSD7ns/EPUCjTMEGKsdqw34/fjwwT0oQ==",
"requires": {
"bindings": "^1.3.0",
"debug": "^3.1.0",
"fast-plist": "^0.1.2",
"nan": "^2.10.0",
"prebuild-install": "^4.0.0"
}
@ -5840,16 +5839,16 @@
"integrity": "sha1-Cr9PHKpbyx96nYrMbepPqqBLrJs="
},
"etcher-sdk": {
"version": "1.0.6",
"resolved": "https://registry.npmjs.org/etcher-sdk/-/etcher-sdk-1.0.6.tgz",
"integrity": "sha512-SbuA68pBEQqOiW/v2SzV+yor4XZT+RjV9oXlg3nv8ekoKw8tkCTnpdvjjLPbo7MUC0vzElqaujBIcMFURx4gWQ==",
"version": "1.0.7",
"resolved": "https://registry.npmjs.org/etcher-sdk/-/etcher-sdk-1.0.7.tgz",
"integrity": "sha512-1c0vGKcktGdtTUVVZZpkRxdZkj6ftoA6vbabAUR2EgSwQfQhkX/tF7yarI86pIgSZoPSxDsOG2gDMWFzHj1lTw==",
"requires": {
"@types/node": "^6.0.112",
"axios": "^0.18.0",
"blockmap": "^3.4.2",
"bluebird": "^3.5.1",
"debug": "^3.1.0",
"drivelist": "^6.4.2",
"drivelist": "^7.0.1",
"file-disk": "^5.0.0",
"file-type": "^8.0.0",
"lodash": "^4.17.10",
@ -6231,11 +6230,6 @@
"integrity": "sha1-PYpcZog6FqMMqGQ+hR8Zuqd5eRc=",
"dev": true
},
"fast-plist": {
"version": "0.1.2",
"resolved": "https://registry.npmjs.org/fast-plist/-/fast-plist-0.1.2.tgz",
"integrity": "sha1-pFr/NFGWAG1AbKbNzQX2kFHvNbg="
},
"fastparse": {
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/fastparse/-/fastparse-1.1.2.tgz",
@ -6442,26 +6436,11 @@
}
},
"follow-redirects": {
"version": "1.6.1",
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.6.1.tgz",
"integrity": "sha512-t2JCjbzxQpWvbhts3l6SH1DKzSrx8a+SsaVf4h6bG4kOXUuPYS/kg2Lr4gQSb7eemaHqJkOThF1BGyjlUkO1GQ==",
"version": "1.7.0",
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.7.0.tgz",
"integrity": "sha512-m/pZQy4Gj287eNy94nivy5wchN3Kp+Q5WgUPNy5lJSZ3sgkVKSYV/ZChMAQVIgx1SqfZ2zBZtPA2YlXIWxxJOQ==",
"requires": {
"debug": "=3.1.0"
},
"dependencies": {
"debug": {
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/debug/-/debug-3.1.0.tgz",
"integrity": "sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g==",
"requires": {
"ms": "2.0.0"
}
},
"ms": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz",
"integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g="
}
"debug": "^3.2.6"
}
},
"for-in": {
@ -9377,9 +9356,9 @@
}
},
"node-abi": {
"version": "2.7.0",
"resolved": "https://registry.npmjs.org/node-abi/-/node-abi-2.7.0.tgz",
"integrity": "sha512-egTtvNoZLMjwxkL/5iiJKYKZgn2im0zP+G+PncMxICYGiD3aZtXUvEsDmu0pF8gpASvLZyD8v53qi1/ELaRZpg==",
"version": "2.7.1",
"resolved": "https://registry.npmjs.org/node-abi/-/node-abi-2.7.1.tgz",
"integrity": "sha512-OV8Bq1OrPh6z+Y4dqwo05HqrRL9YNF7QVMRfq1/pguwKLG+q9UB/Lk0x5qXjO23JjJg+/jqCHSTaG1P3tfKfuw==",
"requires": {
"semver": "^5.4.1"
}

View File

@ -47,9 +47,8 @@
"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",
"etcher-sdk": "^1.0.7",
"flexboxgrid": "^6.3.0",
"immutable": "^3.8.1",
"inactivity-timer": "^1.0.0",