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.writeFooter()
await dest.writeHeader() await dest.writeHeader()
await dest.writeBlockAllocationTable() await dest.writeBlockAllocationTable()
if (directory) {
dest.finalize()
}
}) })
} }

View File

@@ -11,6 +11,8 @@ const zlib = require('zlib')
const { debug } = createLogger('vhd-lib:VhdDirectory') const { debug } = createLogger('vhd-lib:VhdDirectory')
const CREATION_FILE_NAME = '.creating'
const NULL_COMPRESSOR = { const NULL_COMPRESSOR = {
compress: buffer => buffer, compress: buffer => buffer,
decompress: buffer => buffer, decompress: buffer => buffer,
@@ -119,6 +121,7 @@ exports.VhdDirectory = class VhdDirectory extends VhdAbstract {
static async create(handler, path, { flags = 'wx+', compression } = {}) { static async create(handler, path, { flags = 'wx+', compression } = {}) {
await handler.mkdir(path) await handler.mkdir(path)
const vhd = new VhdDirectory(handler, path, { flags, compression }) const vhd = new VhdDirectory(handler, path, { flags, compression })
await handler.writeFile(`${path}/${CREATION_FILE_NAME}`, +new Date())
return { return {
dispose: () => {}, dispose: () => {},
value: vhd, value: vhd,
@@ -174,7 +177,19 @@ exports.VhdDirectory = class VhdDirectory extends VhdAbstract {
return `blocks/${blockPrefix}/${blockSuffix}` 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() await this.#readChunkFilters()
let bufHeader, bufFooter let bufHeader, bufFooter
@@ -290,4 +305,8 @@ exports.VhdDirectory = class VhdDirectory extends VhdAbstract {
}) })
this.#compressor = getCompressor(chunkFilters[0]) 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': case 'bat':
// it exists but I don't care // it exists but I don't care
break break
case 'end':
await vhd.finalize()
break
default: default:
throw new Error(`unhandled type of block generated by parser : ${item.type} while generating ${path}`) 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) const bufFooterEnd = await readLastSector(stream)
assert(bufFooter.equals(bufFooterEnd), 'footer1 !== footer2') assert(bufFooter.equals(bufFooterEnd), 'footer1 !== footer2')
yield {
type: 'end',
}
} }
function readLastSector(stream) { function readLastSector(stream) {