Sort devices by device path on Linux

Changelog-entry: Sort devices by device path on Linux
Change-type: patch
This commit is contained in:
Alexis Svinartchouk 2020-01-31 13:04:21 +01:00
parent 571a3533fb
commit c09237f0c3

View File

@ -124,7 +124,7 @@ function storeReducer(
}); });
} }
const drives = action.data; let drives = action.data;
if (!_.isArray(drives) || !_.every(drives, _.isObject)) { if (!_.isArray(drives) || !_.every(drives, _.isObject)) {
throw errors.createError({ throw errors.createError({
@ -132,6 +132,13 @@ function storeReducer(
}); });
} }
drives = _.sortBy(drives, [
// Devices with no devicePath first (usbboot)
d => !!d.devicePath,
// Then sort by devicePath (only available on Linux with udev) or device
d => d.devicePath || d.device,
]);
const newState = state.set('availableDrives', Immutable.fromJS(drives)); const newState = state.set('availableDrives', Immutable.fromJS(drives));
const selectedDevices = newState.getIn(['selection', 'devices']).toJS(); const selectedDevices = newState.getIn(['selection', 'devices']).toJS();