harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From telli...@apache.org
Subject svn commit: r389232 - in /incubator/harmony/enhanced/classlib/trunk: modules/luni/src/main/java/java/io/ modules/luni/src/main/java/org/apache/harmony/luni/platform/ modules/luni/src/test/java/org/apache/harmony/tests/java/io/ native-src/linux.IA32/por...
Date Mon, 27 Mar 2006 19:39:11 GMT
Author: tellison
Date: Mon Mar 27 11:39:09 2006
New Revision: 389232

URL: http://svn.apache.org/viewcvs?rev=389232&view=rev
Log:
Fix for HARMONY-50 (java.io.RandomAccessFile should accept all modes that are defined in the
specification, including "rws" and "rwd")

Modified:
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/FileChannelFactory.java
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/RandomAccessFile.java
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/platform/IFileSystem.java
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/tests/java/io/AllTests.java
    incubator/harmony/enhanced/classlib/trunk/native-src/linux.IA32/port/hyfile.c
    incubator/harmony/enhanced/classlib/trunk/native-src/shared/include/hyport.h
    incubator/harmony/enhanced/classlib/trunk/native-src/shared/luni/IFileSystem.h
    incubator/harmony/enhanced/classlib/trunk/native-src/shared/luni/OSFileSystem.c
    incubator/harmony/enhanced/classlib/trunk/native-src/win.IA32/port/hyfile.c

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/FileChannelFactory.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/FileChannelFactory.java?rev=389232&r1=389231&r2=389232&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/FileChannelFactory.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/FileChannelFactory.java
Mon Mar 27 11:39:09 2006
@@ -36,6 +36,8 @@
             return new WriteOnlyFileChannel(stream, fd);
         case IFileSystem.O_RDWR:
             return new ReadWriteFileChannel(stream, fd);
+        case IFileSystem.O_RDWRSYNC:
+            return new ReadWriteFileChannel(stream, fd);
         case IFileSystem.O_APPEND:
             return new WriteOnlyFileChannel(stream, fd, true);
         default:

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/RandomAccessFile.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/RandomAccessFile.java?rev=389232&r1=389231&r2=389232&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/RandomAccessFile.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/RandomAccessFile.java
Mon Mar 27 11:39:09 2006
@@ -35,6 +35,8 @@
 	 */
 	FileDescriptor fd;
 
+	private boolean syncMetadata = false;
+	
 	// The unique file channel associated with this FileInputStream (lazily
 	// initialized).
 	private FileChannel channel;
@@ -66,10 +68,24 @@
 	public RandomAccessFile(File file, String mode)
 			throws FileNotFoundException {
 		super();
+		
+		int options = 0;
+		
 		if (mode.equals("r")) { //$NON-NLS-1$
             isReadOnly = 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;
+            options = IFileSystem.O_RDWR;
+            
+            if (mode.equals("rws")) {
+            	// Sync file and metadata with every write
+            	syncMetadata = true;
+            } else if (mode.equals("rwd")) {
+            	// Sync file, but not necessarily metadata
+            	options = IFileSystem.O_RDWRSYNC;
+            }
+            
         } else {
             throw new IllegalArgumentException(com.ibm.oti.util.Msg
                     .getString("K0081")); //$NON-NLS-1$
@@ -83,13 +99,18 @@
         }
 
         fd = new FileDescriptor();
-        // FIXME: add support to "rwd", "rws"
-        fd.descriptor = fileSystem.open(file.properPath(true),
-                isReadOnly ? IFileSystem.O_RDONLY : IFileSystem.O_RDWR);
-        channel = FileChannelFactory.getFileChannel(this, fd.descriptor,
-                isReadOnly ? IFileSystem.O_RDONLY : IFileSystem.O_RDWR);
+        fd.descriptor = fileSystem.open(file.properPath(true), options);
+        channel = FileChannelFactory.getFileChannel(this, fd.descriptor, options);
+        
+        // if we are in "rws" mode, attempt to sync file+metadata
+        if (syncMetadata) {
+			try {
+				fd.sync();
+			} catch (IOException e) {}
+		}
 	}
 
