Compare commits

...

1 Commits

Author SHA1 Message Date
Florent Beauchamp
d47c7c6064 feat(s3): add completion control to s3 backup 2022-05-09 10:01:09 +02:00
4 changed files with 30 additions and 1 deletions

View File

@@ -46,5 +46,9 @@ export default async rawArgs => {
await dest.writeFooter()
await dest.writeHeader()
await dest.writeBlockAllocationTable()
if (directory) {
dest.finalize()
}
})
}

View File

@@ -11,6 +11,8 @@ const zlib = require('zlib')
const { debug } = createLogger('vhd-lib:VhdDirectory')
const CREATION_FILE_NAME = '.creating'
const NULL_COMPRESSOR = {
compress: buffer => buffer,
decompress: buffer => buffer,
@@ -119,6 +121,7 @@ exports.VhdDirectory = class VhdDirectory extends VhdAbstract {
static async create(handler, path, { flags = 'wx+', compression } = {}) {
await handler.mkdir(path)
const vhd = new VhdDirectory(handler, path, { flags, compression })
await handler.writeFile(`${path}/${CREATION_FILE_NAME}`, +new Date())
return {
dispose: () => {},
value: vhd,
@@ -174,7 +177,19 @@ exports.VhdDirectory = class VhdDirectory extends VhdAbstract {
return `blocks/${blockPrefix}/${blockSuffix}`
}
async readHeaderAndFooter() {
async readHeaderAndFooter(checkSecondFooter = true) {
// check that the vhd is complete ( )
if (checkSecondFooter) {
try {
const date = await this._handler.readFile(`${this._path}/${CREATION_FILE_NAME}`)
throw new Error(`the vhd ${this._path} is currently in creation since ${date}`, { path: this._path, date })
} catch (error) {
if (error.code !== 'ENOENT') {
throw error
}
// no temporary file indicating that the vhd is currently in creation
}
}
await this.#readChunkFilters()
let bufHeader, bufFooter
@@ -290,4 +305,8 @@ exports.VhdDirectory = class VhdDirectory extends VhdAbstract {
})
this.#compressor = getCompressor(chunkFilters[0])
}
async finalize() {
await this._handler.unlink(`${this._path}/${CREATION_FILE_NAME}`)
}
}

View File

@@ -26,6 +26,9 @@ const buildVhd = Disposable.wrap(async function* (handler, path, inputStream, {
case 'bat':
// it exists but I don't care
break
case 'end':
await vhd.finalize()
break
default:
throw new Error(`unhandled type of block generated by parser : ${item.type} while generating ${path}`)
}

View File

@@ -119,6 +119,9 @@ exports.parseVhdStream = async function* parseVhdStream(stream) {
*/
const bufFooterEnd = await readLastSector(stream)
assert(bufFooter.equals(bufFooterEnd), 'footer1 !== footer2')
yield {
type: 'end',
}
}
function readLastSector(stream) {