ant-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject svn commit: r755231 - /ant/core/trunk/src/main/org/apache/tools/tar/TarEntry.java
Date Tue, 17 Mar 2009 12:59:48 GMT
Author: bodewig
Date: Tue Mar 17 12:59:48 2009
New Revision: 755231

URL: http://svn.apache.org/viewvc?rev=755231&view=rev
Log:
deal with file system roots being added - was leading to IndexOutOfBoundsExceptions in File-arg
constructor

Modified:
    ant/core/trunk/src/main/org/apache/tools/tar/TarEntry.java   (contents, props changed)

Modified: ant/core/trunk/src/main/org/apache/tools/tar/TarEntry.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/tar/TarEntry.java?rev=755231&r1=755230&r2=755231&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/tar/TarEntry.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/tar/TarEntry.java Tue Mar 17 12:59:48 2009
@@ -161,6 +161,7 @@
     public TarEntry(String name) {
         this();
 
+        name = normalizeFileName(name);
         boolean isDir = name.endsWith("/");
 
         this.devMajor = 0;
@@ -202,42 +203,7 @@
 
         this.file = file;
 
-        String fileName = file.getPath();
-        String osname = System.getProperty("os.name").toLowerCase(Locale.US);
-
-        if (osname != null) {
-
-            // Strip off drive letters!
-            // REVIEW Would a better check be "(File.separator == '\')"?
-
-            if (osname.startsWith("windows")) {
-                if (fileName.length() > 2) {
-                    char ch1 = fileName.charAt(0);
-                    char ch2 = fileName.charAt(1);
-
-                    if (ch2 == ':'
-                            && ((ch1 >= 'a' && ch1 <= 'z')
-                                || (ch1 >= 'A' && ch1 <= 'Z'))) {
-                        fileName = fileName.substring(2);
-                    }
-                }
-            } else if (osname.indexOf("netware") > -1) {
-                int colon = fileName.indexOf(':');
-                if (colon != -1) {
-                    fileName = fileName.substring(colon + 1);
-                }
-            }
-        }
-
-        fileName = fileName.replace(File.separatorChar, '/');
-
-        // No absolute pathnames
-        // Windows (and Posix?) paths can start with "\\NetworkDrive\",
-        // so we loop on starting /'s.
-        while (fileName.startsWith("/")) {
-            fileName = fileName.substring(1);
-        }
-
+        String fileName = normalizeFileName(file.getPath());
         this.linkName = new StringBuffer("");
         this.name = new StringBuffer(fileName);
 
@@ -245,7 +211,8 @@
             this.mode = DEFAULT_DIR_MODE;
             this.linkFlag = LF_DIR;
 
-            if (this.name.charAt(this.name.length() - 1) != '/') {
+            int nameLength = name.length();
+            if (nameLength == 0 || name.charAt(nameLength - 1) != '/') {
                 this.name.append("/");
             }
         } else {
@@ -331,7 +298,7 @@
      * @param name This entry's new name.
      */
     public void setName(String name) {
-        this.name = new StringBuffer(name);
+        this.name = new StringBuffer(normalizeFileName(name));
     }
 
     /**
@@ -635,4 +602,46 @@
         offset += DEVLEN;
         devMinor = (int) TarUtils.parseOctal(header, offset, DEVLEN);
     }
+
+    /**
+     * Strips Windows' drive letter as well as any leading slashes,
+     * turns path separators into forward slahes.
+     */
+    private static String normalizeFileName(String fileName) {
+        String osname = System.getProperty("os.name").toLowerCase(Locale.US);
+
+        if (osname != null) {
+
+            // Strip off drive letters!
+            // REVIEW Would a better check be "(File.separator == '\')"?
+
+            if (osname.startsWith("windows")) {
+                if (fileName.length() > 2) {
+                    char ch1 = fileName.charAt(0);
+                    char ch2 = fileName.charAt(1);
+
+                    if (ch2 == ':'
+                        && ((ch1 >= 'a' && ch1 <= 'z')
+                            || (ch1 >= 'A' && ch1 <= 'Z'))) {
+                        fileName = fileName.substring(2);
+                    }
+                }
+            } else if (osname.indexOf("netware") > -1) {
+                int colon = fileName.indexOf(':');
+                if (colon != -1) {
+                    fileName = fileName.substring(colon + 1);
+                }
+            }
+        }
+
+        fileName = fileName.replace(File.separatorChar, '/');
+
+        // No absolute pathnames
+        // Windows (and Posix?) paths can start with "\\NetworkDrive\",
+        // so we loop on starting /'s.
+        while (fileName.startsWith("/")) {
+            fileName = fileName.substring(1);
+        }
+        return fileName;
+    }
 }

Propchange: ant/core/trunk/src/main/org/apache/tools/tar/TarEntry.java
------------------------------------------------------------------------------
--- svn:mergeinfo (added)
+++ svn:mergeinfo Tue Mar 17 12:59:48 2009
@@ -0,0 +1 @@
+/commons/sandbox/compress/trunk/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveEntry.java:755227



Mime
View raw message