+
 	/**
 	 * Constructs a new RandomAccessFile on the file named <code>fileName</code>
 	 * and opens it according to the access String in <code>mode</code>. The
@@ -616,6 +637,11 @@
             fileSystem.truncate(fd.descriptor, newLength);            
             seek(position > newLength ? newLength : position);
         }
+        
+        // if we are in "rws" mode, attempt to sync file+metadata
+        if (syncMetadata) {
+			fd.sync();
+		}
 	}
 
 	/**
@@ -688,6 +714,11 @@
         synchronized (repositionLock) {
             fileSystem.write(fd.descriptor, buffer, offset, count);
         }
+        
+        // if we are in "rws" mode, attempt to sync file+metadata
+        if (syncMetadata) {
+        	fd.sync();
+		}
 	}
 
 	/**
@@ -713,6 +744,11 @@
         synchronized (repositionLock) {
             fileSystem.write(fd.descriptor, bytes, 0, 1);
         }
+        
+        // if we are in "rws" mode, attempt to sync file+metadata
+        if (syncMetadata) {
+			fd.sync();
+		}
 	}
 
 	/**

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/platform/IFileSystem.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/platform/IFileSystem.java?rev=389232&r1=389231&r2=389232&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/platform/IFileSystem.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/platform/IFileSystem.java
Mon Mar 27 11:39:09 2006
@@ -41,6 +41,8 @@
 
 	public final int O_RDWR = 0x00000010;
 
+	public final int O_RDWRSYNC = 0x00000020;
+	
 	public final int O_APPEND = 0x00000100;
 
 	public final int O_CREAT = 0x00001000;

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/tests/java/io/AllTests.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/tests/java/io/AllTests.java?rev=389232&r1=389231&r2=389232&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/tests/java/io/AllTests.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/tests/java/io/AllTests.java
Mon Mar 27 11:39:09 2006
@@ -34,6 +34,7 @@
 		suite.addTestSuite(FileTest.class);
 		suite.addTestSuite(BufferedReaderTest.class);
 		suite.addTestSuite(PushBackInputStreamTest.class);
+		suite.addTestSuite(RandomAccessFileTest.class);
 		//$JUnit-END$
 		return suite;
 	}

Modified: incubator/harmony/enhanced/classlib/trunk/native-src/linux.IA32/port/hyfile.c
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/native-src/linux.IA32/port/hyfile.c?rev=389232&r1=389231&r2=389232&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/native-src/linux.IA32/port/hyfile.c (original)
+++ incubator/harmony/enhanced/classlib/trunk/native-src/linux.IA32/port/hyfile.c Mon Mar
27 11:39:09 2006
@@ -64,6 +64,11 @@
     {
       realFlags |= O_EXCL | O_CREAT;
     }
+#ifdef O_SYNC
+	if (flags & HyOpenSync) {
+		realFlags |= O_SYNC;
+	}
+#endif    
   if (flags & HyOpenRead)
     {
       if (flags & HyOpenWrite)
@@ -168,8 +173,6 @@
                                          findError (EINVAL));
       return -1;
     }
-
-  /* Neutrino does not handle NULL for stat */
 
   if (!stat (path, &buffer))
     {

Modified: incubator/harmony/enhanced/classlib/trunk/native-src/shared/include/hyport.h
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/native-src/shared/include/hyport.h?rev=389232&r1=389231&r2=389232&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/native-src/shared/include/hyport.h (original)
+++ incubator/harmony/enhanced/classlib/trunk/native-src/shared/include/hyport.h Mon Mar 27
11:39:09 2006
@@ -94,6 +94,7 @@
 #define HyOpenAppend  16
 #define HyOpenText    32
 #define HyOpenCreateNew 64      /* Use this flag with HyOpenCreate, if this flag is specified
then trying to create an existing file will fail */
+#define HyOpenSync		128
 #define HyIsDir   0       /* Return values for HyFileAttr */
 #define HyIsFile  1
 

Modified: incubator/harmony/enhanced/classlib/trunk/native-src/shared/luni/IFileSystem.h
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/native-src/shared/luni/IFileSystem.h?rev=389232&r1=389231&r2=389232&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/native-src/shared/luni/IFileSystem.h (original)
+++ incubator/harmony/enhanced/classlib/trunk/native-src/shared/luni/IFileSystem.h Mon Mar
27 11:39:09 2006
@@ -38,6 +38,8 @@
 #define org_apache_harmony_luni_platform_IFileSystem_O_WRONLY 1L
 #undef org_apache_harmony_luni_platform_IFileSystem_O_RDWR
 #define org_apache_harmony_luni_platform_IFileSystem_O_RDWR 16L
+#undef org_apache_harmony_luni_platform_IFileSystem_O_RDWRSYNC
+#define org_apache_harmony_luni_platform_IFileSystem_O_RDWRSYNC 32L
 #undef org_apache_harmony_luni_platform_IFileSystem_O_APPEND
 #define org_apache_harmony_luni_platform_IFileSystem_O_APPEND 256L
 #undef org_apache_harmony_luni_platform_IFileSystem_O_CREAT

Modified: incubator/harmony/enhanced/classlib/trunk/native-src/shared/luni/OSFileSystem.c
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/native-src/shared/luni/OSFileSystem.c?rev=389232&r1=389231&r2=389232&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/native-src/shared/luni/OSFileSystem.c (original)
+++ incubator/harmony/enhanced/classlib/trunk/native-src/shared/luni/OSFileSystem.c Mon Mar
27 11:39:09 2006
@@ -220,6 +220,10 @@
                 flags = HyOpenWrite | HyOpenCreate | HyOpenAppend; 
                 mode = 0666;
                 break;
+        case org_apache_harmony_luni_platform_IFileSystem_O_RDWRSYNC:
+        		flags = HyOpenRead | HyOpenWrite | HyOpenCreate | HyOpenSync;
+        		mode = 0666;
+        		break;
       }
 
       length = (*env)->GetArrayLength (env, path);

