Skip to content

Commit

Permalink
added deleteDsLock
Browse files Browse the repository at this point in the history
  • Loading branch information
ehsan6sha committed Nov 29, 2024
1 parent a429aab commit edec1c7
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 1 deletion.
16 changes: 16 additions & 0 deletions android/src/main/java/land/fx/fula/FulaModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
3 changes: 3 additions & 0 deletions ios/Fula.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 20 additions & 0 deletions ios/Fula.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
1 change: 1 addition & 0 deletions src/interfaces/fulaNativeModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ interface FulaNativeModule {
getInstallOutput: (pluginName: string, params: string) => Promise<string>;
getInstallStatus: (pluginName: string) => Promise<string>;
updatePlugin: (pluginName: string) => Promise<string>;
deleteDsLock: () => Promise<void>;
}

const LINKING_ERROR =
Expand Down
4 changes: 4 additions & 0 deletions src/protocols/fula.ts
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,10 @@ export const isReady = (filesystemCheck: boolean = true): Promise<boolean> => {
return Fula.isReady(filesystemCheck);
};

export const deleteDsLock = (): Promise<void> => {
return Fula.deleteDsLock();
}

/**
* replicate replicates data on the nework
*/
Expand Down

0 comments on commit edec1c7

Please sign in to comment.