hive-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ecapri...@apache.org
Subject svn commit: r1354816 - /hive/trunk/common/src/java/org/apache/hadoop/hive/common/FileUtils.java
Date Thu, 28 Jun 2012 05:00:11 GMT
Author: ecapriolo
Date: Thu Jun 28 05:00:10 2012
New Revision: 1354816

URL: http://svn.apache.org/viewvc?rev=1354816&view=rev
Log:
HIVE-3206 FileUtils.tar assumes wrong directory in some cases. Navis Ryu (via egc)

Modified:
    hive/trunk/common/src/java/org/apache/hadoop/hive/common/FileUtils.java

Modified: hive/trunk/common/src/java/org/apache/hadoop/hive/common/FileUtils.java
URL: http://svn.apache.org/viewvc/hive/trunk/common/src/java/org/apache/hadoop/hive/common/FileUtils.java?rev=1354816&r1=1354815&r2=1354816&view=diff
==============================================================================
--- hive/trunk/common/src/java/org/apache/hadoop/hive/common/FileUtils.java (original)
+++ hive/trunk/common/src/java/org/apache/hadoop/hive/common/FileUtils.java Thu Jun 28 05:00:10
2012
@@ -255,27 +255,25 @@ public final class FileUtils {
    */
   public static void tar(String parentDir, String[] inputFiles, String outputFile)
       throws IOException {
-    TarArchiveOutputStream tOut = null;
 
+    FileOutputStream out = null;
     try {
-      tOut = new TarArchiveOutputStream(
-          new GzipCompressorOutputStream(
-              new BufferedOutputStream(
-                  new FileOutputStream(new File(parentDir, outputFile)))));
+      out = new FileOutputStream(new File(parentDir, outputFile));
+      TarArchiveOutputStream tOut = new TarArchiveOutputStream(
+          new GzipCompressorOutputStream(new BufferedOutputStream(out)));
 
       for (int i = 0; i < inputFiles.length; i++) {
-        File f = new File(inputFiles[i]);
+        File f = new File(parentDir, inputFiles[i]);
         TarArchiveEntry tarEntry = new TarArchiveEntry(f, f.getName());
         tOut.setLongFileMode(TarArchiveOutputStream.LONGFILE_GNU);
         tOut.putArchiveEntry(tarEntry);
-        IOUtils.copy(new FileInputStream(f), tOut);
+        IOUtils.copy(new FileInputStream(f), tOut); // copy with 8K buffer, not close
         tOut.closeArchiveEntry();
       }
+      tOut.close(); // finishes inside
     } finally {
-      if(tOut != null ) {
-        tOut.finish();
-        tOut.close();
-      }
+      // TarArchiveOutputStream seemed not to close files properly in error situation
+      org.apache.hadoop.io.IOUtils.closeStream(out);
     }
   }
 }



Mime
View raw message