aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/eu
diff options
context:
space:
mode:
authorDaniel Gultsch <daniel@gultsch.de>2016-08-13 12:35:10 +0200
committerDaniel Gultsch <daniel@gultsch.de>2016-08-13 12:35:10 +0200
commiteb8b6165d7c53bc8ed278c9f577d01900533850f (patch)
tree975c6935d94f0d2b5bc93d1bc913d1a4231d3134 /src/main/java/eu
parent8b6f06f0f94b08cdcc300d3308d37969e5d81bd4 (diff)
be more careful in recursive file observer. limit depth
Diffstat (limited to 'src/main/java/eu')
-rw-r--r--src/main/java/eu/siacs/conversations/utils/ConversationsFileObserver.java22
1 files changed, 21 insertions, 1 deletions
diff --git a/src/main/java/eu/siacs/conversations/utils/ConversationsFileObserver.java b/src/main/java/eu/siacs/conversations/utils/ConversationsFileObserver.java
index e6993bfe..ab4dead8 100644
--- a/src/main/java/eu/siacs/conversations/utils/ConversationsFileObserver.java
+++ b/src/main/java/eu/siacs/conversations/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();