You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2025/08/10 21:07:07 UTC

(commons-compress) branch master updated (d8903123f -> 3d2fb385c)

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

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


    from d8903123f Better comment
     new 69b8d631b Internal refactoring
     new 3d2fb385c Javadoc

The 2 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:
 .../compress/archivers/tar/TarArchiveEntry.java    | 35 ++++++++++++----------
 .../commons/compress/archivers/tar/TarUtils.java   | 14 +++++----
 2 files changed, 27 insertions(+), 22 deletions(-)


(commons-compress) 01/02: Internal refactoring

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

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

commit 69b8d631b9d653200c90f263330de185824867a7
Author: Gary D. Gregory <ga...@gmail.com>
AuthorDate: Sun Aug 10 17:04:48 2025 -0400

    Internal refactoring
---
 .../compress/archivers/tar/TarArchiveEntry.java    | 35 ++++++++++++----------
 1 file changed, 19 insertions(+), 16 deletions(-)

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 3568fd70c..a5e193278 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
@@ -55,6 +55,7 @@
 import org.apache.commons.io.file.attribute.FileTimes;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.commons.lang3.SystemProperties;
+import org.apache.commons.lang3.SystemUtils;
 
 /**
  * An entry in a <a href="https://www.gnu.org/software/tar/manual/html_node/Standard.html">Tar archive</a>.
@@ -230,23 +231,25 @@ private static FileTime fileTimeFromOptionalSeconds(final long seconds) {
      */
     private static String normalizeFileName(String fileName, final boolean preserveAbsolutePath) {
         if (!preserveAbsolutePath) {
-            final String property = SystemProperties.getOsName();
-            if (property != null) {
-                final String osName = StringUtils.toRootLowerCase(property);
-                // 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 (ch2 == ':' && (ch1 >= 'a' && ch1 <= 'z' || ch1 >= 'A' && ch1 <= 'Z')) {
-                            fileName = fileName.substring(2);
-                        }
+            // Strip off drive letters!
+            // REVIEW Would a better check be "(File.separator == '\')"?
+            if (SystemUtils.IS_OS_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);
                     }
-                } else if (osName.contains("netware")) {
-                    final int colon = fileName.indexOf(':');
-                    if (colon != -1) {
-                        fileName = fileName.substring(colon + 1);
+                }
+            } else {
+                final String property = SystemProperties.getOsName();
+                if (property != null) {
+                    final String osName = StringUtils.toRootLowerCase(property);
+                    if (osName.contains("netware")) {
+                        final int colon = fileName.indexOf(':');
+                        if (colon != -1) {
+                            fileName = fileName.substring(colon + 1);
+                        }
                     }
                 }
             }


(commons-compress) 02/02: Javadoc

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

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

commit 3d2fb385c51cd2ee6d45fb35f987768a36f269b6
Author: Gary D. Gregory <ga...@gmail.com>
AuthorDate: Sun Aug 10 17:07:01 2025 -0400

    Javadoc
---
 .../apache/commons/compress/archivers/tar/TarUtils.java    | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/src/main/java/org/apache/commons/compress/archivers/tar/TarUtils.java b/src/main/java/org/apache/commons/compress/archivers/tar/TarUtils.java
index b61f55c24..7422689bb 100644
--- a/src/main/java/org/apache/commons/compress/archivers/tar/TarUtils.java
+++ b/src/main/java/org/apache/commons/compress/archivers/tar/TarUtils.java
@@ -918,11 +918,12 @@ static List<TarArchiveStructSparse> readSparseStructs(final byte[] buffer, final
     }
 
     /**
-     * Wikipedia <a href="https://en.wikipedia.org/wiki/Tar_(computing)#File_header">says</a>: <blockquote> The checksum is calculated by taking the sum of the
-     * unsigned byte values of the header block with the eight checksum bytes taken to be ASCII spaces (decimal value 32). It is stored as a six digit octal
-     * number with leading zeroes followed by a NUL and then a space. Various implementations do not adhere to this format. For better compatibility, ignore
-     * leading and trailing whitespace, and get the first six digits. In addition, some historic tar implementations treated bytes as signed. Implementations
-     * typically calculate the checksum both ways, and treat it as good if either the signed or unsigned sum matches the included checksum. </blockquote>
+     * Verifies the checksum in the <a href="https://en.wikipedia.org/wiki/Tar_(computing)#File_header">TAR header</a>: <blockquote>The checksum is calculated
+     * by taking the sum of the unsigned byte values of the header block with the eight checksum bytes taken to be ASCII spaces (decimal value 32). It is stored
+     * as a six digit octal number with leading zeroes followed by a NUL and then a space. Various implementations do not adhere to this format. For better
+     * compatibility, ignore leading and trailing whitespace, and get the first six digits. In addition, some historic tar implementations treated bytes as
+     * signed. Implementations typically calculate the checksum both ways, and treat it as good if either the signed or unsigned sum matches the included
+     * checksum.</blockquote>
      * <p>
      * The return value of this method should be treated as a best-effort heuristic rather than an absolute and final truth. The checksum verification logic may
      * well evolve over time as more special cases are encountered.
@@ -930,6 +931,7 @@ static List<TarArchiveStructSparse> readSparseStructs(final byte[] buffer, final
      *
      * @param header tar header
      * @return whether the checksum is reasonably good
+     * @see <a href="https://en.wikipedia.org/wiki/Tar_(computing)#File_header">TAR header</a>
      * @see <a href="https://issues.apache.org/jira/browse/COMPRESS-191">COMPRESS-191</a>
      * @since 1.5
      */
@@ -948,7 +950,7 @@ public static boolean verifyCheckSum(final byte[] header) {
         return storedSum == unsignedSum || storedSum == signedSum;
     }
 
-    /** Prevents instantiation. */
+    /** No instances needed. */
     private TarUtils() {
     }
 }