felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gno...@apache.org
Subject svn commit: r828204 - in /felix/trunk/fileinstall/src: main/java/org/apache/felix/fileinstall/internal/DirectoryWatcher.java test/java/org/apache/felix/fileinstall/internal/DirectoryWatcherTest.java
Date Wed, 21 Oct 2009 20:45:36 GMT
Author: gnodet
Date: Wed Oct 21 20:45:35 2009
New Revision: 828204

URL: http://svn.apache.org/viewvc?rev=828204&view=rev
Log:
FELIX-1790: fileinstall tmp dir needs to be different for each watched directory

Modified:
    felix/trunk/fileinstall/src/main/java/org/apache/felix/fileinstall/internal/DirectoryWatcher.java
    felix/trunk/fileinstall/src/test/java/org/apache/felix/fileinstall/internal/DirectoryWatcherTest.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=828204&r1=828203&r2=828204&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
Wed Oct 21 20:45:35 2009
@@ -28,6 +28,7 @@
 import java.net.URI;
 import java.net.URISyntaxException;
 import java.net.URL;
+import java.security.SecureRandom;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Dictionary;
@@ -87,6 +88,10 @@
     public final static String START_NEW_BUNDLES = "felix.fileinstall.bundles.new.start";
     public final static String NO_INITIAL_DELAY = "felix.fileinstall.noInitialDelay";
 
+    static final SecureRandom random = new SecureRandom();
+
+    static final File javaIoTmpdir = new File(System.getProperty("java.io.tmpdir"));
+
     Dictionary properties;
     File watchedDirectory;
     File tmpDir;
@@ -120,7 +125,8 @@
         originatingFileName = (String) properties.get(FILENAME);
         watchedDirectory = getFile(properties, DIR, new File("./load"));
         prepareDir(watchedDirectory);
-        tmpDir = getFile(properties, TMPDIR, new File(System.getProperty("java.io.tmpdir"),
"fileinstall"));
+        tmpDir = getFile(properties, TMPDIR, null);
+        prepareTempDir();
         startBundles = getBoolean(properties, START_NEW_BUNDLES, true);  // by default, we
start bundles.
         filter = (String) properties.get(FILTER);
         noInitialDelay = getBoolean(properties, NO_INITIAL_DELAY, false);
@@ -283,7 +289,7 @@
                 // Jar up the directory if needed
                 if (file.isDirectory())
                 {
-                    prepareDir(tmpDir);
+                    prepareTempDir();
                     try
                     {
                         jar = new File(tmpDir, file.getName() + ".jar");
@@ -410,7 +416,7 @@
     {
         if (artifact.getListener() instanceof ArtifactTransformer)
         {
-            prepareDir(tmpDir);
+            prepareTempDir();
             try
             {
                 File transformed = ((ArtifactTransformer) artifact.getListener()).transform(artifact.getJaredDirectory(),
tmpDir);
@@ -467,6 +473,28 @@
         }
     }
 
+
+    private void prepareTempDir()
+    {
+        if (tmpDir == null)
+        {
+            for (;;)
+            {
+                File f = new File(javaIoTmpdir, "fileinstall-" + Long.toString(random.nextLong()));
+                if (!f.exists() && f.mkdirs())
+                {
+                    tmpDir = f;
+                    System.err.println("Created temp dir at " + tmpDir);
+                    break;
+                }
+            }
+        }
+        else
+        {
+            prepareDir(tmpDir);
+        }
+    }
+
     /**
      * Create the watched directory, if not existing.
      * Throws a runtime exception if the directory cannot be created,

Modified: felix/trunk/fileinstall/src/test/java/org/apache/felix/fileinstall/internal/DirectoryWatcherTest.java
URL: http://svn.apache.org/viewvc/felix/trunk/fileinstall/src/test/java/org/apache/felix/fileinstall/internal/DirectoryWatcherTest.java?rev=828204&r1=828203&r2=828204&view=diff
==============================================================================
--- felix/trunk/fileinstall/src/test/java/org/apache/felix/fileinstall/internal/DirectoryWatcherTest.java
(original)
+++ felix/trunk/fileinstall/src/test/java/org/apache/felix/fileinstall/internal/DirectoryWatcherTest.java
Wed Oct 21 20:45:35 2009
@@ -183,8 +183,8 @@
             "src" + File.separatorChar + "test" + File.separatorChar + "resources" ) );
         assertEquals( "Default POLL parameter correctly read", 2000l, dw.poll );
         assertEquals( "Default DEBUG parameter correctly read", -1l, dw.debug );
-        assertTrue( "Default TMPDIR parameter correctly read", dw.tmpDir.getAbsolutePath().equals(
-                new File(System.getProperty("java.io.tmpdir"), "fileinstall").getAbsolutePath())
);
+        assertTrue( "Default TMPDIR parameter correctly read", dw.tmpDir.getAbsolutePath().startsWith(
+                new File(System.getProperty("java.io.tmpdir")).getAbsolutePath()) );
         assertEquals( "Default START_NEW_BUNDLES parameter correctly read", true, dw.startBundles
);
         assertEquals( "Default FILTER parameter correctly read", null, dw.filter );
     }



Mime
View raw message