be more careful in recursive file observer. limit depth

This commit is contained in:
Daniel Gultsch 2016-08-13 12:35:10 +02:00
parent 8b6f06f0f9
commit eb8b6165d7
1 changed files with 21 additions and 1 deletions

View File

@ -37,7 +37,10 @@ public abstract class ConversationsFileObserver {
} }
for(File file : files) { for(File file : files) {
if (file.isDirectory() && !file.getName().equals(".") && !file.getName().equals("..")) { 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() { public synchronized void stopWatching() {
for(FileObserver observer : mObservers) { for(FileObserver observer : mObservers) {
observer.stopWatching(); observer.stopWatching();