Menu

#4 DirWatcher does not monitor after initial notification

open
nobody
None
5
2009-05-14
2009-05-14
Anonymous
No

the watched directory is never added to the "dirs" map. The "watchDirectory" code should be changed to:

public void watchDirectory(DirChangedListener l, File dir,
boolean initialNotify) {
WatchedDir w = (WatchedDir) dirs.get(dir);

if (w == null) {
// New file; read its dir and stuff
String[] files = dir.list();
StringSortable.sortArray(files, SelectionSorter.get());
w = new WatchedDir(files);
dirs.put(dir, w);
dw.fw.watchFile(dw, dir);

} else if (w.who.indexOf(l) != -1) {
// duplicate request; ignore
return;
}

w.who.addElement(l);

// Fake notification?
if (initialNotify) {
for (int i = 0; i < w.files.length; ++i) {
l.handleFileCreated(this, dir, new File(dir, w.files[i]));
}
}
}

*Note that the important line is "dirs.put(dir, w);"

Discussion


Log in to post a comment.