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] Fix for PR/9253: File.listFiles( ) Error on Win32


Hi,

    This patch fixes PR/9253 as reported by Erik on the main list.
In summary, the problem was that File.listFiles( ) was not working
on Win32 if it was created as (say) 'new File("c:")' - drive
letters seemed to be confusing the implementation.

The real problem turns out to be the fact that the performList( )
function in "java/io/natFileWin32.cc" gets the canonical path
to the file path and merely adds "\*.*" to it to create a filter to
search for files using the Win32 FindFirstFile( ) function.

However, "c:" maps to "c:\" in the canonical path and the extra
"\" appended causes FindFirstFile( ) to fail. (Try it out for
yourself by typing "dir c:\\*.*" on a Command Prompt in Windows.)

Note that names like "c:\temp" and "c:\temp\" map to "c:\temp",
but "c:\" as well as "c:" map to "c:\".

The following patch guards against the case where the canonical
path already has a "\" at the end. After this change, listFiles( )
seems to work correctly for a range of inputs I could test with,
which were failing earlier.


ChangeLog:

2003-01-23  Ranjit Mathew  <rmathew@hotmail.com>

        * java/io/natFileWin32.cc (performList): Append only "*.*"
        if the canonical file path already has a "\" at the end.


Patch:
-------------------------------- 8< --------------------------------
--- java/io/natFileWin32.cc	2003-01-23 17:50:26.000000000 +0530
+++ java/io/natFileWin32.cc	2003-01-23 17:52:33.000000000 +0530
@@ -147,5 +147,8 @@
   jsize total = JvGetStringUTFRegion (canon, 0, canon->length(), buf);
   // FIXME?
-  strcpy(&buf[total], "\\*.*");
+  if (buf[total-1] == '\\')
+    strcpy (&buf[total], "*.*");
+  else
+    strcpy (&buf[total], "\\*.*");

   WIN32_FIND_DATA data;
-------------------------------- 8< --------------------------------

Sincerely Yours,
Ranjit.

--
Ranjit Mathew        Email: rmathew AT hotmail DOT com
Bangalore,
INDIA.               Web: http://ranjitmathew.tripod.com/



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