diff --git a/CHANGELOG.unreleased.md b/CHANGELOG.unreleased.md index 4c70d0783..99dd318f4 100644 --- a/CHANGELOG.unreleased.md +++ b/CHANGELOG.unreleased.md @@ -36,7 +36,7 @@ - @xen-orchestra/self-signed patch -- vhd-lib patch +- vhd-lib minor - @xen-orchestra/fs patch - vhd-cli patch - xo-vmdk-to-vhd minor diff --git a/packages/vhd-lib/peekFooterFromVhdStream.js b/packages/vhd-lib/peekFooterFromVhdStream.js index baf4fab89..6ced7039a 100644 --- a/packages/vhd-lib/peekFooterFromVhdStream.js +++ b/packages/vhd-lib/peekFooterFromVhdStream.js @@ -3,11 +3,10 @@ const { readChunk } = require('@vates/read-chunk') const { FOOTER_SIZE } = require('./_constants') -const { fuFooter } = require('./_structs') +const { unpackFooter } = require('./Vhd/_utils.js') module.exports = async function peekFooterFromStream(stream) { - const footerBuffer = await readChunk(stream, FOOTER_SIZE) - const footer = fuFooter.unpack(footerBuffer) - stream.unshift(footerBuffer) - return footer + const buffer = await readChunk(stream, FOOTER_SIZE) + stream.unshift(buffer) + return unpackFooter(buffer) } diff --git a/packages/xo-server/src/api/disk.mjs b/packages/xo-server/src/api/disk.mjs index 7e9286f8a..d47180fe9 100644 --- a/packages/xo-server/src/api/disk.mjs +++ b/packages/xo-server/src/api/disk.mjs @@ -6,7 +6,7 @@ import { defer } from 'golike-defer' import { format, JsonRpcError } from 'json-rpc-peer' import { noSuchObject } from 'xo-common/api-errors.js' import { pipeline } from 'stream' -import { checkFooter, peekFooterFromVhdStream } from 'vhd-lib' +import { peekFooterFromVhdStream } from 'vhd-lib' import { vmdkToVhd } from 'xo-vmdk-to-vhd' import { VDI_FORMAT_VHD, VDI_FORMAT_RAW } from '../xapi/index.mjs' @@ -192,14 +192,12 @@ async function handleImport(req, res, { type, name, description, vmdkData, srId, break case 'vhd': { - const footer = await peekFooterFromVhdStream(vhdStream) - try { - checkFooter(footer) - } catch (e) { + const footer = await peekFooterFromVhdStream(vhdStream).catch(e => { if (e instanceof assert.AssertionError) { throw new JsonRpcError(`Vhd file had an invalid header ${e}`) } - } + throw e + }) vhdStream = part size = footer.currentSize }