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

ruby-changes:42350

From: naruse <ko1@a...>
Date: Wed, 30 Mar 2016 02:17:55 +0900 (JST)
Subject: [ruby-changes:42350] naruse:r54424 (ruby_2_3): merge revision(s) 53688, 53689, 53690, 53702: [Backport #11874]

naruse	2016-03-30 02:17:50 +0900 (Wed, 30 Mar 2016)

  New Revision: 54424

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

  Log:
    merge revision(s) 53688,53689,53690,53702: [Backport #11874]
    
    * win32/win32.c (fileattr_to_unixmode, rb_w32_reparse_symlink_p): volume
      mount point should be treated as directory, not symlink.
      [ruby-core:72483] [Bug #11874]
    
    * win32/win32.c (rb_w32_read_reparse_point): check the reparse point is
      a volume mount point or not.
    
    * win32/file.c (rb_readlink): follow above change (but this pass won't
      be used).
    
    * win32/file.c (rb_readlink): drop garbage after the substitute
      name, as rb_w32_read_reparse_point returns the expected buffer
      size but "\??\" prefix is dropped from the result.
    
    * win32/win32.c (w32_readlink): ditto, including NUL-terminator.

  Modified directories:
    branches/ruby_2_3/
  Modified files:
    branches/ruby_2_3/ChangeLog
    branches/ruby_2_3/test/ruby/test_file_exhaustive.rb
    branches/ruby_2_3/version.h
    branches/ruby_2_3/win32/file.c
    branches/ruby_2_3/win32/win32.c
Index: ruby_2_3/ChangeLog
===================================================================
--- ruby_2_3/ChangeLog	(revision 54423)
+++ ruby_2_3/ChangeLog	(revision 54424)
@@ -1,3 +1,23 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_3/ChangeLog#L1
+Wed Mar 30 02:17:33 2016  Nobuyoshi Nakada  <nobu@r...>
+
+	* win32/file.c (rb_readlink): drop garbage after the substitute
+	  name, as rb_w32_read_reparse_point returns the expected buffer
+	  size but "\??\" prefix is dropped from the result.
+
+	* win32/win32.c (w32_readlink): ditto, including NUL-terminator.
+
+Wed Mar 30 02:17:33 2016  NAKAMURA Usaku  <usa@r...>
+
+	* win32/win32.c (fileattr_to_unixmode, rb_w32_reparse_symlink_p): volume
+	  mount point should be treated as directory, not symlink.
+	  [ruby-core:72483] [Bug #11874]
+
+	* win32/win32.c (rb_w32_read_reparse_point): check the reparse point is
+	  a volume mount point or not.
+
+	* win32/file.c (rb_readlink): follow above change (but this pass won't
+	  be used).
+
 Wed Mar 30 01:32:14 2016  Rei Odaira  <Rei.Odaira@g...>
 
 	* test/-ext-/time/test_new.rb (test_timespec_new): change a gmtoff
Index: ruby_2_3/test/ruby/test_file_exhaustive.rb
===================================================================
--- ruby_2_3/test/ruby/test_file_exhaustive.rb	(revision 54423)
+++ ruby_2_3/test/ruby/test_file_exhaustive.rb	(revision 54424)
@@ -557,6 +557,24 @@ class TestFileExhaustive < Test::Unit::T https://github.com/ruby/ruby/blob/trunk/ruby_2_3/test/ruby/test_file_exhaustive.rb#L557
     end;
   end
 
+  if NTFS
+    def test_readlink_junction
+      base = File.basename(nofile)
+      err = IO.popen(%W"cmd.exe /c mklink /j #{base} .", chdir: @dir, err: %i[child out], &:read)
+      skip err unless $?.success?
+      assert_equal(@dir, File.readlink(nofile))
+    end
+
+    def test_realpath_mount_point
+      vol = IO.popen(["mountvol", DRIVE, "/l"], &:read).strip
+      Dir.mkdir(mnt = File.join(@dir, mntpnt = "mntpnt"))
+      system("mountvol", mntpnt, vol, chdir: @dir)
+      assert_equal(mnt, File.realpath(mnt))
+    ensure
+      system("mountvol", mntpnt, "/d", chdir: @dir)
+    end
+  end
+
   def test_unlink
     assert_equal(1, File.unlink(regular_file))
     make_file("foo", regular_file)
Index: ruby_2_3/win32/win32.c
===================================================================
--- ruby_2_3/win32/win32.c	(revision 54423)
+++ ruby_2_3/win32/win32.c	(revision 54424)
@@ -4804,8 +4804,20 @@ reparse_symlink(const WCHAR *path, rb_w3 https://github.com/ruby/ruby/blob/trunk/ruby_2_3/win32/win32.c#L4804
 int
 rb_w32_reparse_symlink_p(const WCHAR *path)
 {
-    rb_w32_reparse_buffer_t rp;
-    switch (reparse_symlink(path, &rp, sizeof(rp))) {
+    VALUE wtmp = 0;
+    rb_w32_reparse_buffer_t rbuf, *rp = &rbuf;
+    WCHAR *wbuf;
+    DWORD len;
+    int e;
+
+    e = rb_w32_read_reparse_point(path, rp, sizeof(rbuf), &wbuf, &len);
+    if (e == ERROR_MORE_DATA) {
+	size_t size = rb_w32_reparse_buffer_size(len + 1);
+	rp = ALLOCV(wtmp, size);
+	e = rb_w32_read_reparse_point(path, rp, size, &wbuf, &len);
+	ALLOCV_END(wtmp);
+    }
+    switch (e) {
       case 0:
       case ERROR_MORE_DATA:
 	return TRUE;
@@ -4830,6 +4842,7 @@ rb_w32_read_reparse_point(const WCHAR *p https://github.com/ruby/ruby/blob/trunk/ruby_2_3/win32/win32.c#L4842
 	    *len = ret / sizeof(WCHAR);
 	}
 	else { /* IO_REPARSE_TAG_MOUNT_POINT */
+	    static const WCHAR *volume = L"Volume{";
 	    /* +4/-4 means to drop "\??\" */
 	    name = ((char *)rp->MountPointReparseBuffer.PathBuffer +
 		    rp->MountPointReparseBuffer.SubstituteNameOffset +
@@ -4837,6 +4850,9 @@ rb_w32_read_reparse_point(const WCHAR *p https://github.com/ruby/ruby/blob/trunk/ruby_2_3/win32/win32.c#L4850
 	    ret = rp->MountPointReparseBuffer.SubstituteNameLength;
 	    *len = ret / sizeof(WCHAR);
 	    ret -= 4 * sizeof(WCHAR);
+	    if (ret > sizeof(volume) - 1 * sizeof(WCHAR) &&
+		memcmp(name, volume, sizeof(volume) - 1 * sizeof(WCHAR)) == 0)
+		return -1;
 	}
 	*result = name;
 	if (e) {
@@ -4872,6 +4888,7 @@ w32_readlink(UINT cp, const char *path, https://github.com/ruby/ruby/blob/trunk/ruby_2_3/win32/win32.c#L4888
 	errno = map_errno(e);
 	return -1;
     }
+    len = lstrlenW(wname) + 1;
     ret = WideCharToMultiByte(cp, 0, wname, len, buf, bufsize, NULL, NULL);
     ALLOCV_END(wtmp);
     if (e) {
@@ -5295,7 +5312,10 @@ fileattr_to_unixmode(DWORD attr, const W https://github.com/ruby/ruby/blob/trunk/ruby_2_3/win32/win32.c#L5312
     }
 
     if (attr & FILE_ATTRIBUTE_REPARSE_POINT) {
-	mode |= S_IFLNK | S_IEXEC;
+	if (rb_w32_reparse_symlink_p(path))
+	    mode |= S_IFLNK | S_IEXEC;
+	else
+	    mode |= S_IFDIR | S_IEXEC;
     }
     else if (attr & FILE_ATTRIBUTE_DIRECTORY) {
 	mode |= S_IFDIR | S_IEXEC;
Index: ruby_2_3/win32/file.c
===================================================================
--- ruby_2_3/win32/file.c	(revision 54423)
+++ ruby_2_3/win32/file.c	(revision 54424)
@@ -689,11 +689,15 @@ rb_readlink(VALUE path, rb_encoding *res https://github.com/ruby/ruby/blob/trunk/ruby_2_3/win32/file.c#L689
     ALLOCV_END(wpathbuf);
     if (e) {
 	ALLOCV_END(wtmp);
-	rb_syserr_fail_path(rb_w32_map_errno(e), path);
+	if (e != -1)
+	    rb_syserr_fail_path(rb_w32_map_errno(e), path);
+	else /* not symlink; maybe volume mount point */
+	    rb_syserr_fail_path(EINVAL, path);
     }
     enc = resultenc;
     cp = path_cp = code_page(enc);
     if (cp == INVALID_CODE_PAGE) cp = CP_UTF8;
+    len = lstrlenW(wbuf);
     str = append_wstr(rb_enc_str_new(0, 0, enc), wbuf, len, cp, path_cp, enc);
     ALLOCV_END(wtmp);
     return str;
Index: ruby_2_3/version.h
===================================================================
--- ruby_2_3/version.h	(revision 54423)
+++ ruby_2_3/version.h	(revision 54424)
@@ -1,6 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_3/version.h#L1
 #define RUBY_VERSION "2.3.0"
 #define RUBY_RELEASE_DATE "2016-03-30"
-#define RUBY_PATCHLEVEL 68
+#define RUBY_PATCHLEVEL 69
 
 #define RUBY_RELEASE_YEAR 2016
 #define RUBY_RELEASE_MONTH 3

Property changes on: ruby_2_3
___________________________________________________________________
Modified: svn:mergeinfo
   Merged /trunk:r53688-53690,53702


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

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