Skip to content

Commit

Permalink
Make sure to re-add WatchKey so that events continue to be monitored.
Browse files Browse the repository at this point in the history
  • Loading branch information
lincolnthree committed Jan 9, 2014
1 parent 45eb9b9 commit 7508981
Showing 1 changed file with 25 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import java.io.IOException;
import java.nio.file.FileSystems;
import java.nio.file.StandardWatchEventKinds;
import java.nio.file.WatchEvent;
import java.nio.file.WatchKey;
import java.nio.file.WatchService;
import java.util.ArrayList;
Expand Down Expand Up @@ -167,15 +168,20 @@ public Furnace start(ClassLoader loader)
dirty = true;
}

WatchKey key = watcher.poll();
while (key != null)
}

WatchKey key = watcher.poll();
while (key != null)
{
List<WatchEvent<?>> events = key.pollEvents();
if (!events.isEmpty())
{
if (!key.pollEvents().isEmpty())
{
dirty = true;
}
key = watcher.poll();
logger.log(Level.INFO, "Detected changes in repository [" + events.iterator().next().context()
+ "].");
dirty = true;
}
key.reset();
key = watcher.poll();
}

if (dirty)
Expand Down Expand Up @@ -382,11 +388,20 @@ public AddonRepository addRepository(AddonRepositoryMode mode, File directory)
{
if (watcher != null)
{
if (directory.exists())
directory.toPath().register(watcher, StandardWatchEventKinds.ENTRY_MODIFY);
if ((directory.exists() && directory.isDirectory()) || directory.mkdirs())
{
directory.toPath().register(watcher,
StandardWatchEventKinds.ENTRY_MODIFY,
StandardWatchEventKinds.ENTRY_CREATE,
StandardWatchEventKinds.ENTRY_DELETE,
StandardWatchEventKinds.OVERFLOW);
logger.log(Level.INFO, "Monitoring repository [" + directory.toString() + "] for file changes.");
}
else
{
logger.log(Level.WARNING, "Cannot monitor repository [" + directory
+ "] for changes because it does not exist.");
+ "] for changes because it is not a directory.");
}
}
}
catch (IOException e)
Expand Down

0 comments on commit 7508981

Please sign in to comment.