From edec1c7962a9e6f8f2b2850ca68e03fb7f5cbf68 Mon Sep 17 00:00:00 2001 From: ehsan shariati Date: Thu, 28 Nov 2024 20:14:56 -0500 Subject: [PATCH] added deleteDsLock --- .../main/java/land/fx/fula/FulaModule.java | 16 +++++++++++++++ ios/Fula.mm | 3 +++ ios/Fula.swift | 20 +++++++++++++++++++ package.json | 2 +- src/interfaces/fulaNativeModule.ts | 1 + src/protocols/fula.ts | 4 ++++ 6 files changed, 45 insertions(+), 1 deletion(-) diff --git a/android/src/main/java/land/fx/fula/FulaModule.java b/android/src/main/java/land/fx/fula/FulaModule.java index 8e02e39..4ca27b1 100755 --- a/android/src/main/java/land/fx/fula/FulaModule.java +++ b/android/src/main/java/land/fx/fula/FulaModule.java @@ -252,6 +252,22 @@ public void newClient(String identityString, String storePath, String bloxAddr, }); } + @ReactMethod + public void deleteDsLock() { + String lockFilePath = fulaConfig.getStorePath() + "/LOCK"; + Path lockFile = Paths.get(lockFilePath); + try { + if (Files.exists(lockFile)) { + Files.delete(lockFile); + Log.d("ReactNative", "Lock file deleted successfully."); + } else { + Log.d("ReactNative", "Lock file does not exist."); + } + } catch (Exception e) { + Log.d("ReactNative", "Failed to delete lock file: " + e.getMessage()); + } + } + @ReactMethod public void isReady(boolean filesystemCheck, Promise promise) { Log.d("ReactNative", "isReady started"); diff --git a/ios/Fula.mm b/ios/Fula.mm index a527a15..5d1856e 100644 --- a/ios/Fula.mm +++ b/ios/Fula.mm @@ -231,6 +231,9 @@ @interface RCT_EXTERN_MODULE(FulaModule, NSObject) withResolver:(RCTPromiseResolveBlock)resolve withRejecter:(RCTPromiseRejectBlock)reject) +RCT_EXTERN_METHOD(deleteDsLock:(RCTPromiseResolveBlock)resolve + withRejecter:(RCTPromiseRejectBlock)reject) + RCT_EXTERN_METHOD(replicateInPool:(NSArray *)cidArray withAccount:(NSString *)account withPoolID:(NSString *)poolIDStr diff --git a/ios/Fula.swift b/ios/Fula.swift index d481bd0..308062e 100644 --- a/ios/Fula.swift +++ b/ios/Fula.swift @@ -1220,6 +1220,26 @@ class FulaModule: NSObject { } + @objc + func deleteDsLock(_ resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) { + let lockFilePath = (fulaConfig.getStorePath() as NSString).appendingPathComponent("LOCK") + let fileManager = FileManager.default + + do { + if fileManager.fileExists(atPath: lockFilePath) { + try fileManager.removeItem(atPath: lockFilePath) + NSLog("ReactNative: Lock file deleted successfully.") + resolve(true) + } else { + NSLog("ReactNative: Lock file does not exist.") + resolve(false) // Resolve with false if the file doesn't exist + } + } catch let error as NSError { + NSLog("ReactNative: Failed to delete lock file: \(error.localizedDescription)") + reject("delete_error", "Failed to delete lock file", error) + } + } + func shutdownInternal() { NSLog("ReactNative shutdownInternal") if self.fula != nil { diff --git a/package.json b/package.json index 6af7efe..fd2b0a2 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@functionland/react-native-fula", - "version": "1.54.30", + "version": "1.54.31", "description": "This package is a bridge to use the Fula libp2p protocols in the react-native which is using wnfs", "main": "lib/commonjs/index", "module": "lib/module/index", diff --git a/src/interfaces/fulaNativeModule.ts b/src/interfaces/fulaNativeModule.ts index ac69856..bba1568 100644 --- a/src/interfaces/fulaNativeModule.ts +++ b/src/interfaces/fulaNativeModule.ts @@ -145,6 +145,7 @@ interface FulaNativeModule { getInstallOutput: (pluginName: string, params: string) => Promise; getInstallStatus: (pluginName: string) => Promise; updatePlugin: (pluginName: string) => Promise; + deleteDsLock: () => Promise; } const LINKING_ERROR = diff --git a/src/protocols/fula.ts b/src/protocols/fula.ts index 5e1b213..b8d6afd 100644 --- a/src/protocols/fula.ts +++ b/src/protocols/fula.ts @@ -348,6 +348,10 @@ export const isReady = (filesystemCheck: boolean = true): Promise => { return Fula.isReady(filesystemCheck); }; +export const deleteDsLock = (): Promise => { + return Fula.deleteDsLock(); +} + /** * replicate replicates data on the nework */