diff options
author | Daniel Gultsch <daniel@gultsch.de> | 2016-08-13 12:35:10 +0200 |
---|---|---|
committer | Christian Schneppe <christian@pix-art.de> | 2016-08-13 22:22:49 +0200 |
commit | 1d1b58853c13e6e2c27a07b6b37a340d06562989 (patch) | |
tree | 7f21e8506911686e0712f046831fd61dc26e69dc /src/main/java/de | |
parent | 1ad5b0a248c92eb17b260acd8ede77389495e78d (diff) |
be more careful in recursive file observer. limit depth
Diffstat (limited to '')
-rw-r--r-- | src/main/java/de/pixart/messenger/utils/ConversationsFileObserver.java | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/src/main/java/de/pixart/messenger/utils/ConversationsFileObserver.java b/src/main/java/de/pixart/messenger/utils/ConversationsFileObserver.java index 44cdc5100..fbd4c9708 100644 --- a/src/main/java/de/pixart/messenger/utils/ConversationsFileObserver.java +++ b/src/main/java/de/pixart/messenger/utils/ConversationsFileObserver.java @@ -37,7 +37,10 @@ public abstract class ConversationsFileObserver { } for(File file : files) { if (file.isDirectory() && !file.getName().equals(".") && !file.getName().equals("..")) { - stack.push(file.getPath()); + final String currentPath = file.getAbsolutePath(); + if (depth(file) <= 8 && !stack.contains(currentPath) && !observing(currentPath)) { + stack.push(currentPath); + } } } } @@ -46,6 +49,23 @@ public abstract class ConversationsFileObserver { } } + private static int depth(File file) { + int depth = 0; + while((file = file.getParentFile()) != null) { + depth++; + } + return depth; + } + + private boolean observing(String path) { + for(SingleFileObserver observer : mObservers) { + if(path.equals(observer.path)) { + return true; + } + } + return false; + } + public synchronized void stopWatching() { for(FileObserver observer : mObservers) { observer.stopWatching(); |