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 2016/02/05 18:09:27 UTC

commons-compress git commit: COMPRESS-330 ignore non-zero size for directories

Repository: commons-compress
Updated Branches:
  refs/heads/master 9b852f382 -> 51eb0f22b


COMPRESS-330 ignore non-zero size for directories


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

Branch: refs/heads/master
Commit: 51eb0f22b20b94fc635ecc64cdcb5f72e0ed0186
Parents: 9b852f3
Author: Stefan Bodewig <bo...@apache.org>
Authored: Fri Feb 5 18:08:51 2016 +0100
Committer: Stefan Bodewig <bo...@apache.org>
Committed: Fri Feb 5 18:08:51 2016 +0100

----------------------------------------------------------------------
 .../compress/archivers/tar/TarArchiveInputStream.java  | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-compress/blob/51eb0f22/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStream.java
----------------------------------------------------------------------
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 41acf2a..118bf7a 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
@@ -178,6 +178,9 @@ public class TarArchiveInputStream extends ArchiveInputStream {
      */
     @Override
     public int available() throws IOException {
+        if (isDirectory()) {
+            return 0;
+        }
         if (entrySize - entryOffset > Integer.MAX_VALUE) {
             return Integer.MAX_VALUE;
         }
@@ -203,7 +206,7 @@ public class TarArchiveInputStream extends ArchiveInputStream {
      */
     @Override
     public long skip(final long n) throws IOException {
-        if (n <= 0) {
+        if (n <= 0 || isDirectory()) {
             return 0;
         }
 
@@ -329,7 +332,7 @@ public class TarArchiveInputStream extends ArchiveInputStream {
      * additional space used to fill a record after an entry
      */
     private void skipRecordPadding() throws IOException {
-        if (this.entrySize > 0 && this.entrySize % this.recordSize != 0) {
+        if (!isDirectory() && this.entrySize > 0 && this.entrySize % this.recordSize != 0) {
             long numRecords = (this.entrySize / this.recordSize) + 1;
             long padding = (numRecords * this.recordSize) - this.entrySize;
             long skipped = IOUtils.skip(is, padding);
@@ -546,6 +549,10 @@ public class TarArchiveInputStream extends ArchiveInputStream {
         }
     }
 
+    private boolean isDirectory() {
+        return currEntry != null && currEntry.isDirectory();
+    }
+
     /**
      * Returns the next Archive Entry in this Stream.
      *
@@ -601,7 +608,7 @@ public class TarArchiveInputStream extends ArchiveInputStream {
     public int read(byte[] buf, int offset, int numToRead) throws IOException {
     	int totalRead = 0;
 
-        if (hasHitEOF || entryOffset >= entrySize) {
+        if (hasHitEOF || isDirectory() || entryOffset >= entrySize) {
             return -1;
         }