Skip to content

Commit

Permalink
fix: retrieve all files when deleting oldest file
Browse files Browse the repository at this point in the history
alters the filestore so that it obtains all files (including from the legacy directory) when the max
number of files is reached, and the oldest file needs to be deleted
  • Loading branch information
fractalwrench committed Apr 25, 2018
1 parent 9afb2be commit f69ec3a
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions sdk/src/main/java/com/bugsnag/android/FileStore.java
Expand Up @@ -10,6 +10,7 @@
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

Expand Down Expand Up @@ -56,14 +57,16 @@ String write(@NonNull T streamable) {

// Limit number of saved errors to prevent disk space issues
if (storageDir.isDirectory()) {
File[] files = storageDir.listFiles();
if (files != null && files.length >= maxStoreCount) {
List<File> storedFiles = findStoredFiles();

if (storedFiles.size() >= maxStoreCount) {
// Sort files then delete the first one (oldest timestamp)
Arrays.sort(files, comparator);
Collections.sort(storedFiles, comparator);
File oldestFile = storedFiles.get(0);
Logger.warn(String.format("Discarding oldest error as stored "
+ "error limit reached (%s)", files[0].getPath()));
if (!files[0].delete()) {
files[0].deleteOnExit();
+ "error limit reached (%s)", oldestFile.getPath()));
if (!oldestFile.delete()) {
oldestFile.deleteOnExit();
}
}
}
Expand Down

0 comments on commit f69ec3a

Please sign in to comment.