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:08 UTC

(commons-compress) 01/02: Internal refactoring

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);
+                        }
                     }
                 }
             }