Skip to content

Commit

Permalink
Merge pull request #728 from particle-iot/bug/sc-127227/support-renam…
Browse files Browse the repository at this point in the history
…ed-assets

Fix the asset check code
  • Loading branch information
monkbroc committed Apr 15, 2024
2 parents 79046f7 + d88bb6a commit 58e52f2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 19 deletions.
15 changes: 8 additions & 7 deletions src/lib/flash-helper.js
Expand Up @@ -66,6 +66,12 @@ async function _flashDeviceInNormalMode(device, data, { name, progress, checkSki
}
return device;
}
try {
await device.enterListeningMode();
await delay(1000); // Just in case
} catch (error) {
// ignore
}
await device.updateFirmware(data, { progress, timeout: FLASH_TIMEOUT });
return device;
} catch (error) {
Expand All @@ -90,12 +96,6 @@ async function prepareDeviceForFlash({ device, mode, progress }) {
}
device = await usbUtils.reopenInNormalMode(device, { reset: true });
}
try {
await device.enterListeningMode();
await delay(1000); // Just in case
} catch (error) {
// ignore
}
break;
case 'dfu':
if (!device.isInDfuMode) {
Expand Down Expand Up @@ -332,8 +332,9 @@ async function createFlashSteps({ modules, isInDfuMode, factory, platformId }) {
}

function _skipAsset(module, existingAssets) {
const name = path.basename(module.filename);
const hashAssetToBeFlashed = _get256Hash(module);
return existingAssets.some((asset) => hashAssetToBeFlashed === asset.hash && module.filename === asset.name);
return existingAssets.some((asset) => hashAssetToBeFlashed === asset.hash && name === asset.name);
}

function _get256Hash(module) {
Expand Down
16 changes: 4 additions & 12 deletions src/lib/flash-helper.test.js
Expand Up @@ -416,60 +416,52 @@ describe('flash-helper', () => {
const device = {
isOpen: true,
isInDfuMode: true,
close: sinon.stub(),
enterListeningMode: sinon.stub()
close: sinon.stub()
};
reopenInNormalStub.resolves(device);
reopenStub.resolves(device);
await prepareDeviceForFlash({ device, mode: 'normal' });
expect(reopenStub).to.have.been.calledOnce;
expect(reopenInNormalStub).to.have.been.calledOnce;
expect(reopenInDfuModeStub).to.not.have.been.called;
expect(device.enterListeningMode).to.have.been.calledOnce;
});
it('prepares the device when is required for normal mode and currently is in normal mode', async () => {
const device = {
isOpen: true,
isInDfuMode: false,
close: sinon.stub(),
enterListeningMode: sinon.stub()
close: sinon.stub()
};

reopenStub.resolves(device);
await prepareDeviceForFlash({ device, mode: 'normal' });
expect(reopenStub).to.have.been.calledOnce;
expect(reopenInNormalStub).to.not.have.been.called;
expect(reopenInDfuModeStub).to.not.have.been.called;
expect(device.enterListeningMode).to.have.been.calledOnce;
});
it('prepares the device when is required for dfu mode and currently is in normal mode', async () => {
const device = {
isOpen: true,
isInDfuMode: false,
close: sinon.stub(),
enterListeningMode: sinon.stub()
close: sinon.stub()
};

reopenStub.resolves(device);
await prepareDeviceForFlash({ device, mode: 'dfu' });
expect(reopenStub).to.have.been.calledOnce;
expect(reopenInDfuModeStub).to.have.been.calledOnce;
expect(reopenInNormalStub).to.not.have.been.called;
expect(device.enterListeningMode).to.not.have.been.called;
});
it('prepares the device when is required for dfu mode and currently is in dfu mode', async () => {
const device = {
isOpen: true,
isInDfuMode: true,
close: sinon.stub(),
enterListeningMode: sinon.stub()
close: sinon.stub()
};
reopenStub.resolves(device);
await prepareDeviceForFlash({ device, mode: 'dfu' });
expect(reopenStub).to.have.been.calledOnce;
expect(reopenInDfuModeStub).to.not.have.been.called;
expect(reopenInNormalStub).to.not.have.been.called;
expect(device.enterListeningMode).to.not.have.been.called;
});
});

Expand Down

0 comments on commit 58e52f2

Please sign in to comment.