Skip to content

Commit

Permalink
[#9942] Upgradable paths in configs
Browse files Browse the repository at this point in the history
  • Loading branch information
rasom committed Jan 31, 2020
1 parent b2feca7 commit e919283
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ private File getLogsFile() {
return logFile;
}

private String prepareLogsFile(final Context context) {
private File prepareLogsFile(final Context context) {
final File logFile = getLogsFile();

try {
Expand All @@ -185,25 +185,32 @@ private String prepareLogsFile(final Context context) {
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());
}

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();
}

Log.d(TAG, "log dir: " + gethLogDirPath + " log name: " + gethLogFileName);

jsonConfig.put("DataDir", absDataDirPath);
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();
}
Expand Down Expand Up @@ -291,7 +298,7 @@ private String prepareDirAndUpdateConfig(final String jsonConfigString) {
}

try {
final String updatedJsonConfigString = this.updateConfig(jsonConfigString, absRootDirPath, newKeystoreDir);
final String updatedJsonConfigString = this.updateConfig(jsonConfigString, absRootDirPath, "/keystore");

prettyPrintConfig(updatedJsonConfigString);

Expand Down
22 changes: 13 additions & 9 deletions modules/react-native-status/ios/RCTStatus/RCTStatus.m
Original file line number Diff line number Diff line change
Expand Up @@ -325,8 +325,9 @@ -(NSString *) prepareDirAndUpdateConfig:(NSString *)config {

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];
Expand All @@ -341,19 +342,22 @@ -(NSString *) prepareDirAndUpdateConfig:(NSString *)config {
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];
Expand Down
5 changes: 2 additions & 3 deletions src/status_im/utils/platform.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
6 changes: 3 additions & 3 deletions status-go-version.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": "relative-paths",
"commit-sha1": "992168b11451821a5a7115279e8f06a997b07421",
"src-sha256": "13i05il27h4x7c956314q5hv84ww983s4hvrv4m217f5a0bgbrzg"
}

0 comments on commit e919283

Please sign in to comment.