hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cutt...@apache.org
Subject svn commit: r442668 - in /lucene/hadoop/trunk: CHANGES.txt src/c++/libhdfs/hdfs.c
Date Tue, 12 Sep 2006 18:28:06 GMT
Author: cutting
Date: Tue Sep 12 11:28:06 2006
New Revision: 442668

URL: http://svn.apache.org/viewvc?view=rev&rev=442668
Log:
HADOOP-520.  Fix a bug in libhdfs, where write failures were not correctly returning error
codes.  Contributed by Arun.

Modified:
    lucene/hadoop/trunk/CHANGES.txt
    lucene/hadoop/trunk/src/c++/libhdfs/hdfs.c

Modified: lucene/hadoop/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/hadoop/trunk/CHANGES.txt?view=diff&rev=442668&r1=442667&r2=442668
==============================================================================
--- lucene/hadoop/trunk/CHANGES.txt (original)
+++ lucene/hadoop/trunk/CHANGES.txt Tue Sep 12 11:28:06 2006
@@ -1,6 +1,12 @@
 Hadoop Change Log
 
 
+Trunk (unreleased changes)
+
+ 1. HADOOP-520.  Fix a bug in libhdfs, where write failures were not
+    correctly returning error codes.  (Arun C Murthy via cutting)
+
+
 Release 0.6.0 - 2006-08-08
 
  1. HADOOP-427.  Replace some uses of DatanodeDescriptor in the DFS

Modified: lucene/hadoop/trunk/src/c++/libhdfs/hdfs.c
URL: http://svn.apache.org/viewvc/lucene/hadoop/trunk/src/c%2B%2B/libhdfs/hdfs.c?view=diff&rev=442668&r1=442667&r2=442668
==============================================================================
--- lucene/hadoop/trunk/src/c++/libhdfs/hdfs.c (original)
+++ lucene/hadoop/trunk/src/c++/libhdfs/hdfs.c Tue Sep 12 11:28:06 2006
@@ -574,13 +574,17 @@
 
     jthrowable jException;
     jbyteArray jbWarray;
-    jint noWrittenBytes = 0;
 
     //Sanity check
     if (!f || f->type == UNINITIALIZED) {
         errno = EBADF;
         return -1;
     }
+    
+    if (length < 0) {
+    	errno = EINVAL;
+    	return -1;
+    }
 
     //Error checking... make sure that this file is 'writable'
     if (f->type != OUTPUT) {
@@ -589,20 +593,23 @@
         return -1;
     }
 
-    //Write the requisite bytes into the file
-    jbWarray = (*env)->NewByteArray(env, length);
-    (*env)->SetByteArrayRegion(env, jbWarray, 0, length, buffer);
-    if (invokeMethod(env, NULL, &jException, INSTANCE, jOutputStream,
-                "org/apache/hadoop/fs/FSDataOutputStream", "write", 
-                "([B)V", jbWarray)) {
-        fprintf(stderr, 
-            "Call to org.apache.hadoop.fs.FSDataOutputStream::write failed!\n"
-            );
-        errno = EINTERNAL;
-        noWrittenBytes = -1;
-    } 
-    (*env)->ReleaseByteArrayElements(env, jbWarray, 
-                (*env)->GetByteArrayElements(env, jbWarray, 0), JNI_ABORT);
+	// 'length' equals 'zero' is a valid use-case according to Posix!
+	if (length != 0) {
+	    //Write the requisite bytes into the file
+	    jbWarray = (*env)->NewByteArray(env, length);
+	    (*env)->SetByteArrayRegion(env, jbWarray, 0, length, buffer);
+	    if (invokeMethod(env, NULL, &jException, INSTANCE, jOutputStream,
+	                "org/apache/hadoop/fs/FSDataOutputStream", "write", 
+	                "([B)V", jbWarray)) {
+	        fprintf(stderr, 
+	            "Call to org.apache.hadoop.fs.FSDataOutputStream::write failed!\n"
+	            );
+	        errno = EINTERNAL;
+	        length = -1;
+	    } 
+	    (*env)->ReleaseByteArrayElements(env, jbWarray, 
+	                (*env)->GetByteArrayElements(env, jbWarray, 0), JNI_ABORT);
+	}
 
     //Return no. of bytes succesfully written (libc way)
     //i.e. 'length' itself! ;-)



Mime
View raw message