Repository: hadoop
Updated Branches:
  refs/heads/branch-2 2d67dff15 -> d21bc811d
  refs/heads/trunk 310743403 -> 48ca23def


HADOOP-7817. RawLocalFileSystem.append() should give FSDataOutputStream with 
accurate .getPos() (Contributed by kanaka kumar avvaru)


Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo
Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/48ca23de
Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/48ca23de
Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/48ca23de

Branch: refs/heads/trunk
Commit: 48ca23def1d1c28448a65238814070e79c8f4c4e
Parents: 3107434
Author: Vinayakumar B <[email protected]>
Authored: Wed Jun 10 11:05:58 2015 +0530
Committer: Vinayakumar B <[email protected]>
Committed: Wed Jun 10 11:05:58 2015 +0530

----------------------------------------------------------------------
 hadoop-common-project/hadoop-common/CHANGES.txt |  3 ++
 .../apache/hadoop/fs/RawLocalFileSystem.java    |  6 ++--
 .../apache/hadoop/fs/TestLocalFileSystem.java   | 35 ++++++++++++++++++++
 3 files changed, 42 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hadoop/blob/48ca23de/hadoop-common-project/hadoop-common/CHANGES.txt
----------------------------------------------------------------------
diff --git a/hadoop-common-project/hadoop-common/CHANGES.txt 
b/hadoop-common-project/hadoop-common/CHANGES.txt
index 5e8f5be..134c834 100644
--- a/hadoop-common-project/hadoop-common/CHANGES.txt
+++ b/hadoop-common-project/hadoop-common/CHANGES.txt
@@ -846,6 +846,9 @@ Release 2.8.0 - UNRELEASED
     HADOOP-12073. Azure FileSystem PageBlobInputStream does not return -1 on
     EOF. (Ivan Mitic via cnauroth)
 
+    HADOOP-7817. RawLocalFileSystem.append() should give FSDataOutputStream
+    with accurate .getPos() (kanaka kumar avvaru via vinayakumarb)
+
 Release 2.7.1 - UNRELEASED
 
   INCOMPATIBLE CHANGES

http://git-wip-us.apache.org/repos/asf/hadoop/blob/48ca23de/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/RawLocalFileSystem.java
----------------------------------------------------------------------
diff --git 
a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/RawLocalFileSystem.java
 
b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/RawLocalFileSystem.java
index b94d9d9..96d1ab4 100644
--- 
a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/RawLocalFileSystem.java
+++ 
b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/RawLocalFileSystem.java
@@ -271,11 +271,13 @@ public class RawLocalFileSystem extends FileSystem {
     if (!exists(f)) {
       throw new FileNotFoundException("File " + f + " not found");
     }
-    if (getFileStatus(f).isDirectory()) {
+    FileStatus status = getFileStatus(f);
+    if (status.isDirectory()) {
       throw new IOException("Cannot append to a diretory (=" + f + " )");
     }
     return new FSDataOutputStream(new BufferedOutputStream(
-        createOutputStreamWithMode(f, true, null), bufferSize), statistics);
+        createOutputStreamWithMode(f, true, null), bufferSize), statistics,
+        status.getLen());
   }
 
   @Override

http://git-wip-us.apache.org/repos/asf/hadoop/blob/48ca23de/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestLocalFileSystem.java
----------------------------------------------------------------------
diff --git 
a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestLocalFileSystem.java
 
b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestLocalFileSystem.java
index 73a92a1..df5cba9 100644
--- 
a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestLocalFileSystem.java
+++ 
b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestLocalFileSystem.java
@@ -561,4 +561,39 @@ public class TestLocalFileSystem {
     assertEquals("resolvePath did not strip fragment from Path", pathQualified,
         resolved);
   }
+
+  @Test
+  public void testAppendSetsPosCorrectly() throws Exception {
+    FileSystem fs = fileSys.getRawFileSystem();
+    Path file = new Path(TEST_ROOT_DIR, "test-append");
+
+    fs.delete(file, true);
+    FSDataOutputStream out = fs.create(file);
+
+    try {
+      out.write("text1".getBytes());
+    } finally {
+      out.close();
+    }
+
+    // Verify the position
+    out = fs.append(file);
+    try {
+      assertEquals(5, out.getPos());
+      out.write("text2".getBytes());
+    } finally {
+      out.close();
+    }
+
+    // Verify the content
+    FSDataInputStream in = fs.open(file);
+    try {
+      byte[] buf = new byte[in.available()];
+      in.readFully(buf);
+      assertEquals("text1text2", new String(buf));
+    } finally {
+      in.close();
+    }
+  }
+
 }

Reply via email to