harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hinde...@apache.org
Subject svn commit: r578050 - in /harmony/enhanced/classlib/trunk/modules: luni/src/main/native/luni/shared/file.c luni/src/test/api/common/tests/api/java/io/FileTest.java portlib/src/main/native/port/unix/hyfile.c
Date Fri, 21 Sep 2007 10:36:13 GMT
Author: hindessm
Date: Fri Sep 21 03:36:04 2007
New Revision: 578050

URL: http://svn.apache.org/viewvc?rev=578050&view=rev
Log:
Applying fix for "[#HARMONY-4839] [classlib][luni] File.createNewFile
should be atomic".  Minor fix to the patch on JIRA - removing HyOpenCreate
from the flags to avoid problems on windows.  Many thanks to Paulex for
the windows help.

Modified:
    harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/shared/file.c
    harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/tests/api/java/io/FileTest.java
    harmony/enhanced/classlib/trunk/modules/portlib/src/main/native/port/unix/hyfile.c

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/shared/file.c
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/shared/file.c?rev=578050&r1=578049&r2=578050&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/shared/file.c (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/shared/file.c Fri Sep
21 03:36:04 2007
@@ -323,7 +323,6 @@
 Java_java_io_File_newFileImpl (JNIEnv * env, jobject recv, jbyteArray path)
 {
   PORT_ACCESS_FROM_ENV (env);
-  I_32 result;
   IDATA portFD;
   jsize length = (*env)->GetArrayLength (env, path);
   char pathCopy[HyMaxPath];
@@ -332,18 +331,17 @@
   pathCopy[length] = '\0';
   ioh_convertToPlatform (pathCopy);
 
-  /* First check to see if file already exists */
-  result = hyfile_attr (pathCopy);
-  if (result == HyIsDir)
-    return 3;
-  if (result >= 0)
-    return 1;
-
   /* Now create the file and close it */
-  portFD =
-    hyfile_open (pathCopy, HyOpenCreate | HyOpenWrite | HyOpenTruncate, 0666);
-  if (portFD == -1)
+  portFD = hyfile_open (pathCopy,
+                        HyOpenCreateNew | HyOpenWrite | HyOpenTruncate,
+                        0666);
+  
+  if (portFD == -1) {
+    if (hyerror_last_error_number() == HYPORT_ERROR_FILE_EXIST) {
+      return 1;
+    }
     return 2;
+  }
   hyfile_close (portFD);
   return 0;
 }

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/tests/api/java/io/FileTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/tests/api/java/io/FileTest.java?rev=578050&r1=578049&r2=578050&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/tests/api/java/io/FileTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/tests/api/java/io/FileTest.java
Fri Sep 21 03:36:04 2007
@@ -412,15 +412,22 @@
         } catch (IOException e) {
             // expected;
         }
-        
-        // Test create an exist path
-        f1 = new File(base);
-        try {
-            assertFalse(f1.createNewFile());
-            fail("should throw IOE");
-        } catch (IOException e) {
-            // expected;
-        }
+
+        // This test is invalid.  createNewFile should return false
+        // not IOE when the file exists (in this case it exists and is
+        // a directory).  TODO: We should probably replace this test
+        // with some that cover this behaviour.  It might even be
+        // different on unix and windows since it directly reflects
+        // the open syscall behaviour.
+        //
+        // // Test create an exist path
+        // f1 = new File(base);
+        // try {
+        //     assertFalse(f1.createNewFile());
+        //     fail("should throw IOE");
+        // } catch (IOException e) {
+        //     // expected;
+        // }
     }
 
 	/**

Modified: harmony/enhanced/classlib/trunk/modules/portlib/src/main/native/port/unix/hyfile.c
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/portlib/src/main/native/port/unix/hyfile.c?rev=578050&r1=578049&r2=578050&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/portlib/src/main/native/port/unix/hyfile.c (original)
+++ harmony/enhanced/classlib/trunk/modules/portlib/src/main/native/port/unix/hyfile.c Fri
Sep 21 03:36:04 2007
@@ -176,10 +176,13 @@
       return -1;
     }
 
-  if (!stat (path, &buffer))
+  if ( ( flags&HyOpenRead && !(flags&HyOpenWrite) )  && !stat (path,
&buffer))
     {
       if (S_ISDIR (buffer.st_mode))
         {
+          portLibrary->error_set_last_error_with_message (portLibrary,
+                                                          findError (EEXIST),
+                                                          "Is a directory");
           Trc_PRT_file_open_Exit4 ();
           return -1;
         }



Mime
View raw message