Author: gnodet
Date: Thu Oct 15 10:16:01 2009
New Revision: 825455
URL: http://svn.apache.org/viewvc?rev=825455&view=rev
Log:
FELIX-1572: fileinstall runs into an infinite loop while watching multiple
directories, one of which is itself
Modified:
felix/trunk/fileinstall/src/main/java/org/apache/felix/fileinstall/internal/DirectoryWatcher.java
felix/trunk/fileinstall/src/main/java/org/apache/felix/fileinstall/internal/FileInstall.java
Modified:
felix/trunk/fileinstall/src/main/java/org/apache/felix/fileinstall/internal/DirectoryWatcher.java
URL:
http://svn.apache.org/viewvc/felix/trunk/fileinstall/src/main/java/org/apache/felix/fileinstall/internal/DirectoryWatcher.java?rev=825455&r1=825454&r2=825455&view=diff
==============================================================================
---
felix/trunk/fileinstall/src/main/java/org/apache/felix/fileinstall/internal/DirectoryWatcher.java
(original)
+++
felix/trunk/fileinstall/src/main/java/org/apache/felix/fileinstall/internal/DirectoryWatcher.java
Thu Oct 15 10:16:01 2009
@@ -87,6 +87,7 @@
public final static String START_NEW_BUNDLES =
"felix.fileinstall.bundles.new.start";
public final static String NO_INITIAL_DELAY =
"felix.fileinstall.noInitialDelay";
+ Dictionary properties;
File watchedDirectory;
File tmpDir;
long poll;
@@ -112,6 +113,7 @@
public DirectoryWatcher(Dictionary properties, BundleContext context)
{
super(properties.toString());
+ this.properties = properties;
this.context = context;
poll = getLong(properties, POLL, 2000);
debug = getLong(properties, DEBUG, -1);
@@ -139,7 +141,13 @@
flt = null;
}
scanner = new Scanner(watchedDirectory, flt);
+ }
+
+ public Dictionary getProperties() {
+ return properties;
+ }
+ public void start() {
if (noInitialDelay)
{
log("Starting initial scan", null);
@@ -150,6 +158,7 @@
process(files);
}
}
+ super.start();
}
/**
Modified:
felix/trunk/fileinstall/src/main/java/org/apache/felix/fileinstall/internal/FileInstall.java
URL:
http://svn.apache.org/viewvc/felix/trunk/fileinstall/src/main/java/org/apache/felix/fileinstall/internal/FileInstall.java?rev=825455&r1=825454&r2=825455&view=diff
==============================================================================
---
felix/trunk/fileinstall/src/main/java/org/apache/felix/fileinstall/internal/FileInstall.java
(original)
+++
felix/trunk/fileinstall/src/main/java/org/apache/felix/fileinstall/internal/FileInstall.java
Thu Oct 15 10:16:01 2009
@@ -129,13 +129,10 @@
public void stop(BundleContext context) throws Exception
{
List /*<DirectoryWatcher>*/ toClose = new ArrayList
/*<DirectoryWatcher>*/();
- if (watchers != null)
+ synchronized (watchers)
{
- synchronized (watchers)
- {
- toClose.addAll(watchers.values());
- watchers.clear();
- }
+ toClose.addAll(watchers.values());
+ watchers.clear();
}
for (Iterator w = toClose.iterator(); w.hasNext();)
{
@@ -178,11 +175,25 @@
public void updated(String pid, Dictionary properties)
{
- deleted(pid);
- Util.performSubstitution(properties);
-
- DirectoryWatcher watcher = new DirectoryWatcher(properties, context);
- watchers.put(pid, watcher);
+ Util.performSubstitution(properties);
+ DirectoryWatcher watcher = null;
+ synchronized (watchers)
+ {
+ watcher = (DirectoryWatcher) watchers.get(pid);
+ if (watcher != null && watcher.getProperties().equals(properties))
+ {
+ return;
+ }
+ }
+ if (watcher != null)
+ {
+ watcher.close();
+ }
+ watcher = new DirectoryWatcher(properties, context);
+ synchronized (watchers)
+ {
+ watchers.put(pid, watcher);
+ }
watcher.start();
}