From ef49699222ca13a9f01e0dfc87f3319fa494f94b Mon Sep 17 00:00:00 2001 From: Roman Volosovskyi Date: Fri, 31 Jan 2020 14:43:32 +0200 Subject: [PATCH] [#9942] Upgradable paths in configs Storing absolute path for different configs breaks compatibility on iOS as app's dir is changed after upgrade. The solution is to store relative paths and to concatenate it with `backend.rootDataDir`. The only exception is `LogFile` as it is stored outside `backend.rootDataDir` on Android. `LogDir` config was added to allow adding of custom dir for log file. Configs concerned: `DataDir` `LogDir` `LogFile` `KeystoreDir` `BackupDisabledDataDir` --- .../status/ethereum/module/StatusModule.java | 25 ++++++++++++------- .../ios/RCTStatus/RCTStatus.m | 22 +++++++++------- src/status_im/utils/platform.cljs | 5 ++-- status-go-version.json | 6 ++--- 4 files changed, 34 insertions(+), 24 deletions(-) diff --git a/modules/react-native-status/android/src/main/java/im/status/ethereum/module/StatusModule.java b/modules/react-native-status/android/src/main/java/im/status/ethereum/module/StatusModule.java index 3eb208e9f9..a29f2a6507 100644 --- a/modules/react-native-status/android/src/main/java/im/status/ethereum/module/StatusModule.java +++ b/modules/react-native-status/android/src/main/java/im/status/ethereum/module/StatusModule.java @@ -165,7 +165,7 @@ class StatusModule extends ReactContextBaseJavaModule implements LifecycleEventL return logFile; } - private String prepareLogsFile(final Context context) { + private File prepareLogsFile(final Context context) { final File logFile = getLogsFile(); try { @@ -185,7 +185,7 @@ class StatusModule extends ReactContextBaseJavaModule implements LifecycleEventL String gethLogFilePath = logFile.getAbsolutePath(); Log.d(TAG, gethLogFilePath); - return gethLogFilePath; + return logFile; } catch (Exception e) { Log.d(TAG, "Can't create geth.log file! " + e.getMessage()); } @@ -193,17 +193,24 @@ class StatusModule extends ReactContextBaseJavaModule implements LifecycleEventL return null; } - private String updateConfig(final String jsonConfigString, final String absRootDirPath, final String absKeystoreDirPath) throws JSONException { + private String updateConfig(final String jsonConfigString, final String absRootDirPath, final String keystoreDirPath) throws JSONException { final JSONObject jsonConfig = new JSONObject(jsonConfigString); // retrieve parameters from app config, that will be applied onto the Go-side config later on - final String absDataDirPath = pathCombine(absRootDirPath, jsonConfig.getString("DataDir")); + final String dataDirPath = jsonConfig.getString("DataDir"); final Boolean logEnabled = jsonConfig.getBoolean("LogEnabled"); final Context context = this.getReactApplicationContext(); - final String gethLogFilePath = logEnabled ? prepareLogsFile(context) : null; + final File gethLogFile = logEnabled ? prepareLogsFile(context) : null; + String gethLogDirPath = null; + if (gethLogFile != null) { + gethLogDirPath = gethLogFile.getParent(); + } - jsonConfig.put("DataDir", absDataDirPath); - jsonConfig.put("KeyStoreDir", absKeystoreDirPath); - jsonConfig.put("LogFile", gethLogFilePath); + Log.d(TAG, "log dir: " + gethLogDirPath + " log name: " + gethLogFileName); + + jsonConfig.put("DataDir", dataDirPath); + jsonConfig.put("KeyStoreDir", keystoreDirPath); + jsonConfig.put("LogDir", gethLogDirPath); + jsonConfig.put("LogFile", gethLogFileName); return jsonConfig.toString(); } @@ -291,7 +298,7 @@ class StatusModule extends ReactContextBaseJavaModule implements LifecycleEventL } try { - final String updatedJsonConfigString = this.updateConfig(jsonConfigString, absRootDirPath, newKeystoreDir); + final String updatedJsonConfigString = this.updateConfig(jsonConfigString, absRootDirPath, "/keystore"); prettyPrintConfig(updatedJsonConfigString); diff --git a/modules/react-native-status/ios/RCTStatus/RCTStatus.m b/modules/react-native-status/ios/RCTStatus/RCTStatus.m index 93f1646a50..eabfb17050 100644 --- a/modules/react-native-status/ios/RCTStatus/RCTStatus.m +++ b/modules/react-native-status/ios/RCTStatus/RCTStatus.m @@ -325,8 +325,9 @@ RCT_EXPORT_METHOD(multiAccountDeriveAddresses:(NSString *)json NSLog(@"after remove lightchaindata"); - NSURL *absTestnetKeystoreUrl = [absTestnetFolderName URLByAppendingPathComponent:@"keystore"]; - NSURL *absKeystoreUrl = [rootUrl URLByAppendingPathComponent:@"keystore"]; + NSString *keystore = @"keystore"; + NSURL *absTestnetKeystoreUrl = [absTestnetFolderName URLByAppendingPathComponent:keystore]; + NSURL *absKeystoreUrl = [rootUrl URLByAppendingPathComponent:keystore]; if([fileManager fileExistsAtPath:absTestnetKeystoreUrl.path]){ NSLog(@"copy keystore"); [fileManager copyItemAtPath:absTestnetKeystoreUrl.path toPath:absKeystoreUrl.path error:nil]; @@ -341,19 +342,22 @@ RCT_EXPORT_METHOD(multiAccountDeriveAddresses:(NSString *)json NSString *relativeDataDir = [configJSON objectForKey:@"DataDir"]; NSString *absDataDir = [rootUrl.path stringByAppendingString:relativeDataDir]; NSURL *absDataDirUrl = [NSURL fileURLWithPath:absDataDir]; - NSURL *absLogUrl = [absDataDirUrl URLByAppendingPathComponent:@"geth.log"]; - [configJSON setValue:absDataDirUrl.path forKey:@"DataDir"]; - [configJSON setValue:absKeystoreUrl.path forKey:@"KeyStoreDir"]; - [configJSON setValue:absLogUrl.path forKey:@"LogFile"]; + NSURL *dataDirUrl = [NSURL fileURLWithPath:relativeDataDir]; + NSURL *logUrl = [dataDirUrl URLByAppendingPathComponent:@"geth.log"]; + [configJSON setValue:@"/keystore" forKey:@"KeyStoreDir"]; + [configJSON setValue:@"" forKey:@"LogDir"]; + [configJSON setValue:logUrl.path forKey:@"LogFile"]; NSString *resultingConfig = [configJSON bv_jsonStringWithPrettyPrint:NO]; NSLog(@"node config %@", resultingConfig); - if(![fileManager fileExistsAtPath:absDataDirUrl.path]) { - [fileManager createDirectoryAtPath:absDataDirUrl.path withIntermediateDirectories:YES attributes:nil error:nil]; + if(![fileManager fileExistsAtPath:absDataDir]) { + [fileManager createDirectoryAtPath:absDataDir + withIntermediateDirectories:YES attributes:nil error:nil]; } - NSLog(@"logUrlPath %@", absLogUrl.path); + NSLog(@"logUrlPath %@ rootDir %@", logUrl.path, rootUrl.path); + NSURL *absLogUrl = [absDataDirUrl URLByAppendingPathComponent:@"geth.log"]; if(![fileManager fileExistsAtPath:absLogUrl.path]) { NSMutableDictionary *dict = [[NSMutableDictionary alloc] init]; [dict setObject:[NSNumber numberWithInt:511] forKey:NSFilePosixPermissions]; diff --git a/src/status_im/utils/platform.cljs b/src/status_im/utils/platform.cljs index 5cc3f167d5..cbc9274404 100644 --- a/src/status_im/utils/platform.cljs +++ b/src/status_im/utils/platform.cljs @@ -33,9 +33,8 @@ (defn no-backup-directory [] (cond - android? (str (.-DocumentDirectoryPath rn-dependencies/fs) - "/../no_backup") - ios? (.-LibraryDirectoryPath rn-dependencies/fs))) + android? "/../no_backup" + ios? "/")) (defn android-version>= [v] (and android? (>= version v))) diff --git a/status-go-version.json b/status-go-version.json index b7beeea583..4a9097343c 100644 --- a/status-go-version.json +++ b/status-go-version.json @@ -2,7 +2,7 @@ "_comment": "DO NOT EDIT THIS FILE BY HAND. USE 'scripts/update-status-go.sh ' instead", "owner": "status-im", "repo": "status-go", - "version": "v0.41.1", - "commit-sha1": "c2f22f1fbc73e68b8d82370c4645c786739fb40b", - "src-sha256": "038paj2gwdih154nnafcxc3w02x9p21ifkv1g9k2rr1ac0ypainb" + "version": "v0.42.0", + "commit-sha1": "9cf640842b4d0266bcc1b30f6d776c250fdb5c04", + "src-sha256": "0h8da2w3fbgrv6rmd4pib46r97g5q2wwg4a790f91dadsl67pmcl" }