From 63664a8786c82ffef4f09c1bec3d3e7db8cbcfb8 Mon Sep 17 00:00:00 2001 From: Conor MacNeill Date: Sat, 3 Feb 2001 14:24:43 +0000 Subject: [PATCH] Add support for untaring of GNU tar files. git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@268568 13f79535-47bb-0310-9956-ffa450edef68 --- src/main/org/apache/tools/tar/TarEntry.java | 11 +++++++++++ src/main/org/apache/tools/tar/TarInputStream.java | 12 ++++++++++++ 2 files changed, 23 insertions(+) diff --git a/src/main/org/apache/tools/tar/TarEntry.java b/src/main/org/apache/tools/tar/TarEntry.java index bc8cdc878..91da76f9b 100644 --- a/src/main/org/apache/tools/tar/TarEntry.java +++ b/src/main/org/apache/tools/tar/TarEntry.java @@ -454,7 +454,18 @@ public class TarEntry implements TarConstants { public void setSize(long size) { this.size = size; } + + /** + * Indicate if this entry is a GNU long name block + * + * @return true if this is a long name extension provided by GNU tar + */ + public boolean isGNULongNameEntry() { + return linkFlag == LF_GNUTYPE_LONGNAME && + name.toString().equals(GNU_LONGLINK); + } + /** * Return whether or not this entry represents a directory. * diff --git a/src/main/org/apache/tools/tar/TarInputStream.java b/src/main/org/apache/tools/tar/TarInputStream.java index 0bdfa8073..00ad9c31e 100644 --- a/src/main/org/apache/tools/tar/TarInputStream.java +++ b/src/main/org/apache/tools/tar/TarInputStream.java @@ -286,6 +286,18 @@ public class TarInputStream extends FilterInputStream { this.entrySize = (int) this.currEntry.getSize(); } + if (this.currEntry != null && this.currEntry.isGNULongNameEntry()) { + // read in the name + StringBuffer longName = new StringBuffer(); + byte[] buffer = new byte[256]; + int length = 0; + while ((length = read(buffer)) >= 0) { + longName.append(new String(buffer, 0, length)); + } + getNextEntry(); + this.currEntry.setName(longName.toString()); + } + return this.currEntry; }