From 6eda1948e0458c9e81601e3acb3e179856632ca6 Mon Sep 17 00:00:00 2001 From: shyouhei Date: Wed, 25 Feb 2009 05:56:46 +0000 Subject: merge revision(s) 21447: * win32/win32.c (open_dir_handle): extracted from rb_w32_opendir. * win32/win32.c (winnt_stat): gets rid of strange behavior of GetFileAttributes(). [ruby-core:21269] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8_6@22613 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 7 +++++ version.h | 8 ++--- win32/win32.c | 95 ++++++++++++++++++++++++++++++++++++++++++----------------- 3 files changed, 79 insertions(+), 31 deletions(-) diff --git a/ChangeLog b/ChangeLog index 316f812fd8..bc2d2ee5b8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +Wed Feb 25 14:56:30 2009 Nobuyoshi Nakada + + * win32/win32.c (open_dir_handle): extracted from rb_w32_opendir. + + * win32/win32.c (winnt_stat): gets rid of strange behavior of + GetFileAttributes(). [ruby-core:21269] + Tue Feb 24 02:41:47 2009 Masatoshi SEKI * lib/erb.rb (PercentScanner): remove PercentScanner. fixed % after diff --git a/version.h b/version.h index 125e2e585c..50da779862 100644 --- a/version.h +++ b/version.h @@ -1,15 +1,15 @@ #define RUBY_VERSION "1.8.6" -#define RUBY_RELEASE_DATE "2009-02-24" +#define RUBY_RELEASE_DATE "2009-02-25" #define RUBY_VERSION_CODE 186 -#define RUBY_RELEASE_CODE 20090224 -#define RUBY_PATCHLEVEL 352 +#define RUBY_RELEASE_CODE 20090225 +#define RUBY_PATCHLEVEL 353 #define RUBY_VERSION_MAJOR 1 #define RUBY_VERSION_MINOR 8 #define RUBY_VERSION_TEENY 6 #define RUBY_RELEASE_YEAR 2009 #define RUBY_RELEASE_MONTH 2 -#define RUBY_RELEASE_DAY 24 +#define RUBY_RELEASE_DAY 25 #ifdef RUBY_EXTERN RUBY_EXTERN const char ruby_version[]; diff --git a/win32/win32.c b/win32/win32.c index 91b4ea89b8..f1f45f883f 100644 --- a/win32/win32.c +++ b/win32/win32.c @@ -1467,14 +1467,44 @@ rb_w32_cmdvector(const char *cmd, char ***vec) #define BitOfIsRep(n) ((n) * 2 + 1) #define DIRENT_PER_CHAR (CHAR_BIT / 2) +static HANDLE +open_dir_handle(const char *filename, WIN32_FIND_DATA *fd) +{ + HANDLE fh; + static const char wildcard[] = "/*"; + long len = strlen(filename); + char *scanname = malloc(len + sizeof(wildcard)); + + // + // Create the search pattern + // + if (!scanname) { + return INVALID_HANDLE_VALUE; + } + memcpy(scanname, filename, len + 1); + + if (index("/\\:", *CharPrev(scanname, scanname + len)) == NULL) + memcpy(scanname + len, wildcard, sizeof(wildcard)); + else + memcpy(scanname + len, wildcard + 1, sizeof(wildcard) - 1); + + // + // do the FindFirstFile call + // + fh = FindFirstFile(scanname, fd); + free(scanname); + if (fh == INVALID_HANDLE_VALUE) { + errno = map_errno(GetLastError()); + } + return fh; +} + DIR * rb_w32_opendir(const char *filename) { DIR *p; long len; long idx; - char scannamespc[PATHLEN]; - char *scanname = scannamespc; struct stat sbuf; WIN32_FIND_DATA fd; HANDLE fh; @@ -1492,35 +1522,17 @@ rb_w32_opendir(const char *filename) return NULL; } - // - // Get us a DIR structure - // - - p = xcalloc(sizeof(DIR), 1); - if (p == NULL) + fh = open_dir_handle(filename, &fd); + if (fh == INVALID_HANDLE_VALUE) { return NULL; - - // - // Create the search pattern - // - - strcpy(scanname, filename); - - if (index("/\\:", *CharPrev(scanname, scanname + strlen(scanname))) == NULL) - strcat(scanname, "/*"); - else - strcat(scanname, "*"); + } // - // do the FindFirstFile call + // Get us a DIR structure // - - fh = FindFirstFile(scanname, &fd); - if (fh == INVALID_HANDLE_VALUE) { - errno = map_errno(GetLastError()); - free(p); + p = calloc(sizeof(DIR), 1); + if (p == NULL) return NULL; - } // // now allocate the first part of the string table for the @@ -3173,6 +3185,17 @@ fileattr_to_unixmode(DWORD attr, const char *path) return mode; } +static int +check_valid_dir(const char *path) +{ + WIN32_FIND_DATA fd; + HANDLE fh = open_dir_handle(path, &fd); + if (fh == INVALID_HANDLE_VALUE) + return -1; + FindClose(fh); + return 0; +} + static int winnt_stat(const char *path, struct stat *st) { @@ -3203,6 +3226,9 @@ winnt_stat(const char *path, struct stat *st) errno = map_errno(GetLastError()); return -1; } + if (attr & FILE_ATTRIBUTE_DIRECTORY) { + if (check_valid_dir(path)) return -1; + } st->st_mode = fileattr_to_unixmode(attr, path); } @@ -3212,6 +3238,21 @@ winnt_stat(const char *path, struct stat *st) return 0; } +#ifdef WIN95 +static int +win95_stat(const char *path, struct stat *st) +{ + int ret = stat(path, st); + if (ret) return ret; + if (st->st_mode & S_IFDIR) { + return check_valid_dir(path); + } + return 0; +} +#else +#define win95_stat(path, st) -1 +#endif + int rb_w32_stat(const char *path, struct stat *st) { @@ -3247,7 +3288,7 @@ rb_w32_stat(const char *path, struct stat *st) } else if (*end == '\\' || (buf1 + 1 == end && *end == ':')) strcat(buf1, "."); - ret = IsWinNT() ? winnt_stat(buf1, st) : stat(buf1, st); + ret = IsWinNT() ? winnt_stat(buf1, st) : win95_stat(buf1, st); if (ret == 0) { st->st_mode &= ~(S_IWGRP | S_IWOTH); } -- cgit v1.2.3