@xen-orchestra/backups 0.26.0 → 0.27.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/_cleanVm.js +26 -3
  2. package/package.json +4 -4
package/_cleanVm.js CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  const assert = require('assert')
4
4
  const sum = require('lodash/sum')
5
+ const UUID = require('uuid')
5
6
  const { asyncMap } = require('@xen-orchestra/async-map')
6
7
  const { Constants, mergeVhd, openVhd, VhdAbstract, VhdFile } = require('vhd-lib')
7
8
  const { isVhdAlias, resolveVhdAlias } = require('vhd-lib/aliases')
@@ -50,7 +51,7 @@ const computeVhdsSize = (handler, vhdPaths) =>
50
51
  async function mergeVhdChain(chain, { handler, logInfo, remove, merge }) {
51
52
  assert(chain.length >= 2)
52
53
  const chainCopy = [...chain]
53
- const parent = chainCopy.pop()
54
+ const parent = chainCopy.shift()
54
55
  const children = chainCopy
55
56
 
56
57
  if (merge) {
@@ -187,6 +188,7 @@ exports.cleanVm = async function cleanVm(
187
188
  const handler = this._handler
188
189
 
189
190
  const vhdsToJSons = new Set()
191
+ const vhdById = new Map()
190
192
  const vhdParents = { __proto__: null }
191
193
  const vhdChildren = { __proto__: null }
192
194
 
@@ -208,6 +210,27 @@ exports.cleanVm = async function cleanVm(
208
210
  }
209
211
  vhdChildren[parent] = path
210
212
  }
213
+ // Detect VHDs with the same UUIDs
214
+ //
215
+ // Due to a bug introduced in a1bcd35e2
216
+ const duplicate = vhdById.get(UUID.stringify(vhd.footer.uuid))
217
+ let vhdKept = vhd
218
+ if (duplicate !== undefined) {
219
+ logWarn('uuid is duplicated', { uuid: UUID.stringify(vhd.footer.uuid) })
220
+ if (duplicate.containsAllDataOf(vhd)) {
221
+ logWarn(`should delete ${path}`)
222
+ vhdKept = duplicate
223
+ vhds.delete(path)
224
+ } else if (vhd.containsAllDataOf(duplicate)) {
225
+ logWarn(`should delete ${duplicate._path}`)
226
+ vhds.delete(duplicate._path)
227
+ } else {
228
+ logWarn(`same ids but different content`)
229
+ }
230
+ } else {
231
+ logInfo('not duplicate', UUID.stringify(vhd.footer.uuid), path)
232
+ }
233
+ vhdById.set(UUID.stringify(vhdKept.footer.uuid), vhdKept)
211
234
  })
212
235
  } catch (error) {
213
236
  vhds.delete(path)
@@ -362,7 +385,7 @@ exports.cleanVm = async function cleanVm(
362
385
  const unusedVhdsDeletion = []
363
386
  const toMerge = []
364
387
  {
365
- // VHD chains (as list from child to ancestor) to merge indexed by last
388
+ // VHD chains (as list from oldest to most recent) to merge indexed by most recent
366
389
  // ancestor
367
390
  const vhdChainsToMerge = { __proto__: null }
368
391
 
@@ -386,7 +409,7 @@ exports.cleanVm = async function cleanVm(
386
409
  if (child !== undefined) {
387
410
  const chain = getUsedChildChainOrDelete(child)
388
411
  if (chain !== undefined) {
389
- chain.push(vhd)
412
+ chain.unshift(vhd)
390
413
  return chain
391
414
  }
392
415
  }
package/package.json CHANGED
@@ -8,7 +8,7 @@
8
8
  "type": "git",
9
9
  "url": "https://github.com/vatesfr/xen-orchestra.git"
10
10
  },
11
- "version": "0.26.0",
11
+ "version": "0.27.0",
12
12
  "engines": {
13
13
  "node": ">=14.6"
14
14
  },
@@ -22,7 +22,7 @@
22
22
  "@vates/disposable": "^0.1.1",
23
23
  "@vates/parse-duration": "^0.1.1",
24
24
  "@xen-orchestra/async-map": "^0.1.2",
25
- "@xen-orchestra/fs": "^1.0.3",
25
+ "@xen-orchestra/fs": "^1.1.0",
26
26
  "@xen-orchestra/log": "^0.3.0",
27
27
  "@xen-orchestra/template": "^0.1.0",
28
28
  "compare-versions": "^4.0.1",
@@ -38,7 +38,7 @@
38
38
  "promise-toolbox": "^0.21.0",
39
39
  "proper-lockfile": "^4.1.2",
40
40
  "uuid": "^8.3.2",
41
- "vhd-lib": "^3.2.0",
41
+ "vhd-lib": "^3.3.1",
42
42
  "yazl": "^2.5.1"
43
43
  },
44
44
  "devDependencies": {
@@ -46,7 +46,7 @@
46
46
  "tmp": "^0.2.1"
47
47
  },
48
48
  "peerDependencies": {
49
- "@xen-orchestra/xapi": "^1.2.0"
49
+ "@xen-orchestra/xapi": "^1.4.0"
50
50
  },
51
51
  "license": "AGPL-3.0-or-later",
52
52
  "author": {