Przeglądaj źródła

HADOOP-9681. Merging change r1499069 from trunk to branch-2.

git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/branch-2@1499070 13f79535-47bb-0310-9956-ffa450edef68
Chris Nauroth 12 lat temu
rodzic
commit
65bbb30101

+ 3 - 0
hadoop-common-project/hadoop-common/CHANGES.txt

@@ -518,6 +518,9 @@ Release 2.1.0-beta - 2013-07-02
     HADOOP-9678. TestRPC#testStopsAllThreads intermittently fails on Windows.
     (Ivan Mitic via cnauroth)
 
+    HADOOP-9681. FileUtil.unTarUsingJava() should close the InputStream upon
+    finishing. (Chuan Liu via cnauroth)
+
     HADOOP-9665. Fixed BlockDecompressorStream#decompress to return -1 rather
     than throw EOF at end of file. (Zhijie Shen via acmurthy)
 

+ 15 - 10
hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FileUtil.java

@@ -662,18 +662,23 @@ public class FileUtil {
   private static void unTarUsingJava(File inFile, File untarDir,
       boolean gzipped) throws IOException {
     InputStream inputStream = null;
-    if (gzipped) {
-      inputStream = new BufferedInputStream(new GZIPInputStream(
-          new FileInputStream(inFile)));
-    } else {
-      inputStream = new BufferedInputStream(new FileInputStream(inFile));
-    }
+    TarArchiveInputStream tis = null;
+    try {
+      if (gzipped) {
+        inputStream = new BufferedInputStream(new GZIPInputStream(
+            new FileInputStream(inFile)));
+      } else {
+        inputStream = new BufferedInputStream(new FileInputStream(inFile));
+      }
 
-    TarArchiveInputStream tis = new TarArchiveInputStream(inputStream);
+      tis = new TarArchiveInputStream(inputStream);
 
-    for (TarArchiveEntry entry = tis.getNextTarEntry(); entry != null;) {
-      unpackEntries(tis, entry, untarDir);
-      entry = tis.getNextTarEntry();
+      for (TarArchiveEntry entry = tis.getNextTarEntry(); entry != null;) {
+        unpackEntries(tis, entry, untarDir);
+        entry = tis.getNextTarEntry();
+      }
+    } finally {
+      IOUtils.cleanup(LOG, tis, inputStream);
     }
   }