commit 830055f1bc874ae7d4278acf3f845eafa28874e7
parent 6dcacc8d56fbdc05e4d0126aa2b0e2c542be439a
Author: Marc Stibane <marc@taler.net>
Date: Thu, 19 Dec 2024 20:50:02 +0100
exportDbToFile
Diffstat:
1 file changed, 39 insertions(+), 2 deletions(-)
diff --git a/TalerWallet1/Model/WalletModel.swift b/TalerWallet1/Model/WalletModel.swift
@@ -285,12 +285,16 @@ extension WalletModel {
}
}
- private func dbPath () throws -> String {
+ private func dbPath(_ export:Bool = false) throws -> String {
if #available(iOS 16.0, *) {
let documents = URL.documentsDirectory // accessible by FileSharing
+ let docsPath = documents.path(percentEncoded: false)
+ if export {
+ return docsPath
+ }
let appSupport = URL.applicationSupportDirectory
#if DEBUG || GNU_TALER
- return documents.path(percentEncoded: false)
+ return docsPath
#else // TALER_WALLET
migrate(from: documents, to: appSupport)
return appSupport.path(percentEncoded: false)
@@ -300,6 +304,9 @@ extension WalletModel {
let appDirNr: FileManager.SearchPathDirectory = .applicationSupportDirectory
if let documentsDir = FileManager.default.urls(for: docDirNr, in: .userDomainMask).first,
let appSupportDir = FileManager.default.urls(for: appDirNr, in: .userDomainMask).first {
+ if export {
+ return path(documentsDir)
+ }
#if DEBUG || GNU_TALER
return path(documentsDir)
#else
@@ -353,6 +360,36 @@ extension WalletModel {
}
}
// MARK: -
+fileprivate struct ExportDbToFile: WalletBackendFormattedRequest {
+ func operation() -> String { "exportDbToFile" }
+ func args() -> Args { Args(directory: directory, stem: stem) }
+
+ var directory: String
+ var stem: String
+ struct Args: Encodable {
+ var directory: String
+ var stem: String
+ } // no arguments needed
+ struct Response: Decodable, Sendable { // path of the copied DB
+ var path: String
+ }
+}
+
+extension WalletModel {
+ /// export DB
+ nonisolated func exportDbToFile(viewHandles: Bool = false)
+ async throws -> String? {
+ if let dbPath = try? dbPath(true) {
+ let stem = String("Taler " + TalerDater.dateString())
+ let request = ExportDbToFile(directory: dbPath, stem: stem)
+ let response = try await sendRequest(request, 0, viewHandles: viewHandles)
+ return response.path
+ } else {
+ return nil
+ }
+ }
+}
+// MARK: -
fileprivate struct DevExperimentRequest: WalletBackendFormattedRequest {
func operation() -> String { "applyDevExperiment" }
func args() -> Args { Args(devExperimentUri: talerUri) }