harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lian...@apache.org
Subject svn commit: r506271 - in /harmony/enhanced/classlib/trunk/modules/luni/src: main/java/java/io/ main/native/luni/shared/ main/native/luni/unix/ test/java/tests/api/java/io/
Date Mon, 12 Feb 2007 04:18:40 GMT
Author: liangyx
Date: Sun Feb 11 20:18:39 2007
New Revision: 506271

URL: http://svn.apache.org/viewvc?view=rev&rev=506271
Log:
Apply patch for HARMONY-1494([classlib][luni] FileDescriptor.sync() throws unexpected SyncFailedException
when the descriptor is read-only)

Modified:
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/FileDescriptor.java
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/FileInputStream.java
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/RandomAccessFile.java
    harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/shared/filedesc.c
    harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/unix/exports.txt
    harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/FileDescriptorTest.java

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/FileDescriptor.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/FileDescriptor.java?view=diff&rev=506271&r1=506270&r2=506271
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/FileDescriptor.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/FileDescriptor.java
Sun Feb 11 20:18:39 2007
@@ -49,6 +49,8 @@
      * A value of -1 indicates that this FileDescriptor is invalid.
      */
     long descriptor = -1;
+    
+    boolean readOnly = false; 
 
     private static native void oneTimeInitialization();
 
@@ -76,7 +78,14 @@
      * @throws SyncFailedException
      *             when the operation fails
      */
-    public native void sync() throws SyncFailedException;
+    public void sync() throws SyncFailedException {
+        // if the descriptor is a read-only one, do nothing
+        if (!readOnly) {
+            syncImpl();
+        }
+    }
+    
+    private native void syncImpl() throws SyncFailedException;
 
     /**
      * Answers a boolean indicating whether or not this FileDescriptor is valid.

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/FileInputStream.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/FileInputStream.java?view=diff&rev=506271&r1=506270&r2=506271
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/FileInputStream.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/FileInputStream.java
Sun Feb 11 20:18:39 2007
@@ -72,6 +72,7 @@
             security.checkRead(filePath);
         }
         fd = new FileDescriptor();
+        fd.readOnly = true;
         fd.descriptor = fileSystem.open(file.properPath(true),
                 IFileSystem.O_RDONLY);
         innerFD = true;

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/RandomAccessFile.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/RandomAccessFile.java?view=diff&rev=506271&r1=506270&r2=506271
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/RandomAccessFile.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/RandomAccessFile.java
Sun Feb 11 20:18:39 2007
@@ -76,9 +76,12 @@
         super();
 
         int options = 0;
-
+        
+        fd = new FileDescriptor();
+       
         if (mode.equals("r")) { //$NON-NLS-1$
             isReadOnly = true;
+            fd.readOnly = true;
             options = IFileSystem.O_RDONLY;
         } else if (mode.equals("rw") || mode.equals("rws") || mode.equals("rwd")) { //$NON-NLS-1$
//$NON-NLS-2$ //$NON-NLS-3$
             isReadOnly = false;
@@ -102,8 +105,7 @@
                 security.checkWrite(file.getPath());
             }
         }
-
-        fd = new FileDescriptor();
+        
         fd.descriptor = fileSystem.open(file.properPath(true), options);
         channel = FileChannelFactory.getFileChannel(this, fd.descriptor,
                 options);

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/shared/filedesc.c
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/shared/filedesc.c?view=diff&rev=506271&r1=506270&r2=506271
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/shared/filedesc.c (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/shared/filedesc.c Sun
Feb 11 20:18:39 2007
@@ -31,7 +31,7 @@
 }
 
 JNIEXPORT void JNICALL
-Java_java_io_FileDescriptor_sync (JNIEnv * env, jobject recv)
+Java_java_io_FileDescriptor_syncImpl (JNIEnv * env, jobject recv)
 {
   /* Cause all unwritten data to be written out to the OS */
   IDATA descriptor;

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/unix/exports.txt
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/unix/exports.txt?view=diff&rev=506271&r1=506270&r2=506271
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/unix/exports.txt (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/unix/exports.txt Sun
Feb 11 20:18:39 2007
@@ -44,7 +44,7 @@
 Java_java_io_File_setLastModifiedImpl
 Java_java_io_File_setReadOnlyImpl
 Java_java_io_FileDescriptor_oneTimeInitialization
-Java_java_io_FileDescriptor_sync
+Java_java_io_FileDescriptor_syncImpl
 Java_java_io_FileDescriptor_valid
 Java_java_io_FileInputStream_available
 Java_java_io_FileInputStream_closeImpl

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/FileDescriptorTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/FileDescriptorTest.java?view=diff&rev=506271&r1=506270&r2=506271
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/FileDescriptorTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/FileDescriptorTest.java
Sun Feb 11 20:18:39 2007
@@ -22,6 +22,7 @@
 import java.io.FileDescriptor;
 import java.io.FileInputStream;
 import java.io.FileOutputStream;
+import java.io.RandomAccessFile;
 
 public class FileDescriptorTest extends junit.framework.TestCase {
 
@@ -49,23 +50,29 @@
 	/**
 	 * @tests java.io.FileDescriptor#sync()
 	 */
-	public void test_sync() {
+       public void test_sync() throws Exception {
 		// Test for method void java.io.FileDescriptor.sync()
-
-		try {
-			f = new File(System.getProperty("user.dir"), "fd" + platformId
-					+ ".tst");
-			f.delete();
-			fos = new FileOutputStream(f.getPath());
-			fos.write("Test String".getBytes());
-			fis = new FileInputStream(f.getPath());
-			FileDescriptor fd = fos.getFD();
-			fd.sync();
-			assertTrue("Bytes were not written after sync",
-					fis.available() == "Test String".length());
-		} catch (Exception e) {
-			fail("Exception during test : " + e.getMessage());
-		}
+        f = new File(System.getProperty("user.dir"), "fd" + platformId + ".tst");
+        f.delete();
+        fos = new FileOutputStream(f.getPath());
+        fos.write("Test String".getBytes());
+        fis = new FileInputStream(f.getPath());
+        FileDescriptor fd = fos.getFD();
+        fd.sync();
+        int length = "Test String".length();
+        assertEquals("Bytes were not written after sync", length, fis
+                .available());
+        
+        // Regression test for Harmony-1494
+        fd = fis.getFD();
+        fd.sync();
+        assertEquals("Bytes were not written after sync", length, fis
+                .available());
+        
+        RandomAccessFile raf = new RandomAccessFile(f, "r");
+        fd = raf.getFD(); 
+        fd.sync();
+        raf.close();
 	}
 
 	/**



Mime
View raw message