Clean up when new key backup version fails to backup

If creating a new key backup version succeeds but backing up to it fails, delete
the version to avoid surprises. In addition, this converts the creation of a new
key backup to async / await style.

Signed-off-by: J. Ryan Stinnett <jryans@gmail.com>
This commit is contained in:
J. Ryan Stinnett 2018-12-13 12:10:08 +00:00
parent 1c4621c98e
commit 2b14f2af5c

View file

@ -92,25 +92,33 @@ export default React.createClass({
}); });
}, },
_createBackup: function() { _createBackup: async function() {
this.setState({ this.setState({
phase: PHASE_BACKINGUP, phase: PHASE_BACKINGUP,
error: null, error: null,
}); });
this._createBackupPromise = MatrixClientPeg.get().createKeyBackupVersion( let info;
this._keyBackupInfo, try {
).then((info) => { info = await MatrixClientPeg.get().createKeyBackupVersion(
return MatrixClientPeg.get().backupAllGroupSessions(info.version); this._keyBackupInfo,
}).then(() => { );
await MatrixClientPeg.get().backupAllGroupSessions(info.version);
this.setState({ this.setState({
phase: PHASE_DONE, phase: PHASE_DONE,
}); });
}).catch(e => { } catch (e) {
console.log("Error creating key backup", e); console.log("Error creating key backup", e);
// TODO: If creating a version succeeds, but backup fails, should we
// delete the version, disable backup, or do nothing? If we just
// disable without deleting, we'll enable on next app reload since
// it is trusted.
if (info) {
MatrixClientPeg.get().deleteKeyBackupVersion(info.version);
}
this.setState({ this.setState({
error: e, error: e,
}); });
}); }
}, },
_onCancel: function() { _onCancel: function() {