Return-Path: X-Original-To: apmail-commons-commits-archive@minotaur.apache.org Delivered-To: apmail-commons-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id B7A829F2F for ; Thu, 8 Dec 2011 16:13:15 +0000 (UTC) Received: (qmail 85540 invoked by uid 500); 8 Dec 2011 16:13:15 -0000 Delivered-To: apmail-commons-commits-archive@commons.apache.org Received: (qmail 85491 invoked by uid 500); 8 Dec 2011 16:13:15 -0000 Mailing-List: contact commits-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@commons.apache.org Delivered-To: mailing list commits@commons.apache.org Received: (qmail 85484 invoked by uid 99); 8 Dec 2011 16:13:15 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 08 Dec 2011 16:13:15 +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; Thu, 08 Dec 2011 16:13:14 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 585A42388A32 for ; Thu, 8 Dec 2011 16:12:53 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1211943 - in /commons/proper/compress/trunk/src: main/java/org/apache/commons/compress/archivers/tar/TarArchiveOutputStream.java test/java/org/apache/commons/compress/archivers/tar/TarArchiveOutputStreamTest.java Date: Thu, 08 Dec 2011 16:12:53 -0000 To: commits@commons.apache.org From: bodewig@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20111208161253.585A42388A32@eris.apache.org> Author: bodewig Date: Thu Dec 8 16:12:52 2011 New Revision: 1211943 URL: http://svn.apache.org/viewvc?rev=1211943&view=rev Log: Support the POSIX way of writing tar entries with names longer than 100 chars. COMPRESS-166 Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveOutputStream.java commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveOutputStreamTest.java Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveOutputStream.java URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveOutputStream.java?rev=1211943&r1=1211942&r2=1211943&view=diff ============================================================================== --- commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveOutputStream.java (original) +++ commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveOutputStream.java Thu Dec 8 16:12:52 2011 @@ -45,6 +45,9 @@ public class TarArchiveOutputStream exte /** GNU tar extensions are used to store long file names in the archive. */ public static final int LONGFILE_GNU = 2; + /** POSIX/PAX extensions are used to store long file names in the archive. */ + public static final int LONGFILE_POSIX = 3; + /** Fail if a big file (> 8GiB) is required in the archive. */ public static final int BIGFILE_ERROR = 0; @@ -213,7 +216,9 @@ public class TarArchiveOutputStream exte Map paxHeaders = new HashMap(); if (entry.getName().length() >= TarConstants.NAMELEN) { - if (longFileMode == LONGFILE_GNU) { + if (longFileMode == LONGFILE_POSIX) { + paxHeaders.put("path", entry.getName()); + } else if (longFileMode == LONGFILE_GNU) { // create a TarEntry for the LongLink, the contents // of which are the entry's name TarArchiveEntry longLinkEntry = new TarArchiveEntry(TarConstants.GNU_LONGLINK, @@ -385,8 +390,8 @@ public class TarArchiveOutputStream exte void writePaxHeaders(String entryName, Map headers) throws IOException { String name = "./PaxHeaders.X/" + entryName; - if (name.length() > TarConstants.NAMELEN) { - name = name.substring(0, TarConstants.NAMELEN); + if (name.length() >= TarConstants.NAMELEN) { + name = name.substring(0, TarConstants.NAMELEN - 1); } TarArchiveEntry pex = new TarArchiveEntry(name, TarConstants.LF_PAX_EXTENDED_HEADER_LC); Modified: commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveOutputStreamTest.java URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveOutputStreamTest.java?rev=1211943&r1=1211942&r2=1211943&view=diff ============================================================================== --- commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveOutputStreamTest.java (original) +++ commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveOutputStreamTest.java Thu Dec 8 16:12:52 2011 @@ -182,4 +182,26 @@ public class TarArchiveOutputStreamTest return bos.toByteArray(); } + + public void testWriteLongFileNamePosixMode() throws Exception { + String n = "01234567890123456789012345678901234567890123456789" + + "01234567890123456789012345678901234567890123456789" + + "01234567890123456789012345678901234567890123456789"; + TarArchiveEntry t = + new TarArchiveEntry(n); + t.setSize(10 * 1024); + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + TarArchiveOutputStream tos = new TarArchiveOutputStream(bos); + tos.setLongFileMode(TarArchiveOutputStream.LONGFILE_POSIX); + tos.putArchiveEntry(t); + tos.write(new byte[10 * 1024]); + tos.closeArchiveEntry(); + byte[] data = bos.toByteArray(); + assertEquals("160 path=" + n + "\n", + new String(data, 512, 160, "UTF-8")); + TarArchiveInputStream tin = + new TarArchiveInputStream(new ByteArrayInputStream(data)); + TarArchiveEntry e = tin.getNextTarEntry(); + assertEquals(n, e.getName()); + } } \ No newline at end of file