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

ruby-changes:72673

From: NAKAMURA <ko1@a...>
Date: Mon, 25 Jul 2022 20:40:03 +0900 (JST)
Subject: [ruby-changes:72673] 28b238f2cb (ruby_3_0): merge revision(s): a0040af6715d85f416f1282588974e151a8164eb

https://git.ruby-lang.org/ruby.git/commit/?id=28b238f2cb

From 28b238f2cbcbf9993c4ce8031cbe19bd2accbfbf Mon Sep 17 00:00:00 2001
From: NAKAMURA Usaku <usa@r...>
Date: Sat, 18 Jun 2022 22:54:12 +0900
Subject: merge revision(s): a0040af6715d85f416f1282588974e151a8164eb

	[Win32] Fix mode of character/pipe device stat [Bug #18732]
---
 test/ruby/test_file_exhaustive.rb | 33 ++++++++++++++++++++++++++++-----
 version.h                         |  8 ++++----
 win32/win32.c                     | 22 ++++++++++++++++------
 3 files changed, 48 insertions(+), 15 deletions(-)

diff --git a/test/ruby/test_file_exhaustive.rb b/test/ruby/test_file_exhaustive.rb
index e2314424b3..2fe3b8535b 100644
--- a/test/ruby/test_file_exhaustive.rb
+++ b/test/ruby/test_file_exhaustive.rb
@@ -160,9 +160,7 @@ class TestFileExhaustive < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_file_exhaustive.rb#L160
   end
 
   def chardev
-    return @chardev if defined? @chardev
-    @chardev = File::NULL == "/dev/null" ? "/dev/null" : nil
-    @chardev
+    File::NULL
   end
 
   def blockdev
@@ -319,7 +317,7 @@ class TestFileExhaustive < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_file_exhaustive.rb#L317
     assert_file.not_chardev?(regular_file)
     assert_file.not_chardev?(utf8_file)
     assert_file.not_chardev?(nofile)
-    assert_file.chardev?(chardev) if chardev
+    assert_file.chardev?(chardev)
   end
 
   def test_exist_p
@@ -1481,6 +1479,31 @@ class TestFileExhaustive < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_file_exhaustive.rb#L1479
       assert_equal(File.executable?(f), test(?x, f))
       assert_equal(File.executable_real?(f), test(?X, f))
       assert_equal(File.zero?(f), test(?z, f))
+
+      stat = File.stat(f)
+      assert_equal(stat.atime, File.atime(f), f)
+      assert_equal(stat.ctime, File.ctime(f), f)
+      assert_equal(stat.mtime, File.mtime(f), f)
+      assert_equal(stat.blockdev?, File.blockdev?(f), f)
+      assert_equal(stat.chardev?, File.chardev?(f), f)
+      assert_equal(stat.directory?, File.directory?(f), f)
+      assert_equal(stat.file?, File.file?(f), f)
+      assert_equal(stat.setgid?, File.setgid?(f), f)
+      assert_equal(stat.grpowned?, File.grpowned?(f), f)
+      assert_equal(stat.sticky?, File.sticky?(f), f) if stickyfile
+      assert_equal(File.lstat(f).symlink?, File.symlink?(f), f)
+      assert_equal(stat.owned?, File.owned?(f), f)
+      assert_equal(stat.pipe?, File.pipe?(f), f)
+      assert_equal(stat.readable?, File.readable?(f), f)
+      assert_equal(stat.readable_real?, File.readable_real?(f), f)
+      assert_equal(stat.size?, File.size?(f), f)
+      assert_equal(stat.socket?, File.socket?(f), f)
+      assert_equal(stat.setuid?, File.setuid?(f), f)
+      assert_equal(stat.writable?, File.writable?(f), f)
+      assert_equal(stat.writable_real?, File.writable_real?(f), f)
+      assert_equal(stat.executable?, File.executable?(f), f)
+      assert_equal(stat.executable_real?, File.executable_real?(f), f)
+      assert_equal(stat.zero?, File.zero?(f), f)
     end
     assert_equal(false, test(?-, @dir, fn1))
     assert_equal(true, test(?-, fn1, fn1))
@@ -1590,7 +1613,7 @@ class TestFileExhaustive < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_file_exhaustive.rb#L1613
   def test_stat_chardev_p
     assert_not_predicate(File::Stat.new(@dir), :chardev?)
     assert_not_predicate(File::Stat.new(regular_file), :chardev?)
-    assert_predicate(File::Stat.new(chardev), :chardev?) if chardev
+    assert_predicate(File::Stat.new(chardev), :chardev?)
   end
 
   def test_stat_readable_p
diff --git a/version.h b/version.h
index e00808d240..647e4cee3d 100644
--- a/version.h
+++ b/version.h
@@ -10,13 +10,13 @@ https://github.com/ruby/ruby/blob/trunk/version.h#L10
  */
 # define RUBY_VERSION_MAJOR RUBY_API_VERSION_MAJOR
 # define RUBY_VERSION_MINOR RUBY_API_VERSION_MINOR
-#define RUBY_VERSION_TEENY 4
+#define RUBY_VERSION_TEENY 5
 #define RUBY_RELEASE_DATE RUBY_RELEASE_YEAR_STR"-"RUBY_RELEASE_MONTH_STR"-"RUBY_RELEASE_DAY_STR
-#define RUBY_PATCHLEVEL 208
+#define RUBY_PATCHLEVEL 209
 
 #define RUBY_RELEASE_YEAR 2022
-#define RUBY_RELEASE_MONTH 4
-#define RUBY_RELEASE_DAY 12
+#define RUBY_RELEASE_MONTH 6
+#define RUBY_RELEASE_DAY 18
 
 #include "ruby/version.h"
 
diff --git a/win32/win32.c b/win32/win32.c
index cad2784f69..5fd7595414 100644
--- a/win32/win32.c
+++ b/win32/win32.c
@@ -5569,10 +5569,8 @@ filetime_to_nsec(const FILETIME *ft) https://github.com/ruby/ruby/blob/trunk/win32/win32.c#L5569
 
 /* License: Ruby's */
 static unsigned
-fileattr_to_unixmode(DWORD attr, const WCHAR *path)
+fileattr_to_unixmode(DWORD attr, const WCHAR *path, unsigned mode)
 {
-    unsigned mode = 0;
-
     if (attr & FILE_ATTRIBUTE_READONLY) {
 	mode |= S_IREAD;
     }
@@ -5580,7 +5578,10 @@ fileattr_to_unixmode(DWORD attr, const WCHAR *path) https://github.com/ruby/ruby/blob/trunk/win32/win32.c#L5578
 	mode |= S_IREAD | S_IWRITE | S_IWUSR;
     }
 
-    if (attr & FILE_ATTRIBUTE_REPARSE_POINT) {
+    if (mode & S_IFMT) {
+	/* format is already set */
+    }
+    else if (attr & FILE_ATTRIBUTE_REPARSE_POINT) {
 	if (rb_w32_reparse_symlink_p(path))
 	    mode |= S_IFLNK | S_IEXEC;
 	else
@@ -5675,7 +5676,7 @@ stat_by_find(const WCHAR *path, struct stati128 *st) https://github.com/ruby/ruby/blob/trunk/win32/win32.c#L5676
 	return -1;
     }
     FindClose(h);
-    st->st_mode  = fileattr_to_unixmode(wfd.dwFileAttributes, path);
+    st->st_mode  = fileattr_to_unixmode(wfd.dwFileAttributes, path, 0);
     st->st_atime = filetime_to_unixtime(&wfd.ftLastAccessTime);
     st->st_atimensec = filetime_to_nsec(&wfd.ftLastAccessTime);
     st->st_mtime = filetime_to_unixtime(&wfd.ftLastWriteTime);
@@ -5710,6 +5711,15 @@ winnt_stat(const WCHAR *path, struct stati128 *st, BOOL lstat) https://github.com/ruby/ruby/blob/trunk/win32/win32.c#L5711
     if (f != INVALID_HANDLE_VALUE) {
 	DWORD attr = stati128_handle(f, st);
 	const DWORD len = get_final_path(f, finalname, numberof(finalname), 0);
+	unsigned mode = 0;
+	switch (GetFileType(f)) {
+	  case FILE_TYPE_CHAR:
+	    mode = S_IFCHR;
+	    break;
+	  case FILE_TYPE_PIPE:
+	    mode = S_IFIFO;
+	    break;
+	}
 	CloseHandle(f);
 	if (attr & FILE_ATTRIBUTE_REPARSE_POINT) {
 	    /* TODO: size in which encoding? */
@@ -5721,7 +5731,7 @@ winnt_stat(const WCHAR *path, struct stati128 *st, BOOL lstat) https://github.com/ruby/ruby/blob/trunk/win32/win32.c#L5731
 	if (attr & FILE_ATTRIBUTE_DIRECTORY) {
 	    if (check_valid_dir(path)) return -1;
 	}
-	st->st_mode = fileattr_to_unixmode(attr, path);
+	st->st_mode = fileattr_to_unixmode(attr, path, mode);
 	if (len) {
 	    finalname[min(len, numberof(finalname)-1)] = L'\0';
 	    path = finalname;
-- 
cgit v1.2.1


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

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