From f25136a51232a35a8925b1944913c54729e6a802 Mon Sep 17 00:00:00 2001 From: wescoeur Date: Wed, 20 Jan 2016 17:01:39 +0100 Subject: [PATCH] Avoid errors in delta backups. (fix) - Wait the task end of vdi export. - Now, in the error case of vdi backup, the current vdi snapshot is removed with catch(noop). --- src/xo-mixins/backups.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/xo-mixins/backups.js b/src/xo-mixins/backups.js index 7eae00415..6c17d4c48 100644 --- a/src/xo-mixins/backups.js +++ b/src/xo-mixins/backups.js @@ -245,13 +245,16 @@ export default class { const targetStream = createWriteStream(backupFullPath, { flags: 'wx' }) sourceStream.on('error', error => targetStream.emit('error', error)) - await eventToPromise(sourceStream.pipe(targetStream), 'finish') - } catch (e) { + await Promise.all([ + eventToPromise(sourceStream.pipe(targetStream), 'finish'), + sourceStream.task + ]) + } catch (error) { // Remove new backup. (corrupt) and delete new vdi base. - await xapi.deleteVdi(currentSnapshot.$id) + xapi.deleteVdi(currentSnapshot.$id).catch(noop) await unlink(backupFullPath).catch(noop) - throw e + throw error } // Returns relative path. (subdir and vdi filename), old/new base.