fix: throw if attempting to select a locked drive (#512)

We shouldn't allow a write-protected drive from being selected, since
users will get confusing `EPERM` errors later on.

Signed-off-by: Juan Cruz Viotti <jviottidc@gmail.com>
This commit is contained in:
Juan Cruz Viotti 2016-06-23 09:26:23 -04:00 committed by GitHub
parent a93c28ab20
commit e16139af03
2 changed files with 15 additions and 0 deletions

View File

@ -96,6 +96,10 @@ module.exports = redux.createStore(function(state, action) {
throw new Error(`Invalid drive protected state: ${action.data.protected}`);
}
if (action.data.protected) {
throw new Error('The drive is write-protected');
}
// TODO: Reuse from SelectionStateModel.isDriveLargeEnough()
if (state.getIn([ 'selection', 'image', 'size' ], 0) > action.data.size) {
throw new Error('The drive is not large enough');

View File

@ -199,6 +199,17 @@ describe('Browser: SelectionState', function() {
});
});
it('should throw if drive is write protected', function() {
m.chai.expect(function() {
SelectionStateModel.setDrive({
device: '/dev/disk1',
name: 'USB Drive',
size: 999999999,
protected: true
});
}).to.throw('The drive is write-protected');
});
it('should throw if no device', function() {
m.chai.expect(function() {
SelectionStateModel.setDrive({