瀏覽代碼

HADOOP-10575. Small fixes for XAttrCommands and test. Contributed by Yi Liu.

git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/HDFS-2006@1592561 13f79535-47bb-0310-9956-ffa450edef68
Uma Maheswara Rao G 11 年之前
父節點
當前提交
1294e34ca2

+ 9 - 7
hadoop-common-project/hadoop-common/CHANGES-HDFS-2006.txt

@@ -8,18 +8,20 @@ HDFS-2006 (Unreleased)
 
   IMPROVEMENTS
 
-  HADOOP-10520. Extended attributes definition and FileSystem APIs for
-  extended attributes. (Yi Liu via wang)
+    HADOOP-10520. Extended attributes definition and FileSystem APIs for
+    extended attributes. (Yi Liu via wang)
 
-  HADOOP-10546. Javadoc and other small fixes for extended attributes in
-  hadoop-common. (Charles Lamb via wang)
+    HADOOP-10546. Javadoc and other small fixes for extended attributes in
+    hadoop-common. (Charles Lamb via wang)
 
-  HADOOP-10521. FsShell commands for extended attributes. (Yi Liu via wang)
+    HADOOP-10521. FsShell commands for extended attributes. (Yi Liu via wang)
 
-  HADOOP-10548. Improve FsShell xattr error handling and other fixes. (Charles Lamb via umamahesh)
+    HADOOP-10548. Improve FsShell xattr error handling and other fixes. (Charles Lamb via umamahesh)
 
-  HADOOP-10567. Shift XAttr value encoding code out for reuse. (Yi Liu via umamahesh)
+    HADOOP-10567. Shift XAttr value encoding code out for reuse. (Yi Liu via umamahesh)
 
   OPTIMIZATIONS
 
   BUG FIXES
+    
+    HADOOP-10575. Small fixes for XAttrCommands and test. (Yi Liu via umamahesh)

+ 6 - 4
hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/XAttrCommands.java

@@ -118,10 +118,12 @@ class XAttrCommands extends FsCommand {
     }
     
     private void printXAttr(String name, byte[] value) throws IOException{
-      if (value != null && value.length != 0) {
-        out.println(name + "=" + XAttrCodec.encodeValue(value, encoding));
-      } else {
-        out.println(name);
+      if (value != null) {
+        if (value.length != 0) {
+          out.println(name + "=" + XAttrCodec.encodeValue(value, encoding));
+        } else {
+          out.println(name);
+        }
       }
     }
   }

+ 10 - 0
hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/shell/TestXAttrCommands.java

@@ -27,6 +27,7 @@ import java.io.PrintStream;
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.fs.FsShell;
 import org.apache.hadoop.util.ToolRunner;
+import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
 
@@ -34,12 +35,21 @@ public class TestXAttrCommands {
   private final ByteArrayOutputStream errContent = 
       new ByteArrayOutputStream();
   private Configuration conf = null;
+  private PrintStream initialStdErr;
 
   @Before
   public void setup() throws IOException {
+    errContent.reset();
+    initialStdErr = System.err;
     System.setErr(new PrintStream(errContent));
     conf = new Configuration();
   }
+  
+  @After
+  public void cleanUp() throws Exception {
+    errContent.reset();
+    System.setErr(initialStdErr);
+  }
 
   @Test
   public void testGetfattrValidations() throws Exception {