harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From py...@apache.org
Subject svn commit: r448129 - in /incubator/harmony/enhanced/classlib/trunk/modules/luni/src: main/native/port/windows/hyfile.c test/java/tests/api/java/io/FileTest.java
Date Wed, 20 Sep 2006 09:00:45 GMT
Author: pyang
Date: Wed Sep 20 02:00:44 2006
New Revision: 448129

URL: http://svn.apache.org/viewvc?view=rev&rev=448129
Log:
Appli patch for HARMONY-1497 ([classlib][luni] java.io.File.length could not reflect the latest
file attribute)

Modified:
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/native/port/windows/hyfile.c
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/FileTest.java

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/native/port/windows/hyfile.c
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/native/port/windows/hyfile.c?view=diff&rev=448129&r1=448128&r2=448129
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/native/port/windows/hyfile.c
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/native/port/windows/hyfile.c
Wed Sep 20 02:00:44 2006
@@ -299,28 +299,17 @@
 I_64 VMCALL
 hyfile_length (struct HyPortLibrary * portLibrary, const char *path)
 {
-  WIN32_FIND_DATA myStat;
-  HANDLE newHandle;
-  I_64 result;
-  I_32 error;
-
-  newHandle = FindFirstFile (path, &myStat);
-  if (newHandle == INVALID_HANDLE_VALUE)
-    {
-      error = GetLastError ();
-      return portLibrary->error_set_last_error (portLibrary, error,
-						findError (error));
+    I_64 result;
+    I_32 error;
+    WIN32_FILE_ATTRIBUTE_DATA myStat;
+    int ret = GetFileAttributesEx(path,GetFileExInfoStandard,&myStat);
+    if(ret == 0) {
+        error = GetLastError ();
+        return portLibrary->error_set_last_error (portLibrary, error, findError (error));
     }
-
-  result = ((I_64) myStat.nFileSizeHigh) << 32;
-  result += (I_64) myStat.nFileSizeLow;
-  if (0 == FindClose (newHandle))
-    {
-      error = GetLastError ();
-      portLibrary->error_set_last_error (portLibrary, error, findError (error));	/* continue
*/
-    }
-
-  return result;
+    result = ((I_64) myStat.nFileSizeHigh) << 32;
+    result += (I_64) myStat.nFileSizeLow;
+    return result;
 }
 
 #undef CDEV_CURRENT_FUNCTION

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/FileTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/FileTest.java?view=diff&rev=448129&r1=448128&r2=448129
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/FileTest.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/FileTest.java
Wed Sep 20 02:00:44 2006
@@ -21,6 +21,7 @@
 import java.io.FileOutputStream;
 import java.io.FilenameFilter;
 import java.io.IOException;
+import java.io.RandomAccessFile;
 import java.net.MalformedURLException;
 import java.net.URI;
 import java.net.URISyntaxException;
@@ -768,10 +769,8 @@
 			assertEquals("Test 3: Incorrect File Returned.", 0, f2
 					.getCanonicalFile().compareTo(f.getCanonicalFile()));
 
-			// Test for when long directory/file names in Windows
-			String osName = System.getProperty("os.name", "unknown");
+			// Test for when long directory/file names in Windows	
 			boolean onWindows = File.separatorChar == '\\';
-			boolean createdDir = false;
 			// String userDir = System.getProperty("user.dir");
 			if (onWindows) {
 				File testdir = new File(base, "long-" + platformId);
@@ -1149,7 +1148,7 @@
 	/**
 	 * @tests java.io.File#length()
 	 */
-	public void test_length() {
+	public void test_length() throws Exception {
 		// Test for method long java.io.File.length()
 		try {
 			File f = new File(System.getProperty("user.dir"), platformId
@@ -1164,6 +1163,13 @@
 		} catch (IOException e) {
 			fail("Unexpected IOException during test : " + e.getMessage());
 		}
+        
+        // regression test for Harmony-1497
+        File f = File.createTempFile("test", "tmp");
+        f.deleteOnExit();
+        RandomAccessFile raf = new RandomAccessFile(f, "rwd");
+        raf.write(0x41);
+        assertEquals(1, f.length());
 	}
 
 	/**



Mime
View raw message