diff --git a/src/main/org/apache/tools/tar/TarOutputStream.java b/src/main/org/apache/tools/tar/TarOutputStream.java index 9eddaa02b..737ae6504 100644 --- a/src/main/org/apache/tools/tar/TarOutputStream.java +++ b/src/main/org/apache/tools/tar/TarOutputStream.java @@ -274,12 +274,12 @@ public class TarOutputStream extends FilterOutputStream { Map paxHeaders = new HashMap(); final String entryName = entry.getName(); boolean paxHeaderContainsPath = handleLongName(entryName, paxHeaders, "path", - TarConstants.LF_GNUTYPE_LONGNAME); + TarConstants.LF_GNUTYPE_LONGNAME, "file name"); final String linkName = entry.getLinkName(); boolean paxHeaderContainsLinkPath = linkName != null && handleLongName(linkName, paxHeaders, "linkpath", - TarConstants.LF_GNUTYPE_LONGLINK); + TarConstants.LF_GNUTYPE_LONGLINK, "link name"); if (bigNumberMode == BIGNUMBER_POSIX) { addPaxHeadersForBigNumbers(paxHeaders, entry); @@ -589,18 +589,20 @@ public class TarOutputStream extends FilterOutputStream { * 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.
  • + *
  • it throws an exception if longFileMode is ERROR
  • + *
  • it truncates the name if longFileMode is TRUNCATE
  • *

    * * @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 + * @param fieldName the name of the field * @return whether a pax header has been written. */ private boolean handleLongName(String name, Map paxHeaders, - String paxHeaderName, byte linkType) + String paxHeaderName, byte linkType, String fieldName) throws IOException { final ByteBuffer encodedName = encoding.encode(name); final int len = encodedName.limit() - encodedName.position(); @@ -621,7 +623,7 @@ public class TarOutputStream extends FilterOutputStream { write(0); // NUL terminator closeEntry(); } else if (longFileMode != LONGFILE_TRUNCATE) { - throw new RuntimeException(paxHeaderName + " '" + name + throw new RuntimeException(fieldName + " '" + name + "' is too long ( > " + TarConstants.NAMELEN + " bytes)"); }