harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lian...@apache.org
Subject svn commit: r518905 - in /harmony/enhanced/classlib/trunk/modules: luni/src/main/native/luni/shared/ luni/src/main/native/luni/windows/ nio/make/ nio/src/test/java/common/org/apache/harmony/nio/tests/java/nio/channels/ portlib/src/main/native/include/s...
Date Fri, 16 Mar 2007 09:46:29 GMT
Author: liangyx
Date: Fri Mar 16 02:46:28 2007
New Revision: 518905

URL: http://svn.apache.org/viewvc?view=rev&rev=518905
Log:
Apply patch for HARMONY-2476([classlib][nio]FileChannel.read(ByteBuffer) does not throw IOException
if underlying file is locked)

Added:
    harmony/enhanced/classlib/trunk/modules/nio/src/test/java/common/org/apache/harmony/nio/tests/java/nio/channels/FileChannelWin32OnlyTest.java
  (with props)
Modified:
    harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/shared/OSFileSystem.c
    harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/shared/nethelp.c
    harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/windows/OSFileSystemWin32.c
    harmony/enhanced/classlib/trunk/modules/nio/make/exclude.linux.x86.drl
    harmony/enhanced/classlib/trunk/modules/nio/make/exclude.linux.x86.ibm
    harmony/enhanced/classlib/trunk/modules/nio/make/exclude.linux.x86_64.drl
    harmony/enhanced/classlib/trunk/modules/nio/make/exclude.linux.x86_64.ibm
    harmony/enhanced/classlib/trunk/modules/portlib/src/main/native/include/shared/hyporterror.h
    harmony/enhanced/classlib/trunk/modules/portlib/src/main/native/port/windows/hyfile.c

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/shared/OSFileSystem.c
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/shared/OSFileSystem.c?view=diff&rev=518905&r1=518904&r2=518905
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/shared/OSFileSystem.c
(original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/shared/OSFileSystem.c
Fri Mar 16 02:46:28 2007
@@ -22,7 +22,7 @@
 #include <string.h>
 #include "iohelp.h"
 #include "exceptions.h"
-
+#include "nethelp.h"
 #include "OSFileSystem.h"
 #include "IFileSystem.h"
 
@@ -71,6 +71,9 @@
   result =
     (jlong) hyfile_read ((IDATA) fd, (void *) (bytes + offset),
                          (IDATA) nbytes);
+  if(result == -1 && hyerror_last_error_number() == HYPORT_ERROR_FILE_LOCKED){
+    throwNewExceptionByName(env, "java/io/IOException", netLookupErrorString(env, HYPORT_ERROR_FILE_LOCKED));
+  }
   (*env)->ReleaseByteArrayElements (env, byteArray, bytes, 0);
 
   return result;
@@ -92,6 +95,9 @@
   result =
     (jlong) hyfile_write ((IDATA) fd, (void *) (bytes + offset),
                          (IDATA) nbytes);
+  if(result == -1 && hyerror_last_error_number() == HYPORT_ERROR_FILE_LOCKED){
+    throwNewExceptionByName(env, "java/io/IOException", netLookupErrorString(env, HYPORT_ERROR_FILE_LOCKED));
+  }
    (*env)->ReleaseByteArrayElements (env, byteArray, bytes, JNI_ABORT);
 
   return result;

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/shared/nethelp.c
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/shared/nethelp.c?view=diff&rev=518905&r1=518904&r2=518905
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/shared/nethelp.c (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/shared/nethelp.c Fri
Mar 16 02:46:28 2007
@@ -741,6 +741,8 @@
       return "Unable to allocate the fdset structure";
     case HYPORT_ERROR_SOCKET_CONNECTION_REFUSED:
       return "Connection refused";
+	case HYPORT_ERROR_FILE_LOCKED:
+      return "File has been locked by another process";
 
     default:
       return (char *) hysock_error_message ();

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/windows/OSFileSystemWin32.c
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/windows/OSFileSystemWin32.c?view=diff&rev=518905&r1=518904&r2=518905
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/windows/OSFileSystemWin32.c
(original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/windows/OSFileSystemWin32.c
Fri Mar 16 02:46:28 2007
@@ -151,6 +151,10 @@
   int i = 0;
   while(i<size){
     long bytesRead = hyfile_read ((IDATA) fd, (void *) (*(bufs+i)+*(offsets+i)), (IDATA)
*(lengths+i));
+    if(bytesRead == -1 && hyerror_last_error_number() == HYPORT_ERROR_FILE_LOCKED){
+        throwNewExceptionByName(env, "java/io/IOException", netLookupErrorString(env, HYPORT_ERROR_FILE_LOCKED));
+	break;
+    }
     if(bytesRead == -1){
         if (totalRead == 0){
                 totalRead = -1;
@@ -190,6 +194,10 @@
   int i = 0;
   while(i<size){
     long bytesWritten = hyfile_write ((IDATA) fd, (void *) (*(bufs+i)+*(offsets+i)), (IDATA)
*(lengths+i));
+    if(bytesWritten == -1 && hyerror_last_error_number() == HYPORT_ERROR_FILE_LOCKED){
+        throwNewExceptionByName(env, "java/io/IOException", netLookupErrorString(env, HYPORT_ERROR_FILE_LOCKED));
+	break;
+    }
     if(bytesWritten == -1){
         totalWritten = -1;
         break;

Modified: harmony/enhanced/classlib/trunk/modules/nio/make/exclude.linux.x86.drl
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/nio/make/exclude.linux.x86.drl?view=diff&rev=518905&r1=518904&r2=518905
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/nio/make/exclude.linux.x86.drl (original)
+++ harmony/enhanced/classlib/trunk/modules/nio/make/exclude.linux.x86.drl Fri Mar 16 02:46:28
2007
@@ -0,0 +1 @@
+org/apache/harmony/nio/tests/java/nio/channels/FileChannelWin32OnlyTest.java

Modified: harmony/enhanced/classlib/trunk/modules/nio/make/exclude.linux.x86.ibm
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/nio/make/exclude.linux.x86.ibm?view=diff&rev=518905&r1=518904&r2=518905
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/nio/make/exclude.linux.x86.ibm (original)
+++ harmony/enhanced/classlib/trunk/modules/nio/make/exclude.linux.x86.ibm Fri Mar 16 02:46:28
2007
@@ -0,0 +1 @@
+org/apache/harmony/nio/tests/java/nio/channels/FileChannelWin32OnlyTest.java

Modified: harmony/enhanced/classlib/trunk/modules/nio/make/exclude.linux.x86_64.drl
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/nio/make/exclude.linux.x86_64.drl?view=diff&rev=518905&r1=518904&r2=518905
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/nio/make/exclude.linux.x86_64.drl (original)
+++ harmony/enhanced/classlib/trunk/modules/nio/make/exclude.linux.x86_64.drl Fri Mar 16 02:46:28
2007
@@ -0,0 +1 @@
+org/apache/harmony/nio/tests/java/nio/channels/FileChannelWin32OnlyTest.java

Modified: harmony/enhanced/classlib/trunk/modules/nio/make/exclude.linux.x86_64.ibm
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/nio/make/exclude.linux.x86_64.ibm?view=diff&rev=518905&r1=518904&r2=518905
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/nio/make/exclude.linux.x86_64.ibm (original)
+++ harmony/enhanced/classlib/trunk/modules/nio/make/exclude.linux.x86_64.ibm Fri Mar 16 02:46:28
2007
@@ -0,0 +1 @@
+org/apache/harmony/nio/tests/java/nio/channels/FileChannelWin32OnlyTest.java

Added: harmony/enhanced/classlib/trunk/modules/nio/src/test/java/common/org/apache/harmony/nio/tests/java/nio/channels/FileChannelWin32OnlyTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/common/org/apache/harmony/nio/tests/java/nio/channels/FileChannelWin32OnlyTest.java?view=auto&rev=518905
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/nio/src/test/java/common/org/apache/harmony/nio/tests/java/nio/channels/FileChannelWin32OnlyTest.java
(added)
+++ harmony/enhanced/classlib/trunk/modules/nio/src/test/java/common/org/apache/harmony/nio/tests/java/nio/channels/FileChannelWin32OnlyTest.java
Fri Mar 16 02:46:28 2007
@@ -0,0 +1,64 @@
+package org.apache.harmony.nio.tests.java.nio.channels;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.RandomAccessFile;
+import java.nio.ByteBuffer;
+import java.nio.channels.FileChannel;
+
+import junit.framework.TestCase;
+
+public class FileChannelWin32OnlyTest extends TestCase {
+    // Regression test for harmony-2476
+    public void test_lock() throws Exception {
+        FileChannel fc = null, anotherfc = null;
+        String testFileName = "testLockAndTryLock";
+        File f = File.createTempFile(testFileName, "txt");
+        f.deleteOnExit();
+        FileOutputStream out = new FileOutputStream(f);
+        out.write(1);
+        out.close();
+
+        fc = new RandomAccessFile(f, "rw").getChannel();
+        anotherfc = new RandomAccessFile(f, "rw").getChannel();
+
+        assertNotNull(fc.lock());
+
+        ByteBuffer readBuf = ByteBuffer.allocate(100);
+        ByteBuffer writeBuf = ByteBuffer.wrap("bytes".getBytes());
+        try {
+            try {
+                anotherfc.read(readBuf);
+                fail("should throw IOException.");
+            } catch (IOException e) {
+                // expected;
+            }
+
+            try {
+                anotherfc.read(new ByteBuffer[] { readBuf }, 0, 1);
+                fail("should throw IOException.");
+            } catch (IOException e) {
+                // expected;
+            }
+
+            try {
+                anotherfc.write(writeBuf);
+                fail("should throw IOException.");
+            } catch (IOException e) {
+                // expected;
+            }
+
+            try {
+                anotherfc.write(new ByteBuffer[] { writeBuf }, 0, 1);
+                fail("should throw IOException.");
+            } catch (IOException e) {
+                // expected;
+            }
+        } finally {
+            fc.close();
+            anotherfc.close();
+        }
+    }
+
+}

Propchange: harmony/enhanced/classlib/trunk/modules/nio/src/test/java/common/org/apache/harmony/nio/tests/java/nio/channels/FileChannelWin32OnlyTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: harmony/enhanced/classlib/trunk/modules/portlib/src/main/native/include/shared/hyporterror.h
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/portlib/src/main/native/include/shared/hyporterror.h?view=diff&rev=518905&r1=518904&r2=518905
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/portlib/src/main/native/include/shared/hyporterror.h
(original)
+++ harmony/enhanced/classlib/trunk/modules/portlib/src/main/native/include/shared/hyporterror.h
Fri Mar 16 02:46:28 2007
@@ -214,6 +214,7 @@
 #define HYPORT_ERROR_FILE_BADF (HYPORT_ERROR_FILE_BASE-11)
 #define HYPORT_ERROR_FILE_WOULDBLOCK (HYPORT_ERROR_FILE_BASE-12)
 #define HYPORT_ERROR_FILE_INVAL (HYPORT_ERROR_FILE_BASE-13)
+#define HYPORT_ERROR_FILE_LOCKED (HYPORT_ERROR_FILE_BASE-14)
 /** @} */
 
 #endif     /* hyporterror_h */

Modified: harmony/enhanced/classlib/trunk/modules/portlib/src/main/native/port/windows/hyfile.c
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/portlib/src/main/native/port/windows/hyfile.c?view=diff&rev=518905&r1=518904&r2=518905
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/portlib/src/main/native/port/windows/hyfile.c
(original)
+++ harmony/enhanced/classlib/trunk/modules/portlib/src/main/native/port/windows/hyfile.c
Fri Mar 16 02:46:28 2007
@@ -65,6 +65,8 @@
       return HYPORT_ERROR_FILE_EXIST;
     case ERROR_NOT_ENOUGH_MEMORY:
       return HYPORT_ERROR_FILE_SYSTEMFULL;
+    case ERROR_LOCK_VIOLATION:
+      return HYPORT_ERROR_FILE_LOCKED;
     default:
       return HYPORT_ERROR_FILE_OPFAILED;
     }



Mime
View raw message