From 3ea4c757e60fac7085774ebb3d355d781f08009e Mon Sep 17 00:00:00 2001 From: Julien Fontanet Date: Tue, 2 Jun 2020 15:27:12 +0200 Subject: [PATCH] feat(backups-cli): clean checksums for missing XVAs --- @xen-orchestra/backups-cli/commands/clean-vms.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/@xen-orchestra/backups-cli/commands/clean-vms.js b/@xen-orchestra/backups-cli/commands/clean-vms.js index 8986a5f91..8dc8d62c6 100644 --- a/@xen-orchestra/backups-cli/commands/clean-vms.js +++ b/@xen-orchestra/backups-cli/commands/clean-vms.js @@ -152,11 +152,12 @@ async function handleVm(vmDir) { await Promise.all(deletions) } - const [jsons, xvas] = await fs + const [jsons, xvas, xvaSums] = await fs .readdir2(vmDir) .then(entries => [ entries.filter(_ => _.endsWith('.json')), new Set(entries.filter(_ => _.endsWith('.xva'))), + entries.filter(_ => _.endsWith('.xva.cheksum')), ]) await asyncMap(xvas, async path => { @@ -274,6 +275,15 @@ async function handleVm(vmDir) { console.warn('') return force && handler.unlink(path) }), + asyncMap(xvaSums, path => { + // no need to handle checksums for XVAs deleted by the script, they will be handled by `unlink()` + if (!xvas.has(path.slice(0, -'.checksum'.length))) { + console.warn('Unused XVA checksum', path) + force && console.warn(' deleting…') + console.warn('') + return force && handler.unlink(path) + } + }), ]) }