You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by bo...@apache.org on 2018/01/29 05:26:40 UTC

[1/3] commons-compress git commit: optionally preserve the drive letter on Windows

Repository: commons-compress
Updated Branches:
  refs/heads/master 04f887002 -> 7dcce66f1


optionally preserve the drive letter on Windows


Project: http://git-wip-us.apache.org/repos/asf/commons-compress/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-compress/commit/66607ddc
Tree: http://git-wip-us.apache.org/repos/asf/commons-compress/tree/66607ddc
Diff: http://git-wip-us.apache.org/repos/asf/commons-compress/diff/66607ddc

Branch: refs/heads/master
Commit: 66607ddc07ecc319ef7cba0d9994066ad6928b9f
Parents: 04f8870
Author: Stefan Bodewig <bo...@apache.org>
Authored: Mon Jan 29 06:21:46 2018 +0100
Committer: Stefan Bodewig <bo...@apache.org>
Committed: Mon Jan 29 06:21:46 2018 +0100

----------------------------------------------------------------------
 src/changes/changes.xml                         |  5 +++
 .../compress/archivers/tar/TarArchiveEntry.java | 46 +++++++++++---------
 .../archivers/tar/TarArchiveEntryTest.java      | 10 +++++
 3 files changed, 40 insertions(+), 21 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-compress/blob/66607ddc/src/changes/changes.xml
----------------------------------------------------------------------
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index a116892..0133dd3 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -109,6 +109,11 @@ The <action> type attribute can be add,update,fix,remove.
         Various code cleanups.
         Github Pull Request #61.
       </action>
+      <action type="update" date="2018-01-29">
+        TarArchiveEntry's preserveLeadingSlashes constructor argument
+        has been renamed and can now also be used to preserve the
+        drive letter on Windows.
+      </action>
     </release>
     <release version="1.15" date="2017-10-17"
              description="Release 1.15

