fix(vhd-lib): improve openVhd error handling

This commit is contained in:
Florent Beauchamp 2022-10-25 17:44:25 +02:00 committed by Julien Fontanet
parent 0cf6f94677
commit 545a65521a
2 changed files with 4 additions and 3 deletions

View File

@ -83,7 +83,9 @@ exports.VhdFile = class VhdFile extends VhdAbstract {
} }
static async open(handler, path, { flags, checkSecondFooter = true } = {}) { static async open(handler, path, { flags, checkSecondFooter = true } = {}) {
assert(!handler.isEncrypted, `VHDFile implementation is not compatible with encrypted remote`) if (handler.isEncrypted) {
throw new Error(`VHDFile implementation is not compatible with encrypted remote`)
}
const fd = await handler.openFile(path, flags ?? 'r+') const fd = await handler.openFile(path, flags ?? 'r+')
const vhd = new VhdFile(handler, fd) const vhd = new VhdFile(handler, fd)
// openning a file for reading does not trigger EISDIR as long as we don't really read from it : // openning a file for reading does not trigger EISDIR as long as we don't really read from it :

View File

@ -9,8 +9,7 @@ exports.openVhd = async function openVhd(handler, path, opts) {
try { try {
return await VhdFile.open(handler, resolved, opts) return await VhdFile.open(handler, resolved, opts)
} catch (e) { } catch (e) {
// if the remote is encrypted, trying to open a VhdFile will throw an assertion error before checking if the path is a directory, therefore we should try to open a VhdDirectory anyway. if (e.code !== 'EISDIR') {
if (e.code !== 'EISDIR' && e.code !== 'ERR_ASSERTION') {
throw e throw e
} }
return await VhdDirectory.open(handler, resolved, opts) return await VhdDirectory.open(handler, resolved, opts)