[jboss-svn-commits] JBL Code SVN: r38257 - in labs/jbossesb/branches/JBESB_4_11_CP/product/rosetta: tests/src/org/jboss/soa/esb/util and 1 other directory.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Thu Nov 29 13:54:37 EST 2012


Author: tcunning
Date: 2012-11-29 13:54:36 -0500 (Thu, 29 Nov 2012)
New Revision: 38257

Modified:
   labs/jbossesb/branches/JBESB_4_11_CP/product/rosetta/src/org/jboss/soa/esb/util/FileUtil.java
   labs/jbossesb/branches/JBESB_4_11_CP/product/rosetta/tests/src/org/jboss/soa/esb/util/FileUtilUnitTest.java
Log:
JBESB-3882
Commit renameTo changes to return false in the case of locked files.


Modified: labs/jbossesb/branches/JBESB_4_11_CP/product/rosetta/src/org/jboss/soa/esb/util/FileUtil.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_11_CP/product/rosetta/src/org/jboss/soa/esb/util/FileUtil.java	2012-11-29 18:51:01 UTC (rev 38256)
+++ labs/jbossesb/branches/JBESB_4_11_CP/product/rosetta/src/org/jboss/soa/esb/util/FileUtil.java	2012-11-29 18:54:36 UTC (rev 38257)
@@ -110,14 +110,14 @@
 
         if(!from.renameTo(fromLocalRename))
         {
-                LOGGER.debug("Unable to perform local rename of file '" + from.getAbsolutePath() + "' to '" + fromLocalRename.getAbsolutePath() + "'.  Unable to move file.");
-                return true;
+            LOGGER.debug("Unable to perform local rename of file '" + from.getAbsolutePath() + "' to '" + fromLocalRename.getAbsolutePath() + "'.  Unable to move file.");
+            return false;
         }
 
         if(!fromLocalRename.exists())
         {
             LOGGER.debug("Failed to perform local rename of file '" + from.getAbsolutePath() + "' to '" + fromLocalRename.getAbsolutePath() + "'.  Unable to move file.");
-            return true;
+            return false;
         }
 
         final File tmpFile ;
@@ -128,7 +128,7 @@
         catch (final IOException ioe)
         {
             LOGGER.debug("Could not create temporary file for writing", ioe) ;
-            return true;
+            return false;
         }
 
         try
@@ -206,18 +206,18 @@
             }
             finally
             {
-                    try
-                    {
-                            fos.close();
-                    }
-                    catch (final IOException ioe) {} // ignore
+                try
+                {
+                    fos.close();
+                }
+                catch (final IOException ioe) {} // ignore
             }
         }
         finally
         {
             try
             {
-                    fis.close();
+                fis.close();
             }
             catch (final IOException ioe) {} // ignore
         }
@@ -235,7 +235,7 @@
         StringBuffer sb = new StringBuffer(1024);
         BufferedReader reader = new BufferedReader(new FileReader(file.getPath()));
         char[] chars = new char[1];
-        while( (reader.read(chars)) > -1){
+        while( (reader.read(chars)) > -1) {
             sb.append(String.valueOf(chars)); 
             chars = new char[1];
         }

Modified: labs/jbossesb/branches/JBESB_4_11_CP/product/rosetta/tests/src/org/jboss/soa/esb/util/FileUtilUnitTest.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_11_CP/product/rosetta/tests/src/org/jboss/soa/esb/util/FileUtilUnitTest.java	2012-11-29 18:51:01 UTC (rev 38256)
+++ labs/jbossesb/branches/JBESB_4_11_CP/product/rosetta/tests/src/org/jboss/soa/esb/util/FileUtilUnitTest.java	2012-11-29 18:54:36 UTC (rev 38257)
@@ -43,7 +43,37 @@
     protected void tearDown() throws Exception {
         cleanupTemps();
     }
+    
+    public boolean isWindows() {
+    	return System.getProperty("os.name").toLowerCase().indexOf("win") != -1;
+    }
 
+    public void test_renameTo() throws IOException {
+    	if (isWindows()) {
+    		System.out.println("Running Windows renaming test...");
+	    	file1.delete();
+	    	file2.delete();
+	    	
+	        Writer writer = new FileWriter(file1);
+	        writer.write("Write to File!");
+	        writer.close();
+	        
+	        BufferedWriter bw = new BufferedWriter(new FileWriter(file1, true));
+	        
+	        assertTrue(file1.exists());
+	        assertTrue(!file2.exists());
+	        
+	        assertFalse(FileUtil.renameTo(file1, file2));
+	        bw.close();
+	        	
+	        assertTrue(file1.exists());
+	        assertTrue(!file2.exists());
+	        
+	        file1.delete();
+	        file2.delete();
+    	}
+    }
+    
     public void test_moveTo_good() throws IOException {
         writeToFile(file1, "Hi there!");
 



More information about the jboss-svn-commits mailing list