http://git-wip-us.apache.org/repos/asf/commons-compress/blob/66607ddc/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveEntry.java
----------------------------------------------------------------------
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 ad2e8e9..ff31374 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
@@ -150,7 +150,7 @@ public class TarArchiveEntry implements ArchiveEntry, TarConstants {
     private String name = "";
 
     /** Whether to enforce leading slashes on the name */
-    private boolean preserveLeadingSlashes;
+    private boolean preserveAbsolutePath;
 
     /** The entry's permission mode. */
     private int mode;
@@ -258,21 +258,21 @@ public class TarArchiveEntry implements ArchiveEntry, TarConstants {
      *
      * <p>The entry's name will be the value of the {@code name}
      * argument with all file separators replaced by forward slashes.
-     * Leading slashes are stripped if {@code preserveLeadingSlashes}
-     * is {@code false}.</p>
+     * Leading slashes and Windows drive letters are stripped if
+     * {@code preserveAbsolutePath} is {@code false}.</p>
      *
      * @param name the entry name
-     * @param preserveLeadingSlashes whether to allow leading slashes
-     * in the name.
+     * @param preserveAbsolutePath whether to allow leading slashes
+     * in the name or drive letters.
      *
      * @since 1.1
      */
-    public TarArchiveEntry(String name, final boolean preserveLeadingSlashes) {
+    public TarArchiveEntry(String name, final boolean preserveAbsolutePath) {
         this();
 
-        this.preserveLeadingSlashes = preserveLeadingSlashes;
+        this.preserveAbsolutePath = preserveAbsolutePath;
 
-        name = normalizeFileName(name, preserveLeadingSlashes);
+        name = normalizeFileName(name, preserveAbsolutePath);
         final boolean isDir = name.endsWith("/");
 
         this.name = name;
@@ -287,7 +287,8 @@ public class TarArchiveEntry implements ArchiveEntry, TarConstants {
      *
      * <p>The entry's name will be the value of the {@code name}
      * argument with all file separators replaced by forward slashes
-     * and leading slashes stripped.</p>
+     * and leading slashes as well as Windows drive letters
+     * stripped.</p>
      *
      * @param name the entry name
      * @param linkFlag the entry link flag.
@@ -300,19 +301,19 @@ public class TarArchiveEntry implements ArchiveEntry, TarConstants {
      * Construct an entry with a name and a link flag.
      *
      * <p>The entry's name will be the value of the {@code name}
-     * argument with all file separators replaced by forward
-     * slashes. Leading slashes are stripped if {@code
-     * preserveLeadingSlashes} is {@code false}.</p>
+     * argument with all file separators replaced by forward slashes.
+     * Leading slashes and Windows drive letters are stripped if
+     * {@code preserveAbsolutePath} is {@code false}.</p>
      *
      * @param name the entry name
      * @param linkFlag the entry link flag.
-     * @param preserveLeadingSlashes whether to allow leading slashes
-     * in the name.
+     * @param preserveAbsolutePath whether to allow leading slashes
+     * in the name or drive letters.
      *
      * @since 1.5
      */
-    public TarArchiveEntry(final String name, final byte linkFlag, final boolean preserveLeadingSlashes) {
-        this(name, preserveLeadingSlashes);
+    public TarArchiveEntry(final String name, final byte linkFlag, final boolean preserveAbsolutePath) {
+        this(name, preserveAbsolutePath);
         this.linkFlag = linkFlag;
         if (linkFlag == LF_GNUTYPE_LONGNAME) {
             magic = MAGIC_GNU;
@@ -342,8 +343,9 @@ public class TarArchiveEntry implements ArchiveEntry, TarConstants {
      *
      * <p>The entry's name will be the value of the {@code fileName}
      * argument with all file separators replaced by forward slashes
-     * and leading slashes stripped. The name will end in a slash if the
-     * {@code file} represents a directory.</p>
+     * and leading slashes as well as Windows drive letters stripped.
+     * The name will end in a slash if the {@code file} represents a
+     * directory.</p>
      *
      * @param file The file that the entry represents.
      * @param fileName the name to be used for the entry.
@@ -465,7 +467,7 @@ public class TarArchiveEntry implements ArchiveEntry, TarConstants {
      * @param name This entry's new name.
      */
     public void setName(final String name) {
-        this.name = normalizeFileName(name, this.preserveLeadingSlashes);
+        this.name = normalizeFileName(name, this.preserveAbsolutePath);
     }
 
     /**
@@ -1350,7 +1352,8 @@ public class TarArchiveEntry implements ArchiveEntry, TarConstants {
      * turns path separators into forward slahes.
      */
     private static String normalizeFileName(String fileName,
-                                            final boolean preserveLeadingSlashes) {
+                                            final boolean preserveAbsolutePath) {
+        if (!preserveAbsolutePath) {
         final String osname = System.getProperty("os.name").toLowerCase(Locale.ENGLISH);
 
         if (osname != null) {
@@ -1376,13 +1379,14 @@ public class TarArchiveEntry implements ArchiveEntry, TarConstants {
                 }
             }
         }
+        }
 
         fileName = fileName.replace(File.separatorChar, '/');
 
         // No absolute pathnames
         // Windows (and Posix?) paths can start with "\\NetworkDrive\",
         // so we loop on starting /'s.
-        while (!preserveLeadingSlashes && fileName.startsWith("/")) {
+        while (!preserveAbsolutePath && fileName.startsWith("/")) {
             fileName = fileName.substring(1);
         }
         return fileName;

http://git-wip-us.apache.org/repos/asf/commons-compress/blob/66607ddc/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveEntryTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveEntryTest.java b/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveEntryTest.java
index 489ce68..8eba959 100644
--- a/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveEntryTest.java
+++ b/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveEntryTest.java
@@ -24,6 +24,7 @@ import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
+import static org.junit.Assume.assumeTrue;
 
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
@@ -190,6 +191,15 @@ public class TarArchiveEntryTest implements TarConstants {
         assertEquals("/foo", t.getName());
     }
 
+    @Test
+    public void preservesDriveSpecOnWindowsAndNetwareIfAskedTo() {
+        assumeTrue("C:\\".equals(ROOT));
+        TarArchiveEntry t = new TarArchiveEntry(ROOT + "bar.txt", true);
+        assertEquals("C:/foo.txt", t.getName());
+        t = new TarArchiveEntry(ROOT + "/foo.txt", LF_GNUTYPE_LONGNAME, true);
+        assertEquals("C:/foo.txt", t.getName());
+    }
+
     private void assertGnuMagic(final TarArchiveEntry t) {
         assertEquals(MAGIC_GNU + VERSION_GNU_SPACE, readMagic(t));
     }


[2/3] commons-compress git commit: whitespace

Posted by bo...@apache.org.
whitespace


Project: http://git-wip-us.apache.org/repos/asf/commons-compress/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-compress/commit/1bad4f41
Tree: http://git-wip-us.apache.org/repos/asf/commons-compress/tree/1bad4f41
Diff: http://git-wip-us.apache.org/repos/asf/commons-compress/diff/1bad4f41

Branch: refs/heads/master
Commit: 1bad4f4193a86fe3a8ba1cabfd87a9e6e1e436e3
Parents: 66607dd
Author: Stefan Bodewig <bo...@apache.org>
Authored: Mon Jan 29 06:22:55 2018 +0100
Committer: Stefan Bodewig <bo...@apache.org>
Committed: Mon Jan 29 06:22:55 2018 +0100

----------------------------------------------------------------------
 .../compress/archivers/tar/TarArchiveEntry.java | 36 ++++++++++----------
 1 file changed, 18 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-compress/blob/1bad4f41/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveEntry.java
----------------------------------------------------------------------
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 ff31374..6fb95e1 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
@@ -1354,32 +1354,32 @@ public class TarArchiveEntry implements ArchiveEntry, TarConstants {
     private static String normalizeFileName(String fileName,
                                             final boolean preserveAbsolutePath) {
         if (!preserveAbsolutePath) {
-        final String osname = System.getProperty("os.name").toLowerCase(Locale.ENGLISH);
+            final String osname = System.getProperty("os.name").toLowerCase(Locale.ENGLISH);
 
-        if (osname != null) {
+            if (osname != null) {
 
-            // Strip off drive letters!
-            // REVIEW Would a better check be "(File.separator == '\')"?
+                // Strip off drive letters!
+                // REVIEW Would a better check be "(File.separator == '\')"?
 
-            if (osname.startsWith("windows")) {
-                if (fileName.length() > 2) {
-                    final char ch1 = fileName.charAt(0);
-                    final char ch2 = fileName.charAt(1);
+                if (osname.startsWith("windows")) {
+                    if (fileName.length() > 2) {
+                        final char ch1 = fileName.charAt(0);
+                        final char ch2 = fileName.charAt(1);
 
-                    if (ch2 == ':'
-                        && (ch1 >= 'a' && ch1 <= 'z'
-                            || ch1 >= 'A' && ch1 <= 'Z')) {
-                        fileName = fileName.substring(2);
+                        if (ch2 == ':'
+                            && (ch1 >= 'a' && ch1 <= 'z'
+                                || ch1 >= 'A' && ch1 <= 'Z')) {
+                            fileName = fileName.substring(2);
+                        }
+                    }
+                } else if (osname.contains("netware")) {
+                    final int colon = fileName.indexOf(':');
+                    if (colon != -1) {
+                        fileName = fileName.substring(colon + 1);
                     }
-                }
-            } else if (osname.contains("netware")) {
-                final int colon = fileName.indexOf(':');
-                if (colon != -1) {
-                    fileName = fileName.substring(colon + 1);
                 }
             }
         }
-        }
 
         fileName = fileName.replace(File.separatorChar, '/');
 


Re: [1/3] commons-compress git commit: optionally preserve the drive letter on Windows

Posted by Stefan Bodewig <bo...@apache.org>.
On 2018-01-29, sebb wrote:

> On 29 January 2018 at 05:26,  <bo...@apache.org> wrote:

>>      /** Whether to enforce leading slashes on the name */

> Comment no longer applies ...
> ... are there any other such remaining?

Good catch, I think I've changed all of them by now.

Stefan

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Re: [1/3] commons-compress git commit: optionally preserve the drive letter on Windows

Posted by sebb <se...@gmail.com>.
On 29 January 2018 at 05:26,  <bo...@apache.org> wrote:
> Repository: commons-compress
> Updated Branches:
>   refs/heads/master 04f887002 -> 7dcce66f1
>
>
> optionally preserve the drive letter on Windows
>
>
> Project: http://git-wip-us.apache.org/repos/asf/commons-compress/repo
> Commit: http://git-wip-us.apache.org/repos/asf/commons-compress/commit/66607ddc
> Tree: http://git-wip-us.apache.org/repos/asf/commons-compress/tree/66607ddc
> Diff: http://git-wip-us.apache.org/repos/asf/commons-compress/diff/66607ddc
>
> Branch: refs/heads/master
> Commit: 66607ddc07ecc319ef7cba0d9994066ad6928b9f
> Parents: 04f8870
> Author: Stefan Bodewig <bo...@apache.org>
> Authored: Mon Jan 29 06:21:46 2018 +0100
> Committer: Stefan Bodewig <bo...@apache.org>
> Committed: Mon Jan 29 06:21:46 2018 +0100
>
> ----------------------------------------------------------------------
>  src/changes/changes.xml                         |  5 +++
>  .../compress/archivers/tar/TarArchiveEntry.java | 46 +++++++++++---------
>  .../archivers/tar/TarArchiveEntryTest.java      | 10 +++++
>  3 files changed, 40 insertions(+), 21 deletions(-)
> ----------------------------------------------------------------------
>
>
> http://git-wip-us.apache.org/repos/asf/commons-compress/blob/66607ddc/src/changes/changes.xml
> ----------------------------------------------------------------------
> diff --git a/src/changes/changes.xml b/src/changes/changes.xml
> index a116892..0133dd3 100644
> --- a/src/changes/changes.xml
> +++ b/src/changes/changes.xml
> @@ -109,6 +109,11 @@ The <action> type attribute can be add,update,fix,remove.
>          Various code cleanups.
>          Github Pull Request #61.
>        </action>
> +      <action type="update" date="2018-01-29">
> +        TarArchiveEntry's preserveLeadingSlashes constructor argument
> +        has been renamed and can now also be used to preserve the
> +        drive letter on Windows.
> +      </action>
>      </release>
>      <release version="1.15" date="2017-10-17"
>               description="Release 1.15
>
> http://git-wip-us.apache.org/repos/asf/commons-compress/blob/66607ddc/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveEntry.java
> ----------------------------------------------------------------------
> 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 ad2e8e9..ff31374 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
> @@ -150,7 +150,7 @@ public class TarArchiveEntry implements ArchiveEntry, TarConstants {
>      private String name = "";
>
>      /** Whether to enforce leading slashes on the name */

Comment no longer applies ...
... are there any other such remaining?

> -    private boolean preserveLeadingSlashes;
> +    private boolean preserveAbsolutePath;
>
>      /** The entry's permission mode. */
>      private int mode;
> @@ -258,21 +258,21 @@ public class TarArchiveEntry implements ArchiveEntry, TarConstants {
>       *
>       * <p>The entry's name will be the value of the {@code name}
>       * argument with all file separators replaced by forward slashes.
> -     * Leading slashes are stripped if {@code preserveLeadingSlashes}
> -     * is {@code false}.</p>
> +     * Leading slashes and Windows drive letters are stripped if
> +     * {@code preserveAbsolutePath} is {@code false}.</p>
>       *
>       * @param name the entry name
> -     * @param preserveLeadingSlashes whether to allow leading slashes
> -     * in the name.
> +     * @param preserveAbsolutePath whether to allow leading slashes
> +     * in the name or drive letters.
>       *
>       * @since 1.1
>       */
> -    public TarArchiveEntry(String name, final boolean preserveLeadingSlashes) {
> +    public TarArchiveEntry(String name, final boolean preserveAbsolutePath) {
>          this();
>
> -        this.preserveLeadingSlashes = preserveLeadingSlashes;
> +        this.preserveAbsolutePath = preserveAbsolutePath;
>
> -        name = normalizeFileName(name, preserveLeadingSlashes);
> +        name = normalizeFileName(name, preserveAbsolutePath);
>          final boolean isDir = name.endsWith("/");
>
>          this.name = name;
> @@ -287,7 +287,8 @@ public class TarArchiveEntry implements ArchiveEntry, TarConstants {
>       *
>       * <p>The entry's name will be the value of the {@code name}
>       * argument with all file separators replaced by forward slashes
> -     * and leading slashes stripped.</p>
> +     * and leading slashes as well as Windows drive letters
> +     * stripped.</p>
>       *
>       * @param name the entry name
>       * @param linkFlag the entry link flag.
> @@ -300,19 +301,19 @@ public class TarArchiveEntry implements ArchiveEntry, TarConstants {
>       * Construct an entry with a name and a link flag.
>       *
>       * <p>The entry's name will be the value of the {@code name}
> -     * argument with all file separators replaced by forward
> -     * slashes. Leading slashes are stripped if {@code
> -     * preserveLeadingSlashes} is {@code false}.</p>
> +     * argument with all file separators replaced by forward slashes.
> +     * Leading slashes and Windows drive letters are stripped if
> +     * {@code preserveAbsolutePath} is {@code false}.</p>
>       *
>       * @param name the entry name
>       * @param linkFlag the entry link flag.
> -     * @param preserveLeadingSlashes whether to allow leading slashes
> -     * in the name.
> +     * @param preserveAbsolutePath whether to allow leading slashes
> +     * in the name or drive letters.
>       *
>       * @since 1.5
>       */
> -    public TarArchiveEntry(final String name, final byte linkFlag, final boolean preserveLeadingSlashes) {
> -        this(name, preserveLeadingSlashes);
> +    public TarArchiveEntry(final String name, final byte linkFlag, final boolean preserveAbsolutePath) {
> +        this(name, preserveAbsolutePath);
>          this.linkFlag = linkFlag;
>          if (linkFlag == LF_GNUTYPE_LONGNAME) {
>              magic = MAGIC_GNU;
> @@ -342,8 +343,9 @@ public class TarArchiveEntry implements ArchiveEntry, TarConstants {
>       *
>       * <p>The entry's name will be the value of the {@code fileName}
>       * argument with all file separators replaced by forward slashes
> -     * and leading slashes stripped. The name will end in a slash if the
> -     * {@code file} represents a directory.</p>
> +     * and leading slashes as well as Windows drive letters stripped.
> +     * The name will end in a slash if the {@code file} represents a
> +     * directory.</p>
>       *
>       * @param file The file that the entry represents.
>       * @param fileName the name to be used for the entry.
> @@ -465,7 +467,7 @@ public class TarArchiveEntry implements ArchiveEntry, TarConstants {
>       * @param name This entry's new name.
>       */
>      public void setName(final String name) {
> -        this.name = normalizeFileName(name, this.preserveLeadingSlashes);
> +        this.name = normalizeFileName(name, this.preserveAbsolutePath);
>      }
>
>      /**
> @@ -1350,7 +1352,8 @@ public class TarArchiveEntry implements ArchiveEntry, TarConstants {
>       * turns path separators into forward slahes.
>       */
>      private static String normalizeFileName(String fileName,
> -                                            final boolean preserveLeadingSlashes) {
> +                                            final boolean preserveAbsolutePath) {
> +        if (!preserveAbsolutePath) {
>          final String osname = System.getProperty("os.name").toLowerCase(Locale.ENGLISH);
>
>          if (osname != null) {
> @@ -1376,13 +1379,14 @@ public class TarArchiveEntry implements ArchiveEntry, TarConstants {
>                  }
>              }
>          }
> +        }
>
>          fileName = fileName.replace(File.separatorChar, '/');
>
>          // No absolute pathnames
>          // Windows (and Posix?) paths can start with "\\NetworkDrive\",
>          // so we loop on starting /'s.
> -        while (!preserveLeadingSlashes && fileName.startsWith("/")) {
> +        while (!preserveAbsolutePath && fileName.startsWith("/")) {
>              fileName = fileName.substring(1);
>          }
>          return fileName;
>
> http://git-wip-us.apache.org/repos/asf/commons-compress/blob/66607ddc/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveEntryTest.java
> ----------------------------------------------------------------------
> diff --git a/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveEntryTest.java b/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveEntryTest.java
> index 489ce68..8eba959 100644
> --- a/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveEntryTest.java
> +++ b/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveEntryTest.java
> @@ -24,6 +24,7 @@ import static org.junit.Assert.assertNotNull;
>  import static org.junit.Assert.assertNull;
>  import static org.junit.Assert.assertTrue;
>  import static org.junit.Assert.fail;
> +import static org.junit.Assume.assumeTrue;
>
>  import java.io.ByteArrayInputStream;
>  import java.io.ByteArrayOutputStream;
> @@ -190,6 +191,15 @@ public class TarArchiveEntryTest implements TarConstants {
>          assertEquals("/foo", t.getName());
>      }
>
> +    @Test
> +    public void preservesDriveSpecOnWindowsAndNetwareIfAskedTo() {
> +        assumeTrue("C:\\".equals(ROOT));
> +        TarArchiveEntry t = new TarArchiveEntry(ROOT + "bar.txt", true);
> +        assertEquals("C:/foo.txt", t.getName());
> +        t = new TarArchiveEntry(ROOT + "/foo.txt", LF_GNUTYPE_LONGNAME, true);
> +        assertEquals("C:/foo.txt", t.getName());
> +    }
> +
>      private void assertGnuMagic(final TarArchiveEntry t) {
>          assertEquals(MAGIC_GNU + VERSION_GNU_SPACE, readMagic(t));
>      }
>

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


[3/3] commons-compress git commit: allow preserveAbsolutePath to be final

Posted by bo...@apache.org.
allow preserveAbsolutePath to be final


Project: http://git-wip-us.apache.org/repos/asf/commons-compress/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-compress/commit/7dcce66f
Tree: http://git-wip-us.apache.org/repos/asf/commons-compress/tree/7dcce66f
Diff: http://git-wip-us.apache.org/repos/asf/commons-compress/diff/7dcce66f

Branch: refs/heads/master
Commit: 7dcce66f1354cd54a6e64228bd56f0476a1ceb4d
Parents: 1bad4f4
Author: Stefan Bodewig <bo...@apache.org>
Authored: Mon Jan 29 06:26:01 2018 +0100
Committer: Stefan Bodewig <bo...@apache.org>
Committed: Mon Jan 29 06:26:01 2018 +0100

----------------------------------------------------------------------
 .../compress/archivers/tar/TarArchiveEntry.java       | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-compress/blob/7dcce66f/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveEntry.java
----------------------------------------------------------------------
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 6fb95e1..6ec9da5 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
@@ -150,7 +150,7 @@ public class TarArchiveEntry implements ArchiveEntry, TarConstants {
     private String name = "";
 
     /** Whether to enforce leading slashes on the name */
-    private boolean preserveAbsolutePath;
+    private final boolean preserveAbsolutePath;
 
     /** The entry's permission mode. */
     private int mode;
@@ -227,7 +227,7 @@ public class TarArchiveEntry implements ArchiveEntry, TarConstants {
     /**
      * Construct an empty entry and prepares the header values.
      */
-    private TarArchiveEntry() {
+    private TarArchiveEntry(boolean preserveAbsolutePath) {
         String user = System.getProperty("user.name", "");
 
         if (user.length() > MAX_NAMELEN) {
@@ -236,6 +236,7 @@ public class TarArchiveEntry implements ArchiveEntry, TarConstants {
 
         this.userName = user;
         this.file = null;
+        this.preserveAbsolutePath = preserveAbsolutePath;
     }
 
     /**
@@ -268,9 +269,7 @@ public class TarArchiveEntry implements ArchiveEntry, TarConstants {
      * @since 1.1
      */
     public TarArchiveEntry(String name, final boolean preserveAbsolutePath) {
-        this();
-
-        this.preserveAbsolutePath = preserveAbsolutePath;
+        this(preserveAbsolutePath);
 
         name = normalizeFileName(name, preserveAbsolutePath);
         final boolean isDir = name.endsWith("/");
@@ -373,6 +372,7 @@ public class TarArchiveEntry implements ArchiveEntry, TarConstants {
 
         this.modTime = file.lastModified() / MILLIS_PER_SECOND;
         this.userName = "";
+        preserveAbsolutePath = false;
     }
 
     /**
@@ -383,7 +383,7 @@ public class TarArchiveEntry implements ArchiveEntry, TarConstants {
      * @throws IllegalArgumentException if any of the numeric fields have an invalid format
      */
     public TarArchiveEntry(final byte[] headerBuf) {
-        this();
+        this(false);
         parseTarHeader(headerBuf);
     }
 
@@ -399,7 +399,7 @@ public class TarArchiveEntry implements ArchiveEntry, TarConstants {
      */
     public TarArchiveEntry(final byte[] headerBuf, final ZipEncoding encoding)
         throws IOException {
-        this();
+        this(false);
         parseTarHeader(headerBuf, encoding);
     }