fix(deltaBackups): update checksum after altering VHD files (#408)

Fixes vatesfr/xo-web#1606
This commit is contained in:
Nicolas Raynaud 2016-09-30 05:31:33 -07:00 committed by Julien Fontanet
parent 3944b8aaee
commit bdeb5895f6
3 changed files with 15 additions and 1 deletions

View File

@ -154,6 +154,13 @@ export default class RemoteHandlerAbstract {
throw new Error('Not implemented')
}
async refreshChecksum (path) {
const stream = addChecksumToReadStream(await this.createReadStream(path))
stream.resume() // start reading the whole file
const checksum = await stream.checksum
await this.outputFile(`${path}.checksum`, checksum)
}
async createOutputStream (file, {
checksum = false,
...options

View File

@ -572,6 +572,7 @@ export default async function vhdMerge (
await parentVhd.writeFooter()
}
// returns true if the child was actually modified
export async function chainVhd (
parentHandler, parentPath,
childHandler, childPath
@ -588,5 +589,7 @@ export async function chainVhd (
childVhd.header.parentUuid = parentUuid
childVhd.header.parentUnicodeName = parentName
await childVhd.writeHeader()
return true
}
return false
}

View File

@ -295,7 +295,11 @@ export default class {
async _chainDeltaVdiBackups ({handler, dir}) {
const backups = await this._listVdiBackups(handler, dir)
for (let i = 1; i < backups.length; i++) {
await chainVhd(handler, dir + '/' + backups[i - 1], handler, dir + '/' + backups[i])
const childPath = dir + '/' + backups[i]
const modified = await chainVhd(handler, dir + '/' + backups[i - 1], handler, childPath)
if (modified) {
await handler.refreshChecksum(childPath)
}
}
}