From 1f3635acef5049f919c840041615661b6b692678 Mon Sep 17 00:00:00 2001
From: Christoph Gysin <christoph.gysin@gmail.com>
Date: Fri, 31 May 2013 21:35:48 +0300
Subject: [PATCH 4/5] handle GNU long link name

---
 .../apache/commons/compress/archivers/tar/TarArchiveEntry.java | 10 ++++++++++
 .../commons/compress/archivers/tar/TarArchiveInputStream.java  |  5 +++++
 .../apache/commons/compress/archivers/tar/TarConstants.java    |  5 +++++
 3 files changed, 20 insertions(+)

diff --git a/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveEntry.java b/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveEntry.java
index 6ed6280..14b94cc 100644
--- a/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveEntry.java
+++ b/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveEntry.java
@@ -676,6 +676,16 @@ public class TarArchiveEntry implements TarConstants, ArchiveEntry {
     }
 
     /**
+     * Indicate if this entry is a GNU long linkname block
+     *
+     * @return true if this is a long name extension provided by GNU tar
+     */
+    public boolean isGNULongLinkEntry() {
+        return linkFlag == LF_GNUTYPE_LONGLINK
+            && name.equals(GNU_LONGLINK);
+    }
+
+    /**
      * Indicate if this entry is a GNU long name block
      *
      * @return true if this is a long name extension provided by GNU tar
diff --git a/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStream.java b/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStream.java
index 57012d8..1eb0b68 100644
--- a/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStream.java
+++ b/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStream.java
@@ -248,6 +248,11 @@ public class TarArchiveInputStream extends ArchiveInputStream {
         entryOffset = 0;
         entrySize = currEntry.getSize();
 
+        if (currEntry.isGNULongLinkEntry()) {
+            byte[] longLinkData = getLongNameData();
+            currEntry.setLinkName(encoding.decode(longLinkData));
+        }
+
         if (currEntry.isGNULongNameEntry()) {
             byte[] longNameData = getLongNameData();
             currEntry.setName(encoding.decode(longNameData));
diff --git a/src/main/java/org/apache/commons/compress/archivers/tar/TarConstants.java b/src/main/java/org/apache/commons/compress/archivers/tar/TarConstants.java
index 7b7c9cd..5e5889c 100644
--- a/src/main/java/org/apache/commons/compress/archivers/tar/TarConstants.java
+++ b/src/main/java/org/apache/commons/compress/archivers/tar/TarConstants.java
@@ -233,6 +233,11 @@ public interface TarConstants {
     byte   LF_CONTIG = (byte) '7';
 
     /**
+     * Identifies the *next* file on the tape as having a long linkname.
+     */
+    byte LF_GNUTYPE_LONGLINK = (byte) 'K';
+
+    /**
      * Identifies the *next* file on the tape as having a long name.
      */
     byte LF_GNUTYPE_LONGNAME = (byte) 'L';
-- 
1.8.3

