gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[taler-wallet-core] branch master updated: wallet-core: fix/refactor log


From: gnunet
Subject: [taler-wallet-core] branch master updated: wallet-core: fix/refactor logic to get sqlite3 db file path
Date: Tue, 05 Nov 2024 13:10:31 +0100

This is an automated email from the git hooks/post-receive script.

dold pushed a commit to branch master
in repository wallet-core.

The following commit(s) were added to refs/heads/master by this push:
     new 9486afd0e wallet-core: fix/refactor logic to get sqlite3 db file path
9486afd0e is described below

commit 9486afd0e2f1822f473691a28fcde7e4878fbd87
Author: Florian Dold <florian@dold.me>
AuthorDate: Tue Nov 5 13:10:19 2024 +0100

    wallet-core: fix/refactor logic to get sqlite3 db file path
---
 packages/taler-wallet-core/src/host-common.ts     | 28 +++++++++++++++++++++++
 packages/taler-wallet-core/src/host-impl.node.ts  | 10 ++++++--
 packages/taler-wallet-core/src/host-impl.qtart.ts | 10 ++++++--
 packages/taler-wallet-embedded/src/wallet-qjs.ts  | 28 -----------------------
 4 files changed, 44 insertions(+), 32 deletions(-)

diff --git a/packages/taler-wallet-core/src/host-common.ts 
b/packages/taler-wallet-core/src/host-common.ts
index 7651e5a12..933c36533 100644
--- a/packages/taler-wallet-core/src/host-common.ts
+++ b/packages/taler-wallet-core/src/host-common.ts
@@ -58,3 +58,31 @@ export function makeTempfileId(length: number): string {
   }
   return result;
 }
+
+/**
+ * Get the underlying sqlite3 DB filename
+ * from the storage path specified by the wallet-core client.
+ */
+export function getSqlite3FilenameFromStoragePath(
+  p: string | undefined,
+): string {
+  // Allow specifying a directory as the storage path.
+  // In that case, we pick the filename and use the sqlite3
+  // backend.
+  //
+  // We still allow specifying a filename for backwards
+  // compatibility and control over the exact file.
+  //
+  // Specifying a directory allows us to automatically
+  // migrate to a new DB file in the future.
+  if (!p) {
+    return ":memory:";
+  }
+  if (p.endsWith("/")) {
+    // Current sqlite3 DB filename.
+    // Should rarely if ever change.
+    return `${p}talerwalletdb-v30.sqlite3`;
+  } else {
+    return p;
+  }
+}
diff --git a/packages/taler-wallet-core/src/host-impl.node.ts 
b/packages/taler-wallet-core/src/host-impl.node.ts
index a7f0a5738..eb4191f81 100644
--- a/packages/taler-wallet-core/src/host-impl.node.ts
+++ b/packages/taler-wallet-core/src/host-impl.node.ts
@@ -41,7 +41,11 @@ import { createPlatformHttpLib } from 
"@gnu-taler/taler-util/http";
 import * as fs from "fs";
 import { NodeThreadCryptoWorkerFactory } from 
"./crypto/workers/nodeThreadWorker.js";
 import { SynchronousCryptoWorkerFactoryPlain } from 
"./crypto/workers/synchronousWorkerFactoryPlain.js";
-import { DefaultNodeWalletArgs, makeTempfileId } from "./host-common.js";
+import {
+  DefaultNodeWalletArgs,
+  getSqlite3FilenameFromStoragePath,
+  makeTempfileId,
+} from "./host-common.js";
 import { Wallet } from "./wallet.js";
 
 const logger = new Logger("host-impl.node.ts");
@@ -114,7 +118,9 @@ async function makeSqliteDb(
     BridgeIDBFactory.enableTracing = false;
   }
   const imp = await createNodeSqlite3Impl();
-  const dbFilename = args.persistentStoragePath ?? ":memory:";
+  const dbFilename = getSqlite3FilenameFromStoragePath(
+    args.persistentStoragePath,
+  );
   logger.info(`using database ${dbFilename}`);
   const myBackend = await createSqliteBackend(imp, {
     filename: dbFilename,
diff --git a/packages/taler-wallet-core/src/host-impl.qtart.ts 
b/packages/taler-wallet-core/src/host-impl.qtart.ts
index 8ee3f6539..b4ea04be5 100644
--- a/packages/taler-wallet-core/src/host-impl.qtart.ts
+++ b/packages/taler-wallet-core/src/host-impl.qtart.ts
@@ -45,7 +45,11 @@ import {
 import { createPlatformHttpLib } from "@gnu-taler/taler-util/http";
 import { qjsOs, qjsStd } from "@gnu-taler/taler-util/qtart";
 import { SynchronousCryptoWorkerFactoryPlain } from 
"./crypto/workers/synchronousWorkerFactoryPlain.js";
-import { DefaultNodeWalletArgs, makeTempfileId } from "./host-common.js";
+import {
+  DefaultNodeWalletArgs,
+  getSqlite3FilenameFromStoragePath,
+  makeTempfileId,
+} from "./host-common.js";
 import { Wallet } from "./wallet.js";
 
 const logger = new Logger("host-impl.qtart.ts");
@@ -101,7 +105,9 @@ async function makeSqliteDb(
   args: DefaultNodeWalletArgs,
 ): Promise<MakeDbResult> {
   BridgeIDBFactory.enableTracing = false;
-  let filename = args.persistentStoragePath ?? ":memory:";
+  const filename = getSqlite3FilenameFromStoragePath(
+    args.persistentStoragePath,
+  );
   logger.info(`opening sqlite3 database ${j2s(filename)}`);
   const imp = await createQtartSqlite3Impl();
   const myBackend = await createSqliteBackend(imp, {
diff --git a/packages/taler-wallet-embedded/src/wallet-qjs.ts 
b/packages/taler-wallet-embedded/src/wallet-qjs.ts
index 1ec9e592b..358069d43 100644
--- a/packages/taler-wallet-embedded/src/wallet-qjs.ts
+++ b/packages/taler-wallet-embedded/src/wallet-qjs.ts
@@ -37,7 +37,6 @@ import {
   WalletNotification,
   enableNativeLogging,
   getErrorDetailFromException,
-  j2s,
   openPromise,
   performanceNow,
   setGlobalLogLevelFromString,
@@ -89,37 +88,10 @@ class NativeWalletMessageHandler {
 
     switch (operation) {
       case "init": {
-        // Allow specifying a directory as the storage path.
-        // In that case, we pick the filename and use the sqlite3
-        // backend.
-        //
-        // We still allow specifying a filename for backwards
-        // compatibility and control over the exact file.
-        //
-        // Specifying a directory allows us to automatically
-        // migrate to a new DB file in the future.
-        const p = args.persistentStoragePath;
-        let persistentStoragePath: string | undefined;
-        if (p != null) {
-          if (typeof p !== "string") {
-            throw Error("persistentStoragePath must be a string");
-          }
-          if (p.endsWith("/")) {
-            logger.info(
-              `Specified directory ${j2s(p)} as persistentStoragePath`,
-            );
-            persistentStoragePath = `${p}talerwalletdb-v30.sqlite3`;
-          } else {
-            logger.info(`Specified file ${j2s(p)} as as 
persistentStoragePath`);
-            persistentStoragePath = p;
-          }
-        }
-
         const wR = await createNativeWalletHost2({
           notifyHandler: async (notification: WalletNotification) => {
             sendNativeMessage({ type: "notification", payload: notification });
           },
-          persistentStoragePath,
           httpLib: this.httpLib,
           cryptoWorkerType: args.cryptoWorkerType,
           ...args,

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]