[前][次][番号順一覧][スレッド一覧]

ruby-changes:37575

From: naruse <ko1@a...>
Date: Fri, 20 Feb 2015 15:11:28 +0900 (JST)
Subject: [ruby-changes:37575] naruse:r49656 (ruby_2_2): merge revision(s) 49478, 49536, 49533, 49537: [Backport #10819]

naruse	2015-02-20 15:11:20 +0900 (Fri, 20 Feb 2015)

  New Revision: 49656

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=49656

  Log:
    merge revision(s) 49478,49536,49533,49537: [Backport #10819]
    
    * dir.c (glob_helper): obtain real name with FindFirstFile API
      instead of matchin all entries, on Windows.
      [ruby-core:67954] [Bug #10819]
    
    * 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]

  Modified directories:
    branches/ruby_2_2/
  Modified files:
    branches/ruby_2_2/ChangeLog
    branches/ruby_2_2/dir.c
    branches/ruby_2_2/test/ruby/test_dir.rb
    branches/ruby_2_2/version.h
Index: ruby_2_2/ChangeLog
===================================================================
--- ruby_2_2/ChangeLog	(revision 49655)
+++ ruby_2_2/ChangeLog	(revision 49656)
@@ -1,3 +1,17 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_2/ChangeLog#L1
+Fri Feb 20 15:08:17 2015  Nobuyoshi Nakada  <nobu@r...>
+
+	* 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]
+
+Fri Feb 20 15:08:17 2015  Nobuyoshi Nakada  <nobu@r...>
+
+	* dir.c (glob_helper): obtain real name with FindFirstFile API
+	  instead of matchin all entries, on Windows.
+	  [ruby-core:67954] [Bug #10819]
+
 Fri Feb 20 14:32:14 2015  Nobuyoshi Nakada  <nobu@r...>
 
 	* dir.c (dir_initialize): workaround of opendir failure at symlink
Index: ruby_2_2/dir.c
===================================================================
--- ruby_2_2/dir.c	(revision 49655)
+++ ruby_2_2/dir.c	(revision 49656)
@@ -71,6 +71,9 @@ char *strchr(char*,char); https://github.com/ruby/ruby/blob/trunk/ruby_2_2/dir.c#L71
 #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
@@ -81,6 +84,10 @@ char *strchr(char*,char); https://github.com/ruby/ruby/blob/trunk/ruby_2_2/dir.c#L84
 # define USE_NAME_ON_FS 1
 # define RUP32(size) ((size)+3/4)
 # define SIZEUP32(type) RUP32(sizeof(type))
+#elif defined _WIN32
+# define USE_NAME_ON_FS 1
+#elif defined DOSISH
+# define USE_NAME_ON_FS 2	/* by fnmatch */
 #else
 # define USE_NAME_ON_FS 0
 #endif
@@ -1177,10 +1184,19 @@ has_magic(const char *p, const char *pen https://github.com/ruby/ruby/blob/trunk/ruby_2_2/dir.c#L1184
 		return PLAIN;
 	    continue;
 
+#ifdef _WIN32
+	  case '.':
+	    break;
+
+	  case '~':
+	    hasalpha = 1;
+	    break;
+#endif
 	  default:
-	    if (ISALPHA(c)) {
+	    if (IS_WIN32 || ISALPHA(c)) {
 		hasalpha = 1;
 	    }
+	    break;
 	}
 
 	p = Next(p-1, pend, enc);
@@ -1373,7 +1389,7 @@ is_case_sensitive(DIR *dirp) https://github.com/ruby/ruby/blob/trunk/ruby_2_2/dir.c#L1389
 }
 
 static char *
-replace_real_basename(char *path, long base, int norm_p)
+replace_real_basename(char *path, long base, rb_encoding *enc, int norm_p)
 {
     u_int32_t attrbuf[SIZEUP32(attrreference_t) + RUP32(MAXPATHLEN * 3) + 1];
     struct attrlist al = {ATTR_BIT_MAP_COUNT, 0, ATTR_CMN_NAME};
@@ -1408,6 +1424,45 @@ replace_real_basename(char *path, long b https://github.com/ruby/ruby/blob/trunk/ruby_2_2/dir.c#L1424
     IF_NORMALIZE_UTF8PATH(if (!NIL_P(utf8str)) rb_str_resize(utf8str, 0));
     return path;
 }
+#elif defined _WIN32
+VALUE rb_w32_conv_from_wchar(const WCHAR *wstr, rb_encoding *enc);
+
+static char *
+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 = INVALID_HANDLE_VALUE;
+    long wlen;
+    if (enc &&
+	enc != rb_usascii_encoding() &&
+	enc != rb_ascii8bit_encoding() &&
+	enc != rb_utf8_encoding()) {
+	tmp = rb_enc_str_new_cstr(plainname, enc);
+	tmp = rb_str_encode_ospath(tmp);
+	plainname = RSTRING_PTR(tmp);
+    }
+    wplain = rb_w32_mbstr_to_wstr(CP_UTF8, plainname, -1, &wlen);
+    if (tmp) rb_str_resize(tmp, 0);
+    if (!wplain) return path;
+    if (GetFileAttributesExW(wplain, GetFileExInfoStandard, &fa))
+	h = FindFirstFileW(wplain, &fd);
+    free(wplain);
+    if (h == INVALID_HANDLE_VALUE) return path;
+    FindClose(h);
+    tmp = rb_w32_conv_from_wchar(fd.cFileName, enc);
+    wlen = RSTRING_LEN(tmp);
+    path = GLOB_REALLOC(path, base + wlen + 1);
+    memcpy(path + base, RSTRING_PTR(tmp), wlen);
+    path[base + wlen] = 0;
+    rb_str_resize(tmp, 0);
+    return path;
+}
+#elif USE_NAME_ON_FS == 1
+# error not implemented
 #endif
 
 enum answer {UNKNOWN = -1, NO, YES};
@@ -1473,7 +1528,7 @@ glob_helper( https://github.com/ruby/ruby/blob/trunk/ruby_2_2/dir.c#L1528
 	    plain = 1;
 	    break;
 	  case ALPHA:
-#ifdef HAVE_GETATTRLIST
+#if USE_NAME_ON_FS == 1
 	    plain = 1;
 #else
 	    magical = 1;
@@ -1533,11 +1588,11 @@ glob_helper( https://github.com/ruby/ruby/blob/trunk/ruby_2_2/dir.c#L1588
     if (magical || recursive) {
 	struct dirent *dp;
 	DIR *dirp;
-# ifdef DOSISH
+# if USE_NAME_ON_FS == 2
 	char *plainname = 0;
 # endif
 	IF_NORMALIZE_UTF8PATH(int norm_p);
-# ifdef DOSISH
+# if USE_NAME_ON_FS == 2
 	if (cur + 1 == end && (*cur)->type <= ALPHA) {
 	    plainname = join_path(path, pathlen, dirsep, (*cur)->str, strlen((*cur)->str));
 	    if (!plainname) return -1;
@@ -1633,7 +1688,7 @@ glob_helper( https://github.com/ruby/ruby/blob/trunk/ruby_2_2/dir.c#L1688
 		}
 		switch (p->type) {
 		  case ALPHA:
-# ifdef DOSISH
+# if USE_NAME_ON_FS == 2
 		    if (plainname) {
 			*new_end++ = p->next;
 			break;
@@ -1703,10 +1758,10 @@ glob_helper( https://github.com/ruby/ruby/blob/trunk/ruby_2_2/dir.c#L1758
 		    status = -1;
 		    break;
 		}
-#ifdef HAVE_GETATTRLIST
+#if USE_NAME_ON_FS == 1
 		if ((*cur)->type == ALPHA) {
 		    long base = pathlen + (dirsep != 0);
-		    buf = replace_real_basename(buf, base, IF_NORMALIZE_UTF8PATH(1)+0);
+		    buf = replace_real_basename(buf, base, enc, IF_NORMALIZE_UTF8PATH(1)+0);
 		}
 #endif
 		status = glob_helper(buf, 1, UNKNOWN, UNKNOWN, new_beg,
Index: ruby_2_2/version.h
===================================================================
--- ruby_2_2/version.h	(revision 49655)
+++ ruby_2_2/version.h	(revision 49656)
@@ -1,6 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_2/version.h#L1
 #define RUBY_VERSION "2.2.0"
 #define RUBY_RELEASE_DATE "2015-02-20"
-#define RUBY_PATCHLEVEL 64
+#define RUBY_PATCHLEVEL 65
 
 #define RUBY_RELEASE_YEAR 2015
 #define RUBY_RELEASE_MONTH 2
Index: ruby_2_2/test/ruby/test_dir.rb
===================================================================
--- ruby_2_2/test/ruby/test_dir.rb	(revision 49655)
+++ ruby_2_2/test/ruby/test_dir.rb	(revision 49656)
@@ -248,6 +248,18 @@ class TestDir < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/ruby_2_2/test/ruby/test_dir.rb#L248
     assert_equal(roots.map {|n| "/..#{n}"}, Dir.glob("/../*"), bug9648)
   end
 
+  if /mswin|mingw/ =~ RUBY_PLATFORM
+    def test_glob_legacy_short_name
+      bug10819 = '[ruby-core:67954] [Bug #10819]'
+      skip unless /\A\w:/ =~ ENV["ProgramFiles"]
+      short = "#$&/PROGRA~1"
+      skip unless File.directory?(short)
+      entries = Dir.glob("#{short}/Common*")
+      assert_not_empty(entries, bug10819)
+      assert_equal(Dir.glob("#{File.expand_path(short)}/Common*"), entries, bug10819)
+    end
+  end
+
   def test_home
     env_home = ENV["HOME"]
     env_logdir = ENV["LOGDIR"]

Property changes on: ruby_2_2
___________________________________________________________________
Modified: svn:mergeinfo
   Merged /trunk:r49478,49533,49536-49537


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]