Return-Path:
X-Original-To: apmail-ant-notifications-archive@minotaur.apache.org
Delivered-To: apmail-ant-notifications-archive@minotaur.apache.org
Received: from mail.apache.org (hermes.apache.org [140.211.11.3])
by minotaur.apache.org (Postfix) with SMTP id 43895105B2
for ;
Fri, 9 Aug 2013 07:01:05 +0000 (UTC)
Received: (qmail 51021 invoked by uid 500); 9 Aug 2013 07:01:04 -0000
Delivered-To: apmail-ant-notifications-archive@ant.apache.org
Received: (qmail 49778 invoked by uid 500); 9 Aug 2013 07:00:53 -0000
Mailing-List: contact notifications-help@ant.apache.org; run by ezmlm
Precedence: bulk
List-Help:
List-Unsubscribe:
List-Post:
List-Id:
Reply-To: dev@ant.apache.org
Delivered-To: mailing list notifications@ant.apache.org
Received: (qmail 49745 invoked by uid 99); 9 Aug 2013 07:00:51 -0000
Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230)
by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 09 Aug 2013 07:00:51 +0000
X-ASF-Spam-Status: No, hits=-2000.0 required=5.0
tests=ALL_TRUSTED
X-Spam-Check-By: apache.org
Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4)
by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 09 Aug 2013 07:00:48 +0000
Received: from eris.apache.org (localhost [127.0.0.1])
by eris.apache.org (Postfix) with ESMTP id 7966C2388A29
for ; Fri, 9 Aug 2013 07:00:26 +0000 (UTC)
Content-Type: text/plain; charset="utf-8"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Subject: svn commit: r1512171 - in /ant/core/trunk: WHATSNEW
src/main/org/apache/tools/tar/TarOutputStream.java
Date: Fri, 09 Aug 2013 07:00:26 -0000
To: notifications@ant.apache.org
From: bodewig@apache.org
X-Mailer: svnmailer-1.0.9
Message-Id: <20130809070026.7966C2388A29@eris.apache.org>
X-Virus-Checked: Checked by ClamAV on apache.org
Author: bodewig
Date: Fri Aug 9 07:00:25 2013
New Revision: 1512171
URL: http://svn.apache.org/r1512171
Log:
merge TAR long link handling fix by Emmanuel Bourg
Modified:
ant/core/trunk/WHATSNEW
ant/core/trunk/src/main/org/apache/tools/tar/TarOutputStream.java (contents, props changed)
Modified: ant/core/trunk/WHATSNEW
URL: http://svn.apache.org/viewvc/ant/core/trunk/WHATSNEW?rev=1512171&r1=1512170&r2=1512171&view=diff
==============================================================================
--- ant/core/trunk/WHATSNEW (original)
+++ ant/core/trunk/WHATSNEW Fri Aug 9 07:00:25 2013
@@ -14,6 +14,8 @@ Other changes:
* Documentation fix for if/unless attributes. PR 55359.
+ * tar entries with long link names are now handled the same way as
+ entries with long names.
Changes from Ant 1.9.1 TO Ant 1.9.2
===================================
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=1512171&r1=1512170&r2=1512171&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 Fri Aug 9 07:00:25 2013
@@ -273,31 +273,13 @@ public class TarOutputStream extends Fil
}
Map paxHeaders = new HashMap();
final String entryName = entry.getName();
- final ByteBuffer encodedName = encoding.encode(entryName);
- final int nameLen = encodedName.limit() - encodedName.position();
- boolean paxHeaderContainsPath = false;
- if (nameLen >= TarConstants.NAMELEN) {
+ boolean paxHeaderContainsPath = handleLongName(entryName, paxHeaders, "path",
+ TarConstants.LF_GNUTYPE_LONGNAME);
- if (longFileMode == LONGFILE_POSIX) {
- paxHeaders.put("path", entryName);
- paxHeaderContainsPath = true;
- } else if (longFileMode == LONGFILE_GNU) {
- // create a TarEntry for the LongLink, the contents
- // of which are the entry's name
- TarEntry longLinkEntry = new TarEntry(TarConstants.GNU_LONGLINK,
- TarConstants.LF_GNUTYPE_LONGNAME);
-
- longLinkEntry.setSize(nameLen + 1); // +1 for NUL
- putNextEntry(longLinkEntry);
- write(encodedName.array(), encodedName.arrayOffset(), nameLen);
- write(0); // NUL terminator
- closeEntry();
- } else if (longFileMode != LONGFILE_TRUNCATE) {
- throw new RuntimeException("file name '" + entryName
- + "' is too long ( > "
- + TarConstants.NAMELEN + " bytes)");
- }
- }
+ final String linkName = entry.getLinkName();
+ boolean paxHeaderContainsLinkPath = linkName != null
+ && handleLongName(linkName, paxHeaders, "linkpath",
+ TarConstants.LF_GNUTYPE_LONGLINK);
if (bigNumberMode == BIGNUMBER_POSIX) {
addPaxHeadersForBigNumbers(paxHeaders, entry);
@@ -310,10 +292,10 @@ public class TarOutputStream extends Fil
paxHeaders.put("path", entryName);
}
- if (addPaxHeadersForNonAsciiNames
+ if (addPaxHeadersForNonAsciiNames && !paxHeaderContainsLinkPath
&& (entry.isLink() || entry.isSymbolicLink())
- && !ASCII.canEncode(entry.getLinkName())) {
- paxHeaders.put("linkpath", entry.getLinkName());
+ && !ASCII.canEncode(linkName)) {
+ paxHeaders.put("linkpath", linkName);
}
if (paxHeaders.size() > 0) {
@@ -596,4 +578,54 @@ public class TarOutputStream extends Fil
+ maxValue + " )");
}
}
+
+ /**
+ * Handles long file or link names according to the longFileMode setting.
+ *
+ * I.e. if the given name is too long to be written to a plain
+ * tar header then
+ *
+ * - it creates a pax header who's name is given by the
+ * paxHeaderName parameter if longFileMode is POSIX
+ * - it creates a GNU longlink entry who's type is given by
+ * the linkType parameter if longFileMode is GNU
+ * - throws an exception othewise.
+ *
+ *
+ * @param name the name to write
+ * @param paxHeaders current map of pax headers
+ * @param paxHeaderName name of the pax header to write
+ * @param linkType type of the GNU entry to write
+ * @return whether a pax header has been written.
+ */
+ private boolean handleLongName(String name,
+ Map paxHeaders,
+ String paxHeaderName, byte linkType)
+ throws IOException {
+ final ByteBuffer encodedName = encoding.encode(name);
+ final int len = encodedName.limit() - encodedName.position();
+ if (len >= TarConstants.NAMELEN) {
+
+ if (longFileMode == LONGFILE_POSIX) {
+ paxHeaders.put(paxHeaderName, name);
+ return true;
+ } else if (longFileMode == LONGFILE_GNU) {
+ // create a TarEntry for the LongLink, the contents
+ // of which are the link's name
+ TarEntry longLinkEntry =
+ new TarEntry(TarConstants.GNU_LONGLINK, linkType);
+
+ longLinkEntry.setSize(len + 1); // +1 for NUL
+ putNextEntry(longLinkEntry);
+ write(encodedName.array(), encodedName.arrayOffset(), len);
+ write(0); // NUL terminator
+ closeEntry();
+ } else if (longFileMode != LONGFILE_TRUNCATE) {
+ throw new RuntimeException(paxHeaderName + " '" + name
+ + "' is too long ( > "
+ + TarConstants.NAMELEN + " bytes)");
+ }
+ }
+ return false;
+ }
}
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:r1512161