felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gno...@apache.org
Subject svn commit: r1301383 - in /felix/trunk/fileinstall/src: main/java/org/apache/felix/fileinstall/internal/DirectoryWatcher.java test/java/org/apache/felix/fileinstall/internal/DirectoryWatcherTest.java
Date Fri, 16 Mar 2012 09:00:44 GMT
Author: gnodet
Date: Fri Mar 16 09:00:44 2012
New Revision: 1301383

URL: http://svn.apache.org/viewvc?rev=1301383&view=rev
Log:
[FELIX-3047] Infinite loop in File Install if java.io.tmpdir is non-writable

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=1301383&r1=1301382&r2=1301383&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
Fri Mar 16 09:00:44 2012
@@ -97,7 +97,7 @@ public class DirectoryWatcher extends Th
 
     static final SecureRandom random = new SecureRandom();
 
-    static final File javaIoTmpdir = new File(System.getProperty("java.io.tmpdir"));
+    final File javaIoTmpdir = new File(System.getProperty("java.io.tmpdir"));
 
     Dictionary properties;
     File watchedDirectory;
@@ -560,6 +560,9 @@ public class DirectoryWatcher extends Th
     {
         if (tmpDir == null)
         {
+            if (!javaIoTmpdir.exists() && !javaIoTmpdir.mkdirs()) {
+                throw new IllegalStateException("Unable to create temporary directory " +
javaIoTmpdir);
+            }
             for (;;)
             {
                 File f = new File(javaIoTmpdir, "fileinstall-" + Long.toString(random.nextLong()));

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=1301383&r1=1301382&r2=1301383&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
Fri Mar 16 09:00:44 2012
@@ -168,11 +168,11 @@ public class DirectoryWatcherTest extend
 
         assertEquals( "POLL parameter correctly read", 500l, dw.poll );
         assertEquals( "LOG_LEVEL parameter correctly read", 1, dw.logLevel );
-        assertTrue( "DIR parameter correctly read", dw.watchedDirectory.getAbsolutePath().endsWith(
-            "src" + File.separatorChar + "test" + File.separatorChar + "resources" ) );
+        assertTrue("DIR parameter correctly read", dw.watchedDirectory.getAbsolutePath().endsWith(
+                "src" + File.separatorChar + "test" + File.separatorChar + "resources"));
         assertTrue( "TMPDIR parameter correctly read", dw.tmpDir.getAbsolutePath().endsWith(
             "src" + File.separatorChar + "test" + File.separatorChar + "resources" ) );
-        assertEquals( "START_NEW_BUNDLES parameter correctly read", false, dw.startBundles
);
+        assertEquals("START_NEW_BUNDLES parameter correctly read", false, dw.startBundles);
         assertEquals( "FILTER parameter correctly read", ".*\\.cfg", dw.filter );
         EasyMock.verify(new Object[]{mockBundleContext});
     }
@@ -189,11 +189,11 @@ public class DirectoryWatcherTest extend
 
         assertTrue( "DIR parameter correctly read", dw.watchedDirectory.getAbsolutePath().endsWith(
             "src" + File.separatorChar + "test" + File.separatorChar + "resources" ) );
-        assertEquals( "Default POLL parameter correctly read", 2000l, dw.poll );
+        assertEquals("Default POLL parameter correctly read", 2000l, dw.poll);
         assertEquals( "Default LOG_LEVEL parameter correctly read", 1, dw.logLevel );
-        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
);
+        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 );
         EasyMock.verify(new Object[]{mockBundleContext});
     }
@@ -205,7 +205,7 @@ public class DirectoryWatcherTest extend
         EasyMock.expect(mockBundleContext.createFilter((String) EasyMock.anyObject()))
                         .andReturn(null);
         EasyMock.expect(Long.valueOf(mockPackageAdmin.getBundleType(mockBundle)))
-                        .andReturn(new Long(PackageAdmin.BUNDLE_TYPE_FRAGMENT) );
+                        .andReturn(new Long(PackageAdmin.BUNDLE_TYPE_FRAGMENT));
         EasyMock.replay(new Object[]{mockBundleContext, mockPackageAdmin, mockBundle});
 
         FileInstall.padmin = new MockServiceTracker( mockBundleContext, mockPackageAdmin
);
@@ -215,6 +215,43 @@ public class DirectoryWatcherTest extend
 
         EasyMock.verify(new Object[]{mockBundleContext});
     }
+    
+    public void testInvalidTempDir() throws Exception
+    {
+        String oldTmpDir = System.getProperty("java.io.tmpdir");
+        
+        try 
+        {
+            File parent = new File("target/tmp");
+            parent.mkdirs();
+            parent.setWritable(false, false);
+            File tmp = new File(parent, "tmp");
+            System.setProperty("java.io.tmpdir", tmp.toString());
+
+            mockBundleContext.addBundleListener((BundleListener) org.easymock.EasyMock.anyObject());
+            EasyMock.expect(mockBundleContext.createFilter((String) EasyMock.anyObject()))
+                    .andReturn(null);
+            EasyMock.expect(Long.valueOf(mockPackageAdmin.getBundleType(mockBundle)))
+                    .andReturn(new Long(PackageAdmin.BUNDLE_TYPE_FRAGMENT));
+            EasyMock.replay(new Object[]{mockBundleContext, mockPackageAdmin, mockBundle});
+    
+            FileInstall.padmin = new MockServiceTracker( mockBundleContext, mockPackageAdmin
);
+            
+            try 
+            {
+                dw = new DirectoryWatcher( props, mockBundleContext );
+                fail("Expected an IllegalStateException");
+            } 
+            catch (IllegalStateException e)
+            {
+                // expected
+            }
+        }
+        finally
+        {
+            System.setProperty("java.io.tmpdir", oldTmpDir);
+        }
+    }
 
 
 }



Mime
View raw message