Skip to content

Commit

Permalink
feat(vhd-lib): handle broken vhd directory named as aliases (#8292)
Browse files Browse the repository at this point in the history
  • Loading branch information
fbeauchamp authored Mar 4, 2025
1 parent cf03313 commit 90f8f9c
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
20 changes: 19 additions & 1 deletion @xen-orchestra/backups/_cleanVm.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,27 @@ export async function checkAliases(
logWarn('missing target of alias', { alias })
if (remove) {
logInfo('removing alias and non VHD target', { alias, target })
await handler.unlink(target)
await handler.unlink(alias)
}
continue
}
if (err.code === 'EISDIR') {
logWarn('alias is a vhd directory', { alias })
if (remove) {
logInfo('removing vhd directory named as alias', { alias, target })
await VhdAbstract.unlink(handler, alias)
}
continue
}
logWarn('unhandled error while checking alias', { alias, err })
continue
}

if (target === '') {
logWarn('empty target for alias ', { alias })
if (remove) {
logInfo('removing alias and non VHD target', { alias, target })
await handler.unlink(alias)
}
continue
}
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.unreleased.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@

- @xen-orchestra/backups patch
- @xen-orchestra/web minor
- vhd-lib patch
- xo-server patch

<!--packages-end-->
13 changes: 12 additions & 1 deletion packages/vhd-lib/Vhd/VhdAbstract.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@ const {
const assert = require('assert')
const path = require('path')
const asyncIteratorToStream = require('async-iterator-to-stream')
const { createLogger } = require('@xen-orchestra/log')
const { checksumStruct, fuFooter, fuHeader } = require('../_structs')
const { isVhdAlias, resolveVhdAlias } = require('../aliases')

const { warn } = createLogger('vhd-lib:VhdAbstract')
exports.VhdAbstract = class VhdAbstract {
get bitmapSize() {
return sectorsToBytes(this.sectorsOfBitmap)
Expand Down Expand Up @@ -202,7 +204,16 @@ exports.VhdAbstract = class VhdAbstract {
}

static async unlink(handler, path) {
const resolved = await resolveVhdAlias(handler, path)
let resolved = path
try {
resolved = await resolveVhdAlias(handler, path)
} catch (err) {
// broken vhd directory must be unlinkable
if (err.code !== 'EISDIR') {
throw err
}
warn('Deleting directly a VhdDirectory', { path, err })
}
try {
await handler.unlink(resolved)
} catch (err) {
Expand Down

0 comments on commit 90f8f9c

Please sign in to comment.