You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by sebb <se...@gmail.com> on 2018/01/29 08:58:38 UTC

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

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


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