This is the mail archive of the java-patches@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Patch: FYI: File cleanup, URL change


I'm checking this in on the trunk.

This has two parts.  First, a couple fixes for dumb buglets in the
File.getCanonicalPath change from yesterday.

Second, when parsing a URL we sometimes canonicalize the path.  In
this case we want to make sure to preserve a trailing "/", if there
was one.  At least eclipse relies on this, and this is what the JDK
does.

Tom

Index: ChangeLog
from  Tom Tromey  <tromey@redhat.com>

	* java/net/URLStreamHandler.java (parseURL): If original file
	ends with "/", so must canonical result.
	* java/io/natFilePosix.cc (getCanonicalPath): Clean up snafus
	with nul-termination and finding previous "/".

Index: java/io/natFilePosix.cc
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/io/natFilePosix.cc,v
retrieving revision 1.4
diff -u -r1.4 natFilePosix.cc
--- java/io/natFilePosix.cc 11 Sep 2003 16:44:39 -0000 1.4
+++ java/io/natFilePosix.cc 12 Sep 2003 00:15:41 -0000
@@ -164,7 +164,7 @@
 	      // Found ".." component, lop off last part from existing
 	      // buffer.
 	      --out_idx;
-	      while (out_idx > 0 && buf[out_idx] != '/')
+	      while (out_idx > 0 && buf2[out_idx] != '/')
 		--out_idx;
 	      // Can't go up past "/".
 	      if (out_idx == 0)
@@ -179,7 +179,8 @@
 	      out_idx += len;
 	    }
 	}
-      buf[out_idx] = '\0';
+
+      buf2[out_idx] = '\0';
     }
 
   // FIXME: what encoding to assume for file names?  This affects many
Index: java/net/URLStreamHandler.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/net/URLStreamHandler.java,v
retrieving revision 1.20
diff -u -r1.20 URLStreamHandler.java
--- java/net/URLStreamHandler.java 24 Jun 2003 20:22:48 -0000 1.20
+++ java/net/URLStreamHandler.java 12 Sep 2003 00:15:41 -0000
@@ -196,7 +196,11 @@
             // need to canonicalise the file path.
             try
               {
+		boolean endsWithSlash = file.charAt(file.length() - 1) == '/';
                 file = new File (file).getCanonicalPath ();
+		if (endsWithSlash
+		    && file.charAt(file.length() - 1) != '/')
+		  file += '/';
               }
             catch (IOException e)
               {


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]