From 77675c90d800f8c67acc27082fbe20c8562cb233 Mon Sep 17 00:00:00 2001 From: Christian Schneppe Date: Sun, 18 Apr 2021 21:56:13 +0200 Subject: [PATCH] catch exception in expireOldFiles() --- .../persistance/FileBackend.java | 48 +++++++++++-------- 1 file changed, 27 insertions(+), 21 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/persistance/FileBackend.java b/src/main/java/eu/siacs/conversations/persistance/FileBackend.java index ea384c2c2..084c4b882 100644 --- a/src/main/java/eu/siacs/conversations/persistance/FileBackend.java +++ b/src/main/java/eu/siacs/conversations/persistance/FileBackend.java @@ -251,32 +251,38 @@ public class FileBackend { } public void expireOldFiles(File dir, long timestamp) { - long start = SystemClock.elapsedRealtime(); - int num = 0; - if (dir == null) { - return; - } - Stack dirlist = new Stack(); - dirlist.clear(); - dirlist.push(dir); - while (!dirlist.isEmpty()) { - File dirCurrent = dirlist.pop(); - File[] fileList = dirCurrent.listFiles(); - for (File file : fileList) { - if (file.isDirectory()) { - dirlist.push(file); - } else { - if (file.exists() && !file.getName().equalsIgnoreCase(".nomedia")) { - long lastModified = file.lastModified(); - if (lastModified < timestamp) { - num++; - deleteFile(file); + try { + long start = SystemClock.elapsedRealtime(); + int num = 0; + if (dir == null) { + return; + } + Stack dirlist = new Stack(); + dirlist.clear(); + dirlist.push(dir); + while (!dirlist.isEmpty()) { + File dirCurrent = dirlist.pop(); + File[] fileList = dirCurrent.listFiles(); + if (fileList != null) { + for (File file : fileList) { + if (file.isDirectory()) { + dirlist.push(file); + } else { + if (file.exists() && !file.getName().equalsIgnoreCase(".nomedia")) { + long lastModified = file.lastModified(); + if (lastModified < timestamp) { + num++; + deleteFile(file); + } + } } } } } + Log.d(Config.LOGTAG, "deleted " + num + " expired files in " + (SystemClock.elapsedRealtime() - start) + "ms"); + } catch (Exception e) { + e.printStackTrace(); } - Log.d(Config.LOGTAG, "deleted " + num + " expired files in " + (SystemClock.elapsedRealtime() - start) + "ms"); } public void deleteFilesInDir(File dir) {