[#3987] disable logging on status-go side if file is not writable

This commit is contained in:
Roman Volosovskyi 2018-05-01 16:49:16 +02:00
parent 2c7063f96e
commit 0d0be37904
No known key found for this signature in database
GPG Key ID: 0238A4B5ECEE70DE
1 changed files with 7 additions and 3 deletions

View File

@ -122,11 +122,15 @@ class StatusModule extends ReactContextBaseJavaModule implements LifecycleEventL
try {
logFile.setReadable(true);
File parent = logFile.getParentFile();
if (!parent.canWrite()) {
return null;
}
if (!parent.exists()) {
parent.mkdirs();
}
logFile.createNewFile();
logFile.setReadable(true);
logFile.setWritable(true);
Log.d(TAG, "Can write " + logFile.canWrite());
Uri gethLogUri = Uri.fromFile(logFile);
try {
Log.d(TAG, "Attach to geth.log to instabug " + gethLogUri.getPath());
@ -136,7 +140,7 @@ class StatusModule extends ReactContextBaseJavaModule implements LifecycleEventL
}
String gethLogFilePath = logFile.getAbsolutePath();
Log.d("ExtDirLog", gethLogFilePath);
Log.d(TAG, gethLogFilePath);
return gethLogFilePath;
} catch (Exception e) {
@ -215,7 +219,7 @@ class StatusModule extends ReactContextBaseJavaModule implements LifecycleEventL
String gethLogFilePath = prepareLogsFile();
boolean logsEnabled = (gethLogFilePath != null) && !TextUtils.isEmpty(this.logLevel);
String dataDir = root + customConfig.get("DataDir");
jsonConfig.put("LogEnabled", logsEnabled);
jsonConfig.put("LogEnabled", (gethLogFilePath != null && logsEnabled));
jsonConfig.put("LogFile", gethLogFilePath);
jsonConfig.put("LogLevel", TextUtils.isEmpty(this.logLevel) ? "ERROR" : this.logLevel.toUpperCase());
jsonConfig.put("DataDir", dataDir);