[#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`
This commit is contained in:
parent
e0bafb842e
commit
ef49699222
|
@ -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);
|
||||
|
||||
|
|
|
@ -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];
|
||||
|
|
|
@ -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)))
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
"_comment": "DO NOT EDIT THIS FILE BY HAND. USE 'scripts/update-status-go.sh <tag>' 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"
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue