embedded: add missing DB remove call in reset

This commit is contained in:
Florian Dold 2023-02-23 15:18:30 +01:00
parent 7985b0a33f
commit 339080e014
No known key found for this signature in database
GPG Key ID: D2E4F00F29D02A4B
2 changed files with 19 additions and 8 deletions

View File

@ -23,6 +23,7 @@ export interface QjsOsLib {
postMessageToHost(s: string): void;
setMessageFromHostHandler(h: (s: string) => void): void;
rename(oldPath: string, newPath: string): number;
remove(path: string): number;
}
export interface QjsStdLib {

View File

@ -30,6 +30,7 @@ import {
Logger,
setGlobalLogLevelFromString,
setPRNG,
TalerErrorCode,
WalletNotification,
} from "@gnu-taler/taler-util";
import { createPlatformHttpLib } from "@gnu-taler/taler-util/http";
@ -74,7 +75,7 @@ class NativeWalletMessageHandler {
id: string,
args: any,
): Promise<CoreApiResponse> {
const wrapResponse = (result: unknown): CoreApiResponseSuccess => {
const wrapSuccessResponse = (result: unknown): CoreApiResponseSuccess => {
return {
type: "response",
id,
@ -120,7 +121,7 @@ class NativeWalletMessageHandler {
setGlobalLogLevelFromString(logLevel);
}
await reinit();
return wrapResponse({
return wrapSuccessResponse({
...initResponse,
});
}
@ -137,14 +138,22 @@ class NativeWalletMessageHandler {
throw Error("not implemented");
}
case "reset": {
logger.info("resetting wallet");
const oldArgs = this.walletArgs;
this.walletArgs = { ...oldArgs };
if (oldArgs && oldArgs.persistentStoragePath) {
try {
logger.error("FIXME: reset not implemented");
// fs.unlinkSync(oldArgs.persistentStoragePath);
} catch (e) {
logger.error("Error while deleting the wallet db:", e);
const ret = qjsOs.remove(oldArgs.persistentStoragePath);
if (ret != null) {
return {
type: "error",
id,
operation,
error: {
code: TalerErrorCode.GENERIC_UNEXPECTED_REQUEST_ERROR,
hint: `path ${oldArgs.persistentStoragePath}`,
message: "removing DB file failed",
},
};
}
// Prevent further storage!
this.walletArgs.persistentStoragePath = undefined;
@ -154,7 +163,8 @@ class NativeWalletMessageHandler {
this.wp = openPromise<Wallet>();
this.maybeWallet = undefined;
await reinit();
return wrapResponse({});
logger.info("wallet re-initialized after reset");
return wrapSuccessResponse({});
}
default: {
const wallet = await this.wp.promise;