Modified: incubator/harmony/enhanced/classlib/trunk/native-src/win.IA32/port/hyfile.c
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/native-src/win.IA32/port/hyfile.c?rev=389232&r1=389231&r2=389232&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/native-src/win.IA32/port/hyfile.c (original)
+++ incubator/harmony/enhanced/classlib/trunk/native-src/win.IA32/port/hyfile.c Mon Mar 27
11:39:09 2006
@@ -399,7 +399,7 @@
 hyfile_open (struct HyPortLibrary * portLibrary, const char *path, I_32 flags,
 	     I_32 mode)
 {
-  DWORD accessMode, shareMode, createMode;
+  DWORD accessMode, shareMode, createMode, flagsAndAttributes;
   HANDLE aHandle;
   I_32 error;
 
@@ -430,9 +430,14 @@
       createMode = OPEN_EXISTING;
     }
 
+  flagsAndAttributes = FILE_ATTRIBUTE_NORMAL;
+	if (flags & HyOpenSync) {
+		flagsAndAttributes |= FILE_FLAG_WRITE_THROUGH;
+	}
+
   aHandle =
     CreateFile (path, accessMode, shareMode, NULL, createMode,
-		FILE_ATTRIBUTE_NORMAL, NULL);
+		flagsAndAttributes, NULL);
   if (aHandle == INVALID_HANDLE_VALUE)
     {
       error = GetLastError ();
@@ -452,7 +457,7 @@
 
       aHandle =
 	CreateFile (path, accessMode, shareMode, NULL, TRUNCATE_EXISTING,
-		    FILE_ATTRIBUTE_NORMAL, NULL);
+		    flagsAndAttributes, NULL);
       if (aHandle == INVALID_HANDLE_VALUE)
 	{
 	  error = GetLastError ();



Mime
View raw message