Update etcher-sdk to use direct IO

Changelog-entry: Update etcher-sdk to use direct IO
Change-type: patch
This commit is contained in:
Alexis Svinartchouk 2020-04-01 13:54:57 +02:00
parent 7c4f4cacc9
commit 7eddb16f2f
5 changed files with 137 additions and 89 deletions

View File

@ -220,10 +220,9 @@ export class ImageSelector extends React.Component<
return;
}
const source = new sdk.sourceDestination.File(
imagePath,
sdk.sourceDestination.File.OpenFlags.Read,
);
const source = new sdk.sourceDestination.File({
path: imagePath,
});
try {
const innerSource = await source.getInnerSource();
const metadata = (await innerSource.getMetadata()) as sdk.sourceDestination.Metadata & {

View File

@ -27,7 +27,7 @@ function includeSystemDrives() {
}
const adapters: sdk.scanner.adapters.Adapter[] = [
new sdk.scanner.adapters.BlockDeviceAdapter(includeSystemDrives),
new sdk.scanner.adapters.BlockDeviceAdapter({ includeSystemDrives }),
];
// Can't use permissions.isElevated() here as it returns a promise and we need to set

View File

@ -98,12 +98,11 @@ async function writeAndValidate(
let innerSource: sdk.sourceDestination.SourceDestination = await source.getInnerSource();
if (trim && (await innerSource.canRead())) {
// @ts-ignore FIXME: ts thinks that SparseReadStream can't be assigned to SparseReadable (which it implements)
innerSource = new sdk.sourceDestination.ConfiguredSource(
innerSource,
trim,
// Create stream from file-disk (not source stream)
true,
);
innerSource = new sdk.sourceDestination.ConfiguredSource({
source: innerSource,
shouldTrimPartitions: trim,
createStreamFromDisk: true,
});
}
const {
failures,
@ -115,6 +114,7 @@ async function writeAndValidate(
onFail,
onProgress,
verify,
32,
);
const result: WriteResult = {
bytesWritten,
@ -125,8 +125,9 @@ async function writeAndValidate(
errors: [],
};
for (const [destination, error] of failures) {
(error as Error & { device: string }).device = destination.drive.device;
result.errors.push(error);
const err = error as Error & { device: string };
err.device = (destination as sdk.sourceDestination.BlockDevice).device;
result.errors.push(err);
}
return result;
}
@ -218,15 +219,16 @@ ipc.connectTo(IPC_SERVER_ID, () => {
log(`Validate on success: ${options.validateWriteOnSuccess}`);
log(`Trim: ${options.trim}`);
const dests = _.map(options.destinations, destination => {
return new sdk.sourceDestination.BlockDevice(
destination,
options.unmountOnSuccess,
);
return new sdk.sourceDestination.BlockDevice({
drive: destination,
unmountOnSuccess: options.unmountOnSuccess,
write: true,
direct: true,
});
});
const source = new sdk.sourceDestination.File({
path: options.imagePath,
});
const source = new sdk.sourceDestination.File(
options.imagePath,
sdk.sourceDestination.File.OpenFlags.Read,
);
try {
const results = await writeAndValidate(
// @ts-ignore FIXME: ts thinks that SparseWriteStream can't be assigned to SparseWritable (which it implements)

181
npm-shrinkwrap.json generated
View File

@ -343,6 +343,19 @@
"fastq": "^1.6.0"
}
},
"@ronomon/direct-io": {
"version": "3.0.1",
"resolved": "https://registry.npmjs.org/@ronomon/direct-io/-/direct-io-3.0.1.tgz",
"integrity": "sha512-NkKB32bjq7RfMdAMiWayphMlVWzsfPiKelK+btXLqggv1vDVgv2xELqeo0z4uYLLt86fVReLPxQj7qpg0zWvow==",
"requires": {
"@ronomon/queue": "^3.0.1"
}
},
"@ronomon/queue": {
"version": "3.0.1",
"resolved": "https://registry.npmjs.org/@ronomon/queue/-/queue-3.0.1.tgz",
"integrity": "sha512-STcqSvk+c7ArMrZgYxhM92p6O6F7t0SUbGr+zm8s9fJple5EdJAMwP3dXqgdXeF95xWhBpha5kjEqNAIdI0r4w=="
},
"@samverschueren/stream-to-observable": {
"version": "0.3.0",
"resolved": "https://registry.npmjs.org/@samverschueren/stream-to-observable/-/stream-to-observable-0.3.0.tgz",
@ -1840,17 +1853,28 @@
}
},
"bl": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/bl/-/bl-3.0.0.tgz",
"integrity": "sha512-EUAyP5UHU5hxF8BPT0LKW8gjYLhq1DQIcneOX/pL/m2Alo+OYDQAJlHq+yseMP50Os2nHXOSic6Ss3vSQeyf4A==",
"version": "4.0.2",
"resolved": "https://registry.npmjs.org/bl/-/bl-4.0.2.tgz",
"integrity": "sha512-j4OH8f6Qg2bGuWfRiltT2HYGx0e1QcBTrK9KAHNMwMZdQnDZFk0ZSYIpADjYCB3U12nicC5tVJwSIhwOWjb4RQ==",
"requires": {
"readable-stream": "^3.0.1"
"buffer": "^5.5.0",
"inherits": "^2.0.4",
"readable-stream": "^3.4.0"
},
"dependencies": {
"buffer": {
"version": "5.5.0",
"resolved": "https://registry.npmjs.org/buffer/-/buffer-5.5.0.tgz",
"integrity": "sha512-9FTEDjLjwoAkEwyMGDjYJQN2gfRgOKBKRfiglhvibGbpeeU/pQn1bJxQqm32OD/AIeEuHxU9roxXxg34Byp/Ww==",
"requires": {
"base64-js": "^1.0.2",
"ieee754": "^1.1.4"
}
},
"readable-stream": {
"version": "3.5.0",
"resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.5.0.tgz",
"integrity": "sha512-gSz026xs2LfxBPudDuI41V1lka8cxg64E66SGe78zJlsUofOg/yqwezdIcdfwik6B4h8LFmWPA9ef9X3FiNFLA==",
"version": "3.6.0",
"resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.0.tgz",
"integrity": "sha512-BViHy7LKeTz4oNnkcLJ+lVSL6vpiFeX6/d3oSH8zCW7UxP2onchk+vTGB143xuFjHS3deTgkKoXXymXqymiIdA==",
"requires": {
"inherits": "^2.0.3",
"string_decoder": "^1.1.1",
@ -1869,9 +1893,9 @@
}
},
"blockmap": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/blockmap/-/blockmap-4.0.0.tgz",
"integrity": "sha512-ykHgcaMZ3cPFEWku4Xz7+s7AsdfUE1x6dR7ZmaKIipu77eyq+XnBCI06Ez0VWpQfmLV/9Bsl9Qw+7cvNCNFWJA==",
"version": "4.0.1",
"resolved": "https://registry.npmjs.org/blockmap/-/blockmap-4.0.1.tgz",
"integrity": "sha512-ktam+finx4xUQQNbKRBD6VXiULFCb814/N50QBWyD2e6nrWc3QvuMISDLKnSnK64pTnQUMA9dRWpyGFK9ZIchw==",
"requires": {
"debug": "^3.1.0",
"xml-js": "^1.6.11"
@ -5402,13 +5426,13 @@
"integrity": "sha512-kVscqXk4OCp68SZ0dkgEKVi6/8ij300KBWTJq32P/dYeWTSwK41WyTxalN1eRmA5Z9UU/LX9D7FWSmV9SAYx6g=="
},
"etcher-sdk": {
"version": "2.0.17",
"resolved": "https://registry.npmjs.org/etcher-sdk/-/etcher-sdk-2.0.17.tgz",
"integrity": "sha512-9RgYlugEFLFo+nMuXeBNPT9ODg89CmEsjjJW597MKx4WNIZWoCQXQJR1qw2uu3ZT5JuqPq82xz1/9PaiW2mSng==",
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/etcher-sdk/-/etcher-sdk-3.0.0.tgz",
"integrity": "sha512-VYr7YUaGwhP53ylzXOWIIbg8TS3v0LMAJB9yRfvLdGvrtBce8cQ7JkNcLZf3e+X4YgsrgoGOqWU5nahQSpOcqQ==",
"requires": {
"@types/node": "^6.0.112",
"@ronomon/direct-io": "^3.0.1",
"axios": "^0.18.0",
"blockmap": "^4.0.0",
"blockmap": "^4.0.1",
"bluebird": "^3.5.1",
"crc": "^3.8.0",
"debug": "^3.1.0",
@ -5416,26 +5440,19 @@
"file-disk": "^6.0.1",
"file-type": "^8.0.0",
"lodash": "^4.17.10",
"lzma-native": "^4.0.5",
"lzma-native": "^6.0.0",
"mountutils": "^1.3.18",
"node-raspberrypi-usbboot": "^0.2.4",
"outdent": "^0.7.0",
"partitioninfo": "^5.3.4",
"readable-stream": "^2.3.6",
"resin-image-fs": "^5.0.8",
"rwmutex": "^1.0.0",
"speedometer": "^1.0.0",
"udif": "^0.15.7",
"udif": "^0.17.0",
"unbzip2-stream": "github:balena-io-modules/unbzip2-stream#942fc218013c14adab01cf693b0500cf6ac83193",
"unzip-stream": "^0.3.0",
"xxhash": "^0.3.0",
"yauzl": "^2.9.2"
},
"dependencies": {
"@types/node": {
"version": "6.14.9",
"resolved": "https://registry.npmjs.org/@types/node/-/node-6.14.9.tgz",
"integrity": "sha512-leP/gxHunuazPdZaCvsCefPQxinqUDsCxCR5xaDUrY2MkYxQRFZZwU5e7GojyYsGB7QVtCi7iVEl/hoFXQYc+w=="
}
}
},
"event-emitter": {
@ -8375,14 +8392,14 @@
}
},
"lzma-native": {
"version": "4.0.6",
"resolved": "https://registry.npmjs.org/lzma-native/-/lzma-native-4.0.6.tgz",
"integrity": "sha512-1kiSs/KAcAuh9vyyd00ATXZFfrg6W8UCBqH1RKlWg/tBP5aQez6HYOY+SihmsZfpy0RVDioW5SLI76dZ3Mq5Rw==",
"version": "6.0.0",
"resolved": "https://registry.npmjs.org/lzma-native/-/lzma-native-6.0.0.tgz",
"integrity": "sha512-rf5f4opPymsPHotgY2d0cUP3kbVxERSxWDGEbi2gnbnxuWGokFrBaQ02Oe9pssIwsgp0r0PnbSNg7VPY3AYe7w==",
"requires": {
"nan": "^2.14.0",
"node-addon-api": "^1.6.0",
"node-pre-gyp": "^0.11.0",
"readable-stream": "^2.3.5",
"rimraf": "^2.6.1"
"rimraf": "^2.7.1"
}
},
"make-dir": {
@ -8698,9 +8715,9 @@
"integrity": "sha512-jf84uxzwiuiIVKiOLpfYk7N46TSy8ubTonmneY9vrpHNAnp0QBt2BxWV9dO3/j+BoVAb+a5G6YDPW3M5HOdMWQ=="
},
"mimic-response": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/mimic-response/-/mimic-response-2.0.0.tgz",
"integrity": "sha512-8ilDoEapqA4uQ3TwS0jakGONKXVJqpy+RpM+3b7pLdOjghCrEiGp9SRkFbUHAmZW9vdnrENWHjaweIoTIJExSQ=="
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/mimic-response/-/mimic-response-2.1.0.tgz",
"integrity": "sha512-wXqjST+SLt7R009ySCglWBCFpjUygmCIfD790/kVbiGmUgfYGuB14PiTd5DwVxSV4NcYHjzMkoj5LjQZwTQLEA=="
},
"minify": {
"version": "4.1.3",
@ -8847,6 +8864,11 @@
}
}
},
"mkdirp-classic": {
"version": "0.5.2",
"resolved": "https://registry.npmjs.org/mkdirp-classic/-/mkdirp-classic-0.5.2.tgz",
"integrity": "sha512-ejdnDQcR75gwknmMw/tx02AuRs8jCtqFoFqDZMjiNxsu85sRIJVXDKHuLYvUUPRBUtV2FpSZa9bL1BUa3BdR2g=="
},
"mocha": {
"version": "7.0.1",
"resolved": "https://registry.npmjs.org/mocha/-/mocha-7.0.1.tgz",
@ -9272,14 +9294,14 @@
}
},
"napi-build-utils": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/napi-build-utils/-/napi-build-utils-1.0.1.tgz",
"integrity": "sha512-boQj1WFgQH3v4clhu3mTNfP+vOBxorDlE8EKiMjUlLG3C4qAESnn9AxIOkFgTR2c9LtzNjPrjS60cT27ZKBhaA=="
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/napi-build-utils/-/napi-build-utils-1.0.2.tgz",
"integrity": "sha512-ONmRUqK7zj7DWX0D9ADe03wbwOBZxNAfF20PlGfCWQcD3+/MakShIHrMqx9YwPTfxDdF1zLeL+RGZiR9kGMLdg=="
},
"needle": {
"version": "2.3.2",
"resolved": "https://registry.npmjs.org/needle/-/needle-2.3.2.tgz",
"integrity": "sha512-DUzITvPVDUy6vczKKYTnWc/pBZ0EnjMJnQ3y+Jo5zfKFimJs7S3HFCxCRZYB9FUZcrzUQr3WsmvZgddMEIZv6w==",
"version": "2.4.1",
"resolved": "https://registry.npmjs.org/needle/-/needle-2.4.1.tgz",
"integrity": "sha512-x/gi6ijr4B7fwl6WYL9FwlCvRQKGlUNvnceho8wxkwXqN8jvVmmmATTmZPRRG7b/yC1eode26C2HO9jl78Du9g==",
"requires": {
"debug": "^3.2.6",
"iconv-lite": "^0.4.4",
@ -9326,13 +9348,18 @@
}
},
"node-abi": {
"version": "2.14.0",
"resolved": "https://registry.npmjs.org/node-abi/-/node-abi-2.14.0.tgz",
"integrity": "sha512-y54KGgEOHnRHlGQi7E5UiryRkH8bmksmQLj/9iLAjoje743YS+KaKB/sDYXgqtT0J16JT3c3AYJZNI98aU/kYg==",
"version": "2.15.0",
"resolved": "https://registry.npmjs.org/node-abi/-/node-abi-2.15.0.tgz",
"integrity": "sha512-FeLpTS0F39U7hHZU1srAK4Vx+5AHNVOTP+hxBNQknR/54laTHSFIJkDWDqiquY1LeLUgTfPN7sLPhMubx0PLAg==",
"requires": {
"semver": "^5.4.1"
}
},
"node-addon-api": {
"version": "1.7.1",
"resolved": "https://registry.npmjs.org/node-addon-api/-/node-addon-api-1.7.1.tgz",
"integrity": "sha512-2+DuKodWvwRTrCfKOeR24KIc5unKjOh8mz17NCzVnHWfjAdDqbfbjqh7gUT+BkXBRQM52+xCHciKWonJ3CbJMQ=="
},
"node-environment-flags": {
"version": "1.0.6",
"resolved": "https://registry.npmjs.org/node-environment-flags/-/node-environment-flags-1.0.6.tgz",
@ -9553,9 +9580,9 @@
"integrity": "sha1-lKKxYzxPExdVMAfYlm/Q6EG2pMI="
},
"nopt": {
"version": "4.0.1",
"resolved": "https://registry.npmjs.org/nopt/-/nopt-4.0.1.tgz",
"integrity": "sha1-0NRoWv1UFRk8jHUFYC0NF81kR00=",
"version": "4.0.3",
"resolved": "https://registry.npmjs.org/nopt/-/nopt-4.0.3.tgz",
"integrity": "sha512-CvaGwVMztSMJLOeXPrez7fyfObdZqNUK1cPAEzLHrTybIua9pMdmmPR5YwtfNftIOMv3DPUhFaxsZMNTQO20Kg==",
"requires": {
"abbrev": "1",
"osenv": "^0.1.4"
@ -9908,9 +9935,9 @@
}
},
"outdent": {
"version": "0.7.0",
"resolved": "https://registry.npmjs.org/outdent/-/outdent-0.7.0.tgz",
"integrity": "sha512-Ue462G+UIFoyQmOzapGIKWS3d/9NHeD/018WGEDZIhN2/VaQpVXbofMcZX0socv1fw4/tmEn7Vd3McOdPZfKzQ=="
"version": "0.7.1",
"resolved": "https://registry.npmjs.org/outdent/-/outdent-0.7.1.tgz",
"integrity": "sha512-VjIzdUHunL74DdhcwMDt5FhNDQ8NYmTkuW0B+usIV2afS9aWT/1c9z1TsnFW349TP3nxmYeUl7Z++XpJRByvgg=="
},
"p-cancelable": {
"version": "1.1.0",
@ -11122,9 +11149,9 @@
}
},
"resin-image-fs": {
"version": "5.0.8",
"resolved": "https://registry.npmjs.org/resin-image-fs/-/resin-image-fs-5.0.8.tgz",
"integrity": "sha512-m3DPKAdErmgxMkOhGP9NOyqZor0DADkuDKb38XSjlhxj5lJMEtLi7AuZauyl4ysINc4u+ljMDW9IqGNpXhFcXw==",
"version": "5.0.9",
"resolved": "https://registry.npmjs.org/resin-image-fs/-/resin-image-fs-5.0.9.tgz",
"integrity": "sha512-fBCJjF6GeqRveum3cJCBf9E0AtIA7qtVccXU6bmoyEEixA0AxWDqp/nJ5+PjIL26/bpaX95vo7Mscyr8Q1UNfQ==",
"requires": {
"bluebird": "^3.5.1",
"ext2fs": "^1.0.28",
@ -11382,6 +11409,14 @@
"resolved": "https://registry.npmjs.org/rw/-/rw-1.3.3.tgz",
"integrity": "sha1-P4Yt+pGrdmsUiF700BEkv9oHT7Q="
},
"rwmutex": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/rwmutex/-/rwmutex-1.0.0.tgz",
"integrity": "sha1-/dHqaoe3f0SecteF+eonTL4UDe0=",
"requires": {
"debug": "^3.0.1"
}
},
"rx-lite": {
"version": "4.0.8",
"resolved": "https://registry.npmjs.org/rx-lite/-/rx-lite-4.0.8.tgz",
@ -12727,22 +12762,22 @@
}
},
"tar-fs": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/tar-fs/-/tar-fs-2.0.0.tgz",
"integrity": "sha512-vaY0obB6Om/fso8a8vakQBzwholQ7v5+uy+tF3Ozvxv1KNezmVQAiWtcNmMHFSFPqL3dJA8ha6gdtFbfX9mcxA==",
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/tar-fs/-/tar-fs-2.0.1.tgz",
"integrity": "sha512-6tzWDMeroL87uF/+lin46k+Q+46rAJ0SyPGz7OW7wTgblI273hsBqk2C1j0/xNadNLKDTUL9BukSjB7cwgmlPA==",
"requires": {
"chownr": "^1.1.1",
"mkdirp": "^0.5.1",
"mkdirp-classic": "^0.5.2",
"pump": "^3.0.0",
"tar-stream": "^2.0.0"
}
},
"tar-stream": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/tar-stream/-/tar-stream-2.1.0.tgz",
"integrity": "sha512-+DAn4Nb4+gz6WZigRzKEZl1QuJVOLtAwwF+WUxy1fJ6X63CaGaUAxJRD2KEn1OMfcbCjySTYpNC6WmfQoIEOdw==",
"version": "2.1.2",
"resolved": "https://registry.npmjs.org/tar-stream/-/tar-stream-2.1.2.tgz",
"integrity": "sha512-UaF6FoJ32WqALZGOIAApXx+OdxhekNMChu6axLJR85zMMjXKWFGjbIRe+J6P4UnRGg9rAwWvbTT0oI7hD/Un7Q==",
"requires": {
"bl": "^3.0.0",
"bl": "^4.0.1",
"end-of-stream": "^1.4.1",
"fs-constants": "^1.0.0",
"inherits": "^2.0.3",
@ -12750,9 +12785,9 @@
},
"dependencies": {
"readable-stream": {
"version": "3.5.0",
"resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.5.0.tgz",
"integrity": "sha512-gSz026xs2LfxBPudDuI41V1lka8cxg64E66SGe78zJlsUofOg/yqwezdIcdfwik6B4h8LFmWPA9ef9X3FiNFLA==",
"version": "3.6.0",
"resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.0.tgz",
"integrity": "sha512-BViHy7LKeTz4oNnkcLJ+lVSL6vpiFeX6/d3oSH8zCW7UxP2onchk+vTGB143xuFjHS3deTgkKoXXymXqymiIdA==",
"requires": {
"inherits": "^2.0.3",
"string_decoder": "^1.1.1",
@ -13263,14 +13298,26 @@
"integrity": "sha512-8OaIKfzL5cpx8eCMAhhvTlft8GYF8b2eQr6JkCyVdrgjcytyOmPCXrqXFcUnhonRpLlh5yxEZVohm6mzaowUOw=="
},
"udif": {
"version": "0.15.7",
"resolved": "https://registry.npmjs.org/udif/-/udif-0.15.7.tgz",
"integrity": "sha512-rLzT/RZs6aD13oKHcuU4XiKeJXWX0ZiL6GgTpXt21XWM4jSxOjZHurRwaPkXYmFpTqt+VSht06oUd5mx1KjpyA==",
"version": "0.17.0",
"resolved": "https://registry.npmjs.org/udif/-/udif-0.17.0.tgz",
"integrity": "sha512-59bQzrlk/MjbEg3Sv+jrCGOc44V4whyXE2ZlI5O3GWMECUpnM4Wfb5CUc20AV2Plbw8Owq6SaBJRbkkK1DSMPw==",
"requires": {
"apple-data-compression": "^0.4.0",
"plist": "^3.0.1",
"readable-stream": "^2.3.6",
"readable-stream": "^3.3.0",
"seek-bzip": "^1.0.5"
},
"dependencies": {
"readable-stream": {
"version": "3.6.0",
"resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.0.tgz",
"integrity": "sha512-BViHy7LKeTz4oNnkcLJ+lVSL6vpiFeX6/d3oSH8zCW7UxP2onchk+vTGB143xuFjHS3deTgkKoXXymXqymiIdA==",
"requires": {
"inherits": "^2.0.3",
"string_decoder": "^1.1.1",
"util-deprecate": "^1.0.1"
}
}
}
},
"uglify-js": {
@ -14469,4 +14516,4 @@
}
}
}
}
}

View File

@ -61,7 +61,7 @@
"d3": "^4.13.0",
"debug": "^3.1.0",
"electron-updater": "4.0.6",
"etcher-sdk": "^2.0.17",
"etcher-sdk": "^3.0.0",
"flexboxgrid": "^6.3.0",
"immutable": "^3.8.1",
"inactivity-timer": "^1.0.0",