ruby-changes:53021
From: aycabta <ko1@a...>
Date: Sat, 20 Oct 2018 20:47:52 +0900 (JST)
Subject: [ruby-changes:53021] aycabta:r65235 (trunk): Document File.{setuid?, setgid?, sticky?} support for IO objects [Bug #13972]
aycabta 2018-10-20 20:47:45 +0900 (Sat, 20 Oct 2018) New Revision: 65235 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=65235 Log: Document File.{setuid?,setgid?,sticky?} support for IO objects [Bug #13972] * file.c (rb_file_setuid_p): rdoc for IO object support (rb_file_sgid_p): ditto (rb_file_sticky_p): ditto * NEWS: inform users of new feature * test/file/test_file_exhaustive.rb (io_open): wrapper for bare IO object (test_suid): test for bare IO support (test_sgid): ditto (test_sticky): ditto Modified files: trunk/file.c trunk/test/ruby/test_file_exhaustive.rb Index: file.c =================================================================== --- file.c (revision 65234) +++ file.c (revision 65235) @@ -1948,6 +1948,8 @@ check3rdbyte(VALUE fname, int mode) https://github.com/ruby/ruby/blob/trunk/file.c#L1948 * File.setuid?(file_name) -> true or false * * Returns <code>true</code> if the named file has the setuid bit set. + * + * _file_name_ can be an IO object. */ static VALUE @@ -1965,6 +1967,8 @@ rb_file_suid_p(VALUE obj, VALUE fname) https://github.com/ruby/ruby/blob/trunk/file.c#L1967 * File.setgid?(file_name) -> true or false * * Returns <code>true</code> if the named file has the setgid bit set. + * + * _file_name_ can be an IO object. */ static VALUE @@ -1982,6 +1986,8 @@ rb_file_sgid_p(VALUE obj, VALUE fname) https://github.com/ruby/ruby/blob/trunk/file.c#L1986 * File.sticky?(file_name) -> true or false * * Returns <code>true</code> if the named file has the sticky bit set. + * + * _file_name_ can be an IO object. */ static VALUE Index: test/ruby/test_file_exhaustive.rb =================================================================== --- test/ruby/test_file_exhaustive.rb (revision 65234) +++ test/ruby/test_file_exhaustive.rb (revision 65235) @@ -495,22 +495,39 @@ class TestFileExhaustive < Test::Unit::T https://github.com/ruby/ruby/blob/trunk/test/ruby/test_file_exhaustive.rb#L495 assert_file.grpowned?(utf8_file) end if POSIX + def io_open(file_name) + # avoid File.open since we do not want #to_path + io = IO.for_fd(IO.sysopen(file_name)) + yield io + ensure + io&.close + end + def test_suid assert_file.not_setuid?(regular_file) assert_file.not_setuid?(utf8_file) - assert_file.setuid?(suidfile) if suidfile + if suidfile + assert_file.setuid?(suidfile) + io_open(suidfile) { |io| assert_file.setuid?(io) } + end end def test_sgid assert_file.not_setgid?(regular_file) assert_file.not_setgid?(utf8_file) - assert_file.setgid?(sgidfile) if sgidfile + if sgidfile + assert_file.setgid?(sgidfile) + io_open(sgidfile) { |io| assert_file.setgid?(io) } + end end def test_sticky assert_file.not_sticky?(regular_file) assert_file.not_sticky?(utf8_file) - assert_file.sticky?(stickyfile) if stickyfile + if stickyfile + assert_file.sticky?(stickyfile) + io_open(stickyfile) { |io| assert_file.sticky?(io) } + end end def test_path_identical_p -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/