You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by pe...@apache.org on 2020/11/30 01:45:35 UTC

[commons-compress] branch master updated (0bff34c -> 291b49d)

This is an automated email from the ASF dual-hosted git repository.

peterlee pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/commons-compress.git.


    from 0bff34c  Redundant return.
     new b86feb6  COMPRESS-560: Do not return false if the entry is a tar sparse entry
     new 7d00426  COMPRESS-560: Use assumeTrue/assumeFalse to check if the test should be run on the current OS
     new 291b49d  COMPRESS-560: Add message to assume check

The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../archivers/tar/TarArchiveInputStream.java       |  8 +--
 .../compress/archivers/tar/SparseFilesTest.java    | 77 ++++++++++++----------
 2 files changed, 43 insertions(+), 42 deletions(-)


[commons-compress] 01/03: COMPRESS-560: Do not return false if the entry is a tar sparse entry

Posted by pe...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

peterlee pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-compress.git

commit b86feb61e7d96e36c9348b4c4ac9ead331fc714a
Author: theobisproject <th...@gmail.com>
AuthorDate: Sun Nov 22 14:07:21 2020 +0100

    COMPRESS-560: Do not return false if the entry is a tar sparse entry
---
 .../archivers/tar/TarArchiveInputStream.java       |  8 +--
 .../compress/archivers/tar/SparseFilesTest.java    | 59 +++++++++++++---------
 2 files changed, 37 insertions(+), 30 deletions(-)

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 cdaf692..ea68d7c 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
@@ -1006,15 +1006,11 @@ public class TarArchiveInputStream extends ArchiveInputStream {
     /**
      * Whether this class is able to read the given entry.
      *
-     * <p>May return false if the current entry is a sparse file.</p>
+     * @return The implementation will return true if the {@link ArchiveEntry} is an instance of {@link TarArchiveEntry}
      */
     @Override
     public boolean canReadEntryData(final ArchiveEntry ae) {
-        if (ae instanceof TarArchiveEntry) {
-            final TarArchiveEntry te = (TarArchiveEntry) ae;
-            return !te.isSparse();
-        }
-        return false;
+        return ae instanceof TarArchiveEntry;
     }
 
     /**
diff --git a/src/test/java/org/apache/commons/compress/archivers/tar/SparseFilesTest.java b/src/test/java/org/apache/commons/compress/archivers/tar/SparseFilesTest.java
index d528b65..49f49e1 100644
--- a/src/test/java/org/apache/commons/compress/archivers/tar/SparseFilesTest.java
+++ b/src/test/java/org/apache/commons/compress/archivers/tar/SparseFilesTest.java
@@ -45,7 +45,7 @@ public class SparseFilesTest extends AbstractTestCase {
             assertTrue(ae.isOldGNUSparse());
             assertTrue(ae.isGNUSparse());
             assertFalse(ae.isPaxGNUSparse());
-            assertFalse(tin.canReadEntryData(ae));
+            assertTrue(tin.canReadEntryData(ae));
 
             final List<TarArchiveStructSparse> sparseHeaders = ae.getSparseHeaders();
             assertEquals(3, sparseHeaders.size());
@@ -82,27 +82,33 @@ public class SparseFilesTest extends AbstractTestCase {
         try (TarArchiveInputStream paxGNUSparseInputStream = new TarArchiveInputStream(new FileInputStream(paxGNUSparseTar))) {
 
             // compare between old GNU and PAX 0.0
-            paxGNUSparseInputStream.getNextTarEntry();
+            TarArchiveEntry paxGNUEntry = paxGNUSparseInputStream.getNextTarEntry();
+            assertTrue(paxGNUSparseInputStream.canReadEntryData(paxGNUEntry));
             try (TarArchiveInputStream oldGNUSparseInputStream = new TarArchiveInputStream(new FileInputStream(oldGNUSparseTar))) {
-                oldGNUSparseInputStream.getNextTarEntry();
+                final TarArchiveEntry oldGNUEntry = oldGNUSparseInputStream.getNextTarEntry();
+                assertTrue(oldGNUSparseInputStream.canReadEntryData(oldGNUEntry));
                 assertArrayEquals(IOUtils.toByteArray(oldGNUSparseInputStream),
-                    IOUtils.toByteArray(paxGNUSparseInputStream));
+                        IOUtils.toByteArray(paxGNUSparseInputStream));
             }
 
             // compare between old GNU and PAX 0.1
-            paxGNUSparseInputStream.getNextTarEntry();
+            paxGNUEntry = paxGNUSparseInputStream.getNextTarEntry();
+            assertTrue(paxGNUSparseInputStream.canReadEntryData(paxGNUEntry));
             try (TarArchiveInputStream oldGNUSparseInputStream = new TarArchiveInputStream(new FileInputStream(oldGNUSparseTar))) {
-                oldGNUSparseInputStream.getNextTarEntry();
+                final TarArchiveEntry oldGNUEntry = oldGNUSparseInputStream.getNextTarEntry();
+                assertTrue(oldGNUSparseInputStream.canReadEntryData(oldGNUEntry));
                 assertArrayEquals(IOUtils.toByteArray(oldGNUSparseInputStream),
-                    IOUtils.toByteArray(paxGNUSparseInputStream));
+                        IOUtils.toByteArray(paxGNUSparseInputStream));
             }
 
             // compare between old GNU and PAX 1.0
-            paxGNUSparseInputStream.getNextTarEntry();
+            paxGNUEntry = paxGNUSparseInputStream.getNextTarEntry();
+            assertTrue(paxGNUSparseInputStream.canReadEntryData(paxGNUEntry));
             try (TarArchiveInputStream oldGNUSparseInputStream = new TarArchiveInputStream(new FileInputStream(oldGNUSparseTar))) {
-                oldGNUSparseInputStream.getNextTarEntry();
+                final TarArchiveEntry oldGNUEntry = oldGNUSparseInputStream.getNextTarEntry();
+                assertTrue(oldGNUSparseInputStream.canReadEntryData(oldGNUEntry));
                 assertArrayEquals(IOUtils.toByteArray(oldGNUSparseInputStream),
-                    IOUtils.toByteArray(paxGNUSparseInputStream));
+                        IOUtils.toByteArray(paxGNUSparseInputStream));
             }
         }
     }
@@ -114,13 +120,14 @@ public class SparseFilesTest extends AbstractTestCase {
         }
 
         try {
-        final File file = getFile("oldgnu_sparse.tar");
-        try (InputStream sparseFileInputStream = extractTarAndGetInputStream(file, "sparsefile");
-             TarArchiveInputStream tin = new TarArchiveInputStream(new FileInputStream(file))) {
-            tin.getNextTarEntry();
-            assertArrayEquals(IOUtils.toByteArray(tin),
-                IOUtils.toByteArray(sparseFileInputStream));
-        }
+            final File file = getFile("oldgnu_sparse.tar");
+            try (InputStream sparseFileInputStream = extractTarAndGetInputStream(file, "sparsefile");
+                 TarArchiveInputStream tin = new TarArchiveInputStream(new FileInputStream(file))) {
+                final TarArchiveEntry entry = tin.getNextTarEntry();
+                assertTrue(tin.canReadEntryData(entry));
+                assertArrayEquals(IOUtils.toByteArray(tin),
+                        IOUtils.toByteArray(sparseFileInputStream));
+            }
         } catch (RuntimeException | IOException ex) {
             ex.printStackTrace();
             throw ex;
@@ -137,6 +144,7 @@ public class SparseFilesTest extends AbstractTestCase {
         try (InputStream sparseFileInputStream = extractTarAndGetInputStream(file, "sparse6");
              TarArchiveInputStream tin = new TarArchiveInputStream(new FileInputStream(file))) {
             final TarArchiveEntry ae = tin.getNextTarEntry();
+            assertTrue(tin.canReadEntryData(ae));
 
             assertArrayEquals(IOUtils.toByteArray(tin),
                 IOUtils.toByteArray(sparseFileInputStream));
@@ -176,24 +184,27 @@ public class SparseFilesTest extends AbstractTestCase {
         final File file = getFile("pax_gnu_sparse.tar");
         try (TarArchiveInputStream tin = new TarArchiveInputStream(new FileInputStream(file))) {
 
-            tin.getNextTarEntry();
+            TarArchiveEntry paxGNUEntry = tin.getNextTarEntry();
+            assertTrue(tin.canReadEntryData(paxGNUEntry));
             try (InputStream sparseFileInputStream = extractTarAndGetInputStream(file, "sparsefile-0.0")) {
                 assertArrayEquals(IOUtils.toByteArray(tin),
-                    IOUtils.toByteArray(sparseFileInputStream));
+                        IOUtils.toByteArray(sparseFileInputStream));
             }
 
             // TODO : it's wired that I can only get a 0 size sparsefile-0.1 on my Ubuntu 16.04
             //        using "tar -xf pax_gnu_sparse.tar"
-            tin.getNextTarEntry();
+            paxGNUEntry = tin.getNextTarEntry();
+            assertTrue(tin.canReadEntryData(paxGNUEntry));
             try (InputStream sparseFileInputStream = extractTarAndGetInputStream(file, "sparsefile-0.0")) {
                 assertArrayEquals(IOUtils.toByteArray(tin),
-                    IOUtils.toByteArray(sparseFileInputStream));
+                        IOUtils.toByteArray(sparseFileInputStream));
             }
 
-            tin.getNextTarEntry();
+            paxGNUEntry = tin.getNextTarEntry();
+            assertTrue(tin.canReadEntryData(paxGNUEntry));
             try (InputStream sparseFileInputStream = extractTarAndGetInputStream(file, "sparsefile-1.0")) {
                 assertArrayEquals(IOUtils.toByteArray(tin),
-                    IOUtils.toByteArray(sparseFileInputStream));
+                        IOUtils.toByteArray(sparseFileInputStream));
             }
         }
     }
@@ -204,7 +215,7 @@ public class SparseFilesTest extends AbstractTestCase {
         assertTrue(ae.isGNUSparse());
         assertTrue(ae.isPaxGNUSparse());
         assertFalse(ae.isOldGNUSparse());
-        assertFalse(tin.canReadEntryData(ae));
+        assertTrue(tin.canReadEntryData(ae));
 
         final List<TarArchiveStructSparse> sparseHeaders = ae.getSparseHeaders();
         assertEquals(3, sparseHeaders.size());


[commons-compress] 03/03: COMPRESS-560: Add message to assume check

Posted by pe...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

peterlee pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-compress.git

commit 291b49d2f36b2e21f209a6eb2913db2ddaf6fef8
Author: theobisproject <th...@gmail.com>
AuthorDate: Fri Nov 27 16:30:35 2020 +0100

    COMPRESS-560: Add message to assume check
---
 .../apache/commons/compress/archivers/tar/SparseFilesTest.java    | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/src/test/java/org/apache/commons/compress/archivers/tar/SparseFilesTest.java b/src/test/java/org/apache/commons/compress/archivers/tar/SparseFilesTest.java
index 136aef3..434fa64 100644
--- a/src/test/java/org/apache/commons/compress/archivers/tar/SparseFilesTest.java
+++ b/src/test/java/org/apache/commons/compress/archivers/tar/SparseFilesTest.java
@@ -75,7 +75,7 @@ public class SparseFilesTest extends AbstractTestCase {
 
     @Test
     public void testExtractSparseTarsOnWindows() throws IOException {
-        assumeTrue(isOnWindows);
+        assumeTrue("This test should be ignored if not running on Windows", isOnWindows);
 
         final File oldGNUSparseTar = getFile("oldgnu_sparse.tar");
         final File paxGNUSparseTar = getFile("pax_gnu_sparse.tar");
@@ -115,7 +115,7 @@ public class SparseFilesTest extends AbstractTestCase {
 
     @Test
     public void testExtractOldGNU() throws IOException, InterruptedException {
-        assumeFalse(isOnWindows);
+        assumeFalse("This test should be ignored on Windows", isOnWindows);
 
         try {
             final File file = getFile("oldgnu_sparse.tar");
@@ -134,7 +134,7 @@ public class SparseFilesTest extends AbstractTestCase {
 
     @Test
     public void testExtractExtendedOldGNU() throws IOException, InterruptedException {
-        assumeFalse(isOnWindows);
+        assumeFalse("This test should be ignored on Windows", isOnWindows);
 
         final File file = getFile("oldgnu_extended_sparse.tar");
         try (InputStream sparseFileInputStream = extractTarAndGetInputStream(file, "sparse6");
@@ -173,7 +173,7 @@ public class SparseFilesTest extends AbstractTestCase {
 
     @Test
     public void testExtractPaxGNU() throws IOException, InterruptedException {
-        assumeFalse(isOnWindows);
+        assumeFalse("This test should be ignored on Windows", isOnWindows);
 
         final File file = getFile("pax_gnu_sparse.tar");
         try (TarArchiveInputStream tin = new TarArchiveInputStream(new FileInputStream(file))) {


[commons-compress] 02/03: COMPRESS-560: Use assumeTrue/assumeFalse to check if the test should be run on the current OS

Posted by pe...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

peterlee pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-compress.git

commit 7d004266d31d6bbbc0560159d39c04fec02abb9a
Author: theobisproject <th...@gmail.com>
AuthorDate: Sun Nov 22 14:09:33 2020 +0100

    COMPRESS-560: Use assumeTrue/assumeFalse to check if the test should be run on the current OS
---
 .../compress/archivers/tar/SparseFilesTest.java        | 18 ++++++------------
 1 file changed, 6 insertions(+), 12 deletions(-)

diff --git a/src/test/java/org/apache/commons/compress/archivers/tar/SparseFilesTest.java b/src/test/java/org/apache/commons/compress/archivers/tar/SparseFilesTest.java
index 49f49e1..136aef3 100644
--- a/src/test/java/org/apache/commons/compress/archivers/tar/SparseFilesTest.java
+++ b/src/test/java/org/apache/commons/compress/archivers/tar/SparseFilesTest.java
@@ -19,6 +19,8 @@
 package org.apache.commons.compress.archivers.tar;
 
 import static org.junit.Assert.*;
+import static org.junit.Assume.assumeFalse;
+import static org.junit.Assume.assumeTrue;
 
 import org.apache.commons.compress.AbstractTestCase;
 import org.apache.commons.compress.utils.IOUtils;
@@ -73,9 +75,7 @@ public class SparseFilesTest extends AbstractTestCase {
 
     @Test
     public void testExtractSparseTarsOnWindows() throws IOException {
-        if (!isOnWindows) {
-            return;
-        }
+        assumeTrue(isOnWindows);
 
         final File oldGNUSparseTar = getFile("oldgnu_sparse.tar");
         final File paxGNUSparseTar = getFile("pax_gnu_sparse.tar");
@@ -115,9 +115,7 @@ public class SparseFilesTest extends AbstractTestCase {
 
     @Test
     public void testExtractOldGNU() throws IOException, InterruptedException {
-        if (isOnWindows) {
-            return;
-        }
+        assumeFalse(isOnWindows);
 
         try {
             final File file = getFile("oldgnu_sparse.tar");
@@ -136,9 +134,7 @@ public class SparseFilesTest extends AbstractTestCase {
 
     @Test
     public void testExtractExtendedOldGNU() throws IOException, InterruptedException {
-        if (isOnWindows) {
-            return;
-        }
+        assumeFalse(isOnWindows);
 
         final File file = getFile("oldgnu_extended_sparse.tar");
         try (InputStream sparseFileInputStream = extractTarAndGetInputStream(file, "sparse6");
@@ -177,9 +173,7 @@ public class SparseFilesTest extends AbstractTestCase {
 
     @Test
     public void testExtractPaxGNU() throws IOException, InterruptedException {
-        if (isOnWindows) {
-            return;
-        }
+        assumeFalse(isOnWindows);
 
         final File file = getFile("pax_gnu_sparse.tar");
         try (TarArchiveInputStream tin = new TarArchiveInputStream(new FileInputStream(file))) {