Skip to content

Commit

Permalink
Fix LogFileCollector to work with getFilesDir() sub-directories
Browse files Browse the repository at this point in the history
context.openFileInput() name parameter can not contain path separators. So when a relative log file path is passed to ACRA config, we have to build full path to the file, then open it with FileInputStream().
  • Loading branch information
gregd committed Dec 4, 2015
1 parent 3f21616 commit 28bd89c
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/main/java/org/acra/collector/LogFileCollector.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,15 @@ public static String collectLogFile(Context context, String fileName, int number

private static BufferedReader getReader(Context context, String fileName) {
try {
if (fileName.contains("/")) {
return new BufferedReader(new InputStreamReader(new FileInputStream(fileName)), 1024);
FileInputStream inputStream;
if (fileName.startsWith("/")) {
inputStream = new FileInputStream(fileName);
} else if (fileName.contains("/")) {
inputStream = new FileInputStream(context.getFilesDir() + File.separator + fileName);
} else {
return new BufferedReader(new InputStreamReader(context.openFileInput(fileName)), 1024);
inputStream = context.openFileInput(fileName);
}
return new BufferedReader(new InputStreamReader(inputStream), 1024);
} catch (FileNotFoundException e) {
ACRA.log.e(LOG_TAG, "Cannot find application log file : '" + ACRA.getConfig().applicationLogFile() + "'");
return new BufferedReader(new InputStreamReader(new ByteArrayInputStream(new byte[0])));
Expand Down

0 comments on commit 28bd89c

Please sign in to comment.