2008-05-07 Dick Porter <dick@ximian.com>
authorDick Porter <dick@acm.org>
Wed, 7 May 2008 16:48:39 +0000 (16:48 -0000)
committerDick Porter <dick@acm.org>
Wed, 7 May 2008 16:48:39 +0000 (16:48 -0000)
* io.c (FindNextFile): Handle symlinks correctly.  Fixes bug
385765.

svn path=/trunk/mono/; revision=102741

mono/io-layer/ChangeLog
mono/io-layer/io.c

index 16a62e7db8ffc7ff823332c46a14fd89f4a4da54..449022ab70f13c81d32c5bb61f35333a7a86fc33 100644 (file)
@@ -1,3 +1,8 @@
+2008-05-07  Dick Porter  <dick@ximian.com>
+
+       * io.c (FindNextFile): Handle symlinks correctly.  Fixes bug
+       385765.
+
 2008-04-25  Zoltan Varga  <vargaz@gmail.com>
 
        * handles.c (_wapi_handle_check_share): Fix a crash introduced by the lazy
index fe806d078dd46185622571d1aff69a45e83dca6d..fc0dab30ec7f04448249e6b551f2b65c04e32f53 100644 (file)
@@ -2906,7 +2906,8 @@ gboolean FindNextFile (gpointer handle, WapiFindData *find_data)
 {
        struct _WapiHandle_find *find_handle;
        gboolean ok;
-       struct stat buf;
+       struct stat buf, linkbuf;
+       int result;
        gchar *filename;
        gchar *utf8_filename, *utf8_basename;
        gunichar2 *utf16_basename;
@@ -2938,7 +2939,14 @@ retry:
        /* stat next match */
 
        filename = g_build_filename (find_handle->dir_part, find_handle->namelist[find_handle->count ++], NULL);
-       if (_wapi_lstat (filename, &buf) != 0) {
+
+       result = _wapi_stat (filename, &buf);
+       if (result == -1 && errno == ENOENT) {
+               /* Might be a dangling symlink */
+               result = _wapi_lstat (filename, &buf);
+       }
+       
+       if (result != 0) {
 #ifdef DEBUG
                g_message ("%s: stat failed: %s", __func__, filename);
 #endif
@@ -2947,6 +2955,16 @@ retry:
                goto retry;
        }
 
+       result = _wapi_lstat (filename, &linkbuf);
+       if (result != 0) {
+#ifdef DEBUG
+               g_message ("%s: lstat failed: %s", __func__, filename);
+#endif
+
+               g_free (filename);
+               goto retry;
+       }
+
        utf8_filename = mono_utf8_from_external (filename);
        if (utf8_filename == NULL) {
                /* We couldn't turn this filename into utf8 (eg the
@@ -2971,7 +2989,7 @@ retry:
        else
                create_time = buf.st_ctime;
        
-       find_data->dwFileAttributes = _wapi_stat_to_file_attributes (utf8_filename, &buf, &buf);
+       find_data->dwFileAttributes = _wapi_stat_to_file_attributes (utf8_filename, &buf, &linkbuf);
 
        _wapi_time_t_to_filetime (create_time, &find_data->ftCreationTime);
        _wapi_time_t_to_filetime (buf.st_atime, &find_data->ftLastAccessTime);