From: Dick Porter Date: Wed, 7 May 2008 16:48:39 +0000 (-0000) Subject: 2008-05-07 Dick Porter X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=commitdiff_plain;h=2cf315cb6052df9b26d8560318f702c1a621f9c6;hp=632bbe7a3e6bee509fa9076506fe8698b4eddc39;p=mono.git 2008-05-07 Dick Porter * io.c (FindNextFile): Handle symlinks correctly. Fixes bug 385765. svn path=/trunk/mono/; revision=102741 --- diff --git a/mono/io-layer/ChangeLog b/mono/io-layer/ChangeLog index 16a62e7db8f..449022ab70f 100644 --- a/mono/io-layer/ChangeLog +++ b/mono/io-layer/ChangeLog @@ -1,3 +1,8 @@ +2008-05-07 Dick Porter + + * io.c (FindNextFile): Handle symlinks correctly. Fixes bug + 385765. + 2008-04-25 Zoltan Varga * handles.c (_wapi_handle_check_share): Fix a crash introduced by the lazy diff --git a/mono/io-layer/io.c b/mono/io-layer/io.c index fe806d078dd..fc0dab30ec7 100644 --- a/mono/io-layer/io.c +++ b/mono/io-layer/io.c @@ -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);