diff --git a/core/src/main/groovy/com/muwire/core/Core.groovy b/core/src/main/groovy/com/muwire/core/Core.groovy index aff08214..8043faf9 100644 --- a/core/src/main/groovy/com/muwire/core/Core.groovy +++ b/core/src/main/groovy/com/muwire/core/Core.groovy @@ -430,6 +430,7 @@ public class Core { register(DirectoryWatchedEvent.class, directoryWatcher) register(WatchedDirectoryConvertedEvent.class, directoryWatcher) register(DirectoryUnsharedEvent.class, directoryWatcher) + register(WatchedDirectoryConfigurationEvent.class, directoryWatcher) } } diff --git a/core/src/main/groovy/com/muwire/core/files/DirectoryWatcher.groovy b/core/src/main/groovy/com/muwire/core/files/DirectoryWatcher.groovy index dca090b8..29a907f5 100644 --- a/core/src/main/groovy/com/muwire/core/files/DirectoryWatcher.groovy +++ b/core/src/main/groovy/com/muwire/core/files/DirectoryWatcher.groovy @@ -15,6 +15,7 @@ import java.util.concurrent.ConcurrentHashMap import com.muwire.core.EventBus import com.muwire.core.MuWireSettings import com.muwire.core.SharedFile +import com.muwire.core.files.directories.WatchedDirectoryConfigurationEvent import com.muwire.core.files.directories.WatchedDirectoryConvertedEvent import com.muwire.core.files.directories.WatchedDirectoryManager @@ -80,6 +81,19 @@ class DirectoryWatcher { wk?.cancel() } + void onWatchedDirectoryConfigurationEvent(WatchedDirectoryConfigurationEvent e) { + if (watchService == null) + return // still converting + if (!e.autoWatch) { + WatchKey wk = watchedDirectories.remove(e.directory) + wk?.cancel() + } else if (!watchedDirectories.containsKey(e.directory)) { + Path path = e.directory.toPath() + def wk = path.register(watchService, kinds) + watchedDirectories.put(e.directory, wk) + } // else it was already watched + } + private void watch() { try { while(!shutdown) { diff --git a/core/src/main/groovy/com/muwire/core/files/directories/WatchedDirectoryManager.groovy b/core/src/main/groovy/com/muwire/core/files/directories/WatchedDirectoryManager.groovy index a90286a9..5bf8f983 100644 --- a/core/src/main/groovy/com/muwire/core/files/directories/WatchedDirectoryManager.groovy +++ b/core/src/main/groovy/com/muwire/core/files/directories/WatchedDirectoryManager.groovy @@ -61,7 +61,14 @@ class WatchedDirectoryManager { newDir.autoWatch = e.autoWatch persist(newDir) } else { - // TODO: update state and stuff + def wd = watchedDirs.get(e.directory) + if (wd == null) { + log.severe("got a configuration event for a non-watched directory ${e.directory}") + return + } + wd.autoWatch = e.autoWatch + wd.syncInterval = e.syncInterval + persist(wd) } }