Files
xen-orchestra/packages/vhd-lib/src/chain.js
T

31 lines
1.0 KiB
JavaScript
Raw Normal View History

2018-05-14 04:48:16 -07:00
import { dirname, relative } from 'path'
import { openVhd } from './'
2018-05-14 04:48:16 -07:00
import { DISK_TYPE_DIFFERENCING } from './_constants'
import { Disposable } from 'promise-toolbox'
2018-05-14 04:48:16 -07:00
2020-11-24 10:50:40 +01:00
export default async function chain(parentHandler, parentPath, childHandler, childPath, force = false) {
await Disposable.use(
[openVhd(parentHandler, parentPath), openVhd(childHandler, childPath)],
async ([parentVhd, childVhd]) => {
await childVhd.readHeaderAndFooter()
const { header, footer } = childVhd
2018-05-14 04:48:16 -07:00
if (footer.diskType !== DISK_TYPE_DIFFERENCING) {
if (!force) {
throw new Error('cannot chain disk of type ' + footer.diskType)
}
footer.diskType = DISK_TYPE_DIFFERENCING
}
await childVhd.readBlockAllocationTable()
2018-05-14 04:48:16 -07:00
const parentName = relative(dirname(childPath), parentPath)
header.parentUuid = parentVhd.footer.uuid
header.parentUnicodeName = parentName
await childVhd.setUniqueParentLocator(parentName)
await childVhd.writeHeader()
await childVhd.writeFooter()
2018-05-14 04:48:16 -07:00
}
)
2018-05-14 04:48:16 -07:00
}