ant-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject svn commit: r1426337 - in /ant/core/trunk/src/main/org/apache/tools: tar/TarOutputStream.java tar/TarUtils.java zip/ZipOutputStream.java
Date Thu, 27 Dec 2012 21:41:24 GMT
Author: bodewig
Date: Thu Dec 27 21:41:24 2012
New Revision: 1426337

URL: http://svn.apache.org/viewvc?rev=1426337&view=rev
Log:
merge recent fixes from Compress' tar package

Modified:
    ant/core/trunk/src/main/org/apache/tools/tar/TarOutputStream.java   (contents, props changed)
    ant/core/trunk/src/main/org/apache/tools/tar/TarUtils.java   (contents, props changed)
    ant/core/trunk/src/main/org/apache/tools/zip/ZipOutputStream.java   (contents, props changed)

Modified: ant/core/trunk/src/main/org/apache/tools/tar/TarOutputStream.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/tar/TarOutputStream.java?rev=1426337&r1=1426336&r2=1426337&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/tar/TarOutputStream.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/tar/TarOutputStream.java Thu Dec 27 21:41:24
2012
@@ -28,6 +28,7 @@ import java.io.FilterOutputStream;
 import java.io.IOException;
 import java.io.OutputStream;
 import java.io.StringWriter;
+import java.nio.ByteBuffer;
 import java.util.HashMap;
 import java.util.Map;
 import org.apache.tools.zip.ZipEncoding;
@@ -272,9 +273,10 @@ public class TarOutputStream extends Fil
         }
         Map<String, String> paxHeaders = new HashMap<String, String>();
         final String entryName = entry.getName();
-        final byte[] nameBytes = encoding.encode(entryName).array();
+        final ByteBuffer encodedName = encoding.encode(entryName);
+        final int nameLen = encodedName.limit() - encodedName.position();
         boolean paxHeaderContainsPath = false;
-        if (nameBytes.length >= TarConstants.NAMELEN) {
+        if (nameLen >= TarConstants.NAMELEN) {
 
             if (longFileMode == LONGFILE_POSIX) {
                 paxHeaders.put("path", entryName);
@@ -285,9 +287,9 @@ public class TarOutputStream extends Fil
                 TarEntry longLinkEntry = new TarEntry(TarConstants.GNU_LONGLINK,
                                                       TarConstants.LF_GNUTYPE_LONGNAME);
 
-                longLinkEntry.setSize(nameBytes.length + 1); // +1 for NUL
+                longLinkEntry.setSize(nameLen + 1); // +1 for NUL
                 putNextEntry(longLinkEntry);
-                write(nameBytes);
+                write(encodedName.array(), encodedName.arrayOffset(), nameLen);
                 write(0); // NUL terminator
                 closeEntry();
             } else if (longFileMode != LONGFILE_TRUNCATE) {
@@ -483,6 +485,11 @@ public class TarOutputStream extends Fil
     void writePaxHeaders(String entryName,
                          Map<String, String> headers) throws IOException {
         String name = "./PaxHeaders.X/" + stripTo7Bits(entryName);
+        while (name.endsWith("/")) {
+            // TarEntry's constructor would think this is a directory
+            // and not allow any data to be written
+            name = name.substring(0, name.length() - 1);
+        }
         if (name.length() >= TarConstants.NAMELEN) {
             name = name.substring(0, TarConstants.NAMELEN - 1);
         }

Propchange: ant/core/trunk/src/main/org/apache/tools/tar/TarOutputStream.java
------------------------------------------------------------------------------
  Merged /commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveOutputStream.java:r1426319,1426334

Modified: ant/core/trunk/src/main/org/apache/tools/tar/TarUtils.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/tar/TarUtils.java?rev=1426337&r1=1426336&r2=1426337&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/tar/TarUtils.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/tar/TarUtils.java Thu Dec 27 21:41:24 2012
@@ -350,7 +350,7 @@ public class TarUtils {
         while (b.limit() > length && len > 0) {
             b = encoding.encode(name.substring(0, --len));
         }
-        final int limit = b.limit();
+        final int limit = b.limit() - b.position();
         System.arraycopy(b.array(), b.arrayOffset(), buf, offset, limit);
 
         // Pad any remaining output bytes with NUL

Propchange: ant/core/trunk/src/main/org/apache/tools/tar/TarUtils.java
------------------------------------------------------------------------------
--- svn:mergeinfo (added)
+++ svn:mergeinfo Thu Dec 27 21:41:24 2012
@@ -0,0 +1 @@
+/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/tar/TarUtils.java:1426326

Modified: ant/core/trunk/src/main/org/apache/tools/zip/ZipOutputStream.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/zip/ZipOutputStream.java?rev=1426337&r1=1426336&r2=1426337&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/zip/ZipOutputStream.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/zip/ZipOutputStream.java Thu Dec 27 21:41:24
2012
@@ -986,7 +986,8 @@ public class ZipOutputStream extends Fil
         written += SHORT;
 
         // file name
-        writeOut(name.array(), name.arrayOffset(), name.limit());
+        writeOut(name.array(), name.arrayOffset(),
+                 name.limit() - name.position());
         written += name.limit();
 
         // extra field
@@ -1009,7 +1010,8 @@ public class ZipOutputStream extends Fil
             ze.addExtraField(new UnicodePathExtraField(ze.getName(),
                                                        name.array(),
                                                        name.arrayOffset(),
-                                                       name.limit()));
+                                                       name.limit()
+                                                       - name.position()));
         }
 
         String comm = ze.getComment();
@@ -1023,7 +1025,8 @@ public class ZipOutputStream extends Fil
                 ze.addExtraField(new UnicodeCommentExtraField(comm,
                                                               commentB.array(),
                                                               commentB.arrayOffset(),
-                                                              commentB.limit())
+                                                              commentB.limit()
+                                                              - commentB.position())
                                  );
             }
         }
@@ -1159,7 +1162,8 @@ public class ZipOutputStream extends Fil
         written += WORD;
 
         // file name
-        writeOut(name.array(), name.arrayOffset(), name.limit());
+        writeOut(name.array(), name.arrayOffset(),
+                 name.limit() - name.position());
         written += name.limit();
 
         // extra field
@@ -1167,7 +1171,8 @@ public class ZipOutputStream extends Fil
         written += extra.length;
 
         // file comment
-        writeOut(commentB.array(), commentB.arrayOffset(), commentB.limit());
+        writeOut(commentB.array(), commentB.arrayOffset(),
+                 commentB.limit() - commentB.position());
         written += commentB.limit();
     }
 
@@ -1233,7 +1238,8 @@ public class ZipOutputStream extends Fil
         // ZIP file comment
         ByteBuffer data = this.zipEncoding.encode(comment);
         writeOut(ZipShort.getBytes(data.limit()));
-        writeOut(data.array(), data.arrayOffset(), data.limit());
+        writeOut(data.array(), data.arrayOffset(),
+                 data.limit() - data.position());
     }
 
     /**

Propchange: ant/core/trunk/src/main/org/apache/tools/zip/ZipOutputStream.java
------------------------------------------------------------------------------
  Merged /commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveOutputStream.java:r1426326



Mime
View raw message