From 034e38d8a2de9bfd82438fab0c0dc6eaa1335d7f Mon Sep 17 00:00:00 2001 From: nobu Date: Sat, 7 Feb 2015 10:25:27 +0000 Subject: dir.c: long path name on Windows * dir.c (has_magic): always get long path name on Windows even if no tilde is there. [ruby-core:68011] [Bug #10819] * dir.c (replace_real_basename): FindFirstFile ignore redirection character, check if exists before call it. cf. [Bug #8597] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49537 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 8 ++++++++ dir.c | 32 +++++++++++++------------------- 2 files changed, 21 insertions(+), 19 deletions(-) diff --git a/ChangeLog b/ChangeLog index 3e79babca0..1cc3ea1c64 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +Sat Feb 7 19:25:25 2015 Nobuyoshi Nakada + + * dir.c (has_magic): always get long path name on Windows even if + no tilde is there. [ruby-core:68011] [Bug #10819] + + * dir.c (replace_real_basename): FindFirstFile ignore redirection + character, check if exists before call it. cf. [Bug #8597] + Sat Feb 7 13:30:11 2015 Masaki Suketa * test/win32ole/test_win32ole_record.rb diff --git a/dir.c b/dir.c index 8e5c5c5fe4..229913865d 100644 --- a/dir.c +++ b/dir.c @@ -71,6 +71,9 @@ char *strchr(char*,char); #define rmdir(p) rb_w32_urmdir(p) #undef opendir #define opendir(p) rb_w32_uopendir(p) +#define IS_WIN32 1 +#else +#define IS_WIN32 0 #endif #ifdef HAVE_SYS_ATTR_H @@ -1210,28 +1213,17 @@ has_magic(const char *p, const char *pend, int flags, rb_encoding *enc) break; #ifdef _WIN32 + case '.': + break; + case '~': - /* possibly legacy 8.3 short name */ - if (p < pend && (c = *p, ISDIGIT(c))) { - while (++p < pend && (c = *p, ISDIGIT(c))); - if (p == pend || c == '.') hasalpha = 1; - } - continue; + hasalpha = 1; + break; #endif - default: - if (ISALPHA(c)) { + if (IS_WIN32 || ISALPHA(c)) { hasalpha = 1; } -#ifdef _WIN32 - else if (!rb_isascii(c)) { - unsigned int code = rb_enc_mbc_to_codepoint(p, pend, enc); - if (ONIGENC_IS_CODE_ALPHA(enc, code)) { - /* Full width alphabets */ - hasalpha = 1; - } - } -#endif break; } @@ -1469,8 +1461,9 @@ replace_real_basename(char *path, long base, rb_encoding *enc, int norm_p) char *plainname = path; volatile VALUE tmp = 0; WIN32_FIND_DATAW fd; + WIN32_FILE_ATTRIBUTE_DATA fa; WCHAR *wplain; - HANDLE h; + HANDLE h = INVALID_HANDLE_VALUE; long wlen; if (enc && enc != rb_usascii_encoding() && @@ -1483,7 +1476,8 @@ replace_real_basename(char *path, long base, rb_encoding *enc, int norm_p) wplain = rb_w32_mbstr_to_wstr(CP_UTF8, plainname, -1, &wlen); if (tmp) rb_str_resize(tmp, 0); if (!wplain) return path; - h = FindFirstFileW(wplain, &fd); + if (GetFileAttributesExW(wplain, GetFileExInfoStandard, &fa)) + h = FindFirstFileW(wplain, &fd); free(wplain); if (h == INVALID_HANDLE_VALUE) return path; FindClose(h); -- cgit v1.2.3