[#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;
|
return logFile;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String prepareLogsFile(final Context context) {
|
private File prepareLogsFile(final Context context) {
|
||||||
final File logFile = getLogsFile();
|
final File logFile = getLogsFile();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -185,7 +185,7 @@ class StatusModule extends ReactContextBaseJavaModule implements LifecycleEventL
|
||||||
String gethLogFilePath = logFile.getAbsolutePath();
|
String gethLogFilePath = logFile.getAbsolutePath();
|
||||||
Log.d(TAG, gethLogFilePath);
|
Log.d(TAG, gethLogFilePath);
|
||||||
|
|
||||||
return gethLogFilePath;
|
return logFile;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Log.d(TAG, "Can't create geth.log file! " + e.getMessage());
|
Log.d(TAG, "Can't create geth.log file! " + e.getMessage());
|
||||||
}
|
}
|
||||||
|
@ -193,17 +193,24 @@ class StatusModule extends ReactContextBaseJavaModule implements LifecycleEventL
|
||||||
return null;
|
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);
|
final JSONObject jsonConfig = new JSONObject(jsonConfigString);
|
||||||
// retrieve parameters from app config, that will be applied onto the Go-side config later on
|
// 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 Boolean logEnabled = jsonConfig.getBoolean("LogEnabled");
|
||||||
final Context context = this.getReactApplicationContext();
|
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);
|
Log.d(TAG, "log dir: " + gethLogDirPath + " log name: " + gethLogFileName);
|
||||||
jsonConfig.put("KeyStoreDir", absKeystoreDirPath);
|
|
||||||
jsonConfig.put("LogFile", gethLogFilePath);
|
jsonConfig.put("DataDir", dataDirPath);
|
||||||
|
jsonConfig.put("KeyStoreDir", keystoreDirPath);
|
||||||
|
jsonConfig.put("LogDir", gethLogDirPath);
|
||||||
|
jsonConfig.put("LogFile", gethLogFileName);
|
||||||
|
|
||||||
return jsonConfig.toString();
|
return jsonConfig.toString();
|
||||||
}
|
}
|
||||||
|
@ -291,7 +298,7 @@ class StatusModule extends ReactContextBaseJavaModule implements LifecycleEventL
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
final String updatedJsonConfigString = this.updateConfig(jsonConfigString, absRootDirPath, newKeystoreDir);
|
final String updatedJsonConfigString = this.updateConfig(jsonConfigString, absRootDirPath, "/keystore");
|
||||||
|
|
||||||
prettyPrintConfig(updatedJsonConfigString);
|
prettyPrintConfig(updatedJsonConfigString);
|
||||||
|
|
||||||
|
|
|
@ -325,8 +325,9 @@ RCT_EXPORT_METHOD(multiAccountDeriveAddresses:(NSString *)json
|
||||||
|
|
||||||
NSLog(@"after remove lightchaindata");
|
NSLog(@"after remove lightchaindata");
|
||||||
|
|
||||||
NSURL *absTestnetKeystoreUrl = [absTestnetFolderName URLByAppendingPathComponent:@"keystore"];
|
NSString *keystore = @"keystore";
|
||||||
NSURL *absKeystoreUrl = [rootUrl URLByAppendingPathComponent:@"keystore"];
|
NSURL *absTestnetKeystoreUrl = [absTestnetFolderName URLByAppendingPathComponent:keystore];
|
||||||
|
NSURL *absKeystoreUrl = [rootUrl URLByAppendingPathComponent:keystore];
|
||||||
if([fileManager fileExistsAtPath:absTestnetKeystoreUrl.path]){
|
if([fileManager fileExistsAtPath:absTestnetKeystoreUrl.path]){
|
||||||
NSLog(@"copy keystore");
|
NSLog(@"copy keystore");
|
||||||
[fileManager copyItemAtPath:absTestnetKeystoreUrl.path toPath:absKeystoreUrl.path error:nil];
|
[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 *relativeDataDir = [configJSON objectForKey:@"DataDir"];
|
||||||
NSString *absDataDir = [rootUrl.path stringByAppendingString:relativeDataDir];
|
NSString *absDataDir = [rootUrl.path stringByAppendingString:relativeDataDir];
|
||||||
NSURL *absDataDirUrl = [NSURL fileURLWithPath:absDataDir];
|
NSURL *absDataDirUrl = [NSURL fileURLWithPath:absDataDir];
|
||||||
NSURL *absLogUrl = [absDataDirUrl URLByAppendingPathComponent:@"geth.log"];
|
NSURL *dataDirUrl = [NSURL fileURLWithPath:relativeDataDir];
|
||||||
[configJSON setValue:absDataDirUrl.path forKey:@"DataDir"];
|
NSURL *logUrl = [dataDirUrl URLByAppendingPathComponent:@"geth.log"];
|
||||||
[configJSON setValue:absKeystoreUrl.path forKey:@"KeyStoreDir"];
|
[configJSON setValue:@"/keystore" forKey:@"KeyStoreDir"];
|
||||||
[configJSON setValue:absLogUrl.path forKey:@"LogFile"];
|
[configJSON setValue:@"" forKey:@"LogDir"];
|
||||||
|
[configJSON setValue:logUrl.path forKey:@"LogFile"];
|
||||||
|
|
||||||
NSString *resultingConfig = [configJSON bv_jsonStringWithPrettyPrint:NO];
|
NSString *resultingConfig = [configJSON bv_jsonStringWithPrettyPrint:NO];
|
||||||
NSLog(@"node config %@", resultingConfig);
|
NSLog(@"node config %@", resultingConfig);
|
||||||
|
|
||||||
if(![fileManager fileExistsAtPath:absDataDirUrl.path]) {
|
if(![fileManager fileExistsAtPath:absDataDir]) {
|
||||||
[fileManager createDirectoryAtPath:absDataDirUrl.path withIntermediateDirectories:YES attributes:nil error:nil];
|
[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]) {
|
if(![fileManager fileExistsAtPath:absLogUrl.path]) {
|
||||||
NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
|
NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
|
||||||
[dict setObject:[NSNumber numberWithInt:511] forKey:NSFilePosixPermissions];
|
[dict setObject:[NSNumber numberWithInt:511] forKey:NSFilePosixPermissions];
|
||||||
|
|
|
@ -33,9 +33,8 @@
|
||||||
|
|
||||||
(defn no-backup-directory []
|
(defn no-backup-directory []
|
||||||
(cond
|
(cond
|
||||||
android? (str (.-DocumentDirectoryPath rn-dependencies/fs)
|
android? "/../no_backup"
|
||||||
"/../no_backup")
|
ios? "/"))
|
||||||
ios? (.-LibraryDirectoryPath rn-dependencies/fs)))
|
|
||||||
|
|
||||||
(defn android-version>= [v]
|
(defn android-version>= [v]
|
||||||
(and 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",
|
"_comment": "DO NOT EDIT THIS FILE BY HAND. USE 'scripts/update-status-go.sh <tag>' instead",
|
||||||
"owner": "status-im",
|
"owner": "status-im",
|
||||||
"repo": "status-go",
|
"repo": "status-go",
|
||||||
"version": "v0.41.1",
|
"version": "v0.42.0",
|
||||||
"commit-sha1": "c2f22f1fbc73e68b8d82370c4645c786739fb40b",
|
"commit-sha1": "9cf640842b4d0266bcc1b30f6d776c250fdb5c04",
|
||||||
"src-sha256": "038paj2gwdih154nnafcxc3w02x9p21ifkv1g9k2rr1ac0ypainb"
|
"src-sha256": "0h8da2w3fbgrv6rmd4pib46r97g5q2wwg4a790f91dadsl67pmcl"
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue