ruby-changes:43326
From: nagachika <ko1@a...>
Date: Tue, 14 Jun 2016 03:14:37 +0900 (JST)
Subject: [ruby-changes:43326] nagachika:r55400 (ruby_2_3): merge revision(s) 54887-54889: [Backport #12340]
nagachika 2016-06-14 03:14:31 +0900 (Tue, 14 Jun 2016) New Revision: 55400 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=55400 Log: merge revision(s) 54887-54889: [Backport #12340] * win32/win32.c, include/ruby/win32.h (rb_w32_utruncate): implements new truncate alternative which accepts UTF-8 path. * file.c (truncate): use above function. [Bug #12340] Modified directories: branches/ruby_2_3/ Modified files: branches/ruby_2_3/ChangeLog branches/ruby_2_3/file.c branches/ruby_2_3/include/ruby/win32.h branches/ruby_2_3/test/ruby/test_file_exhaustive.rb branches/ruby_2_3/version.h branches/ruby_2_3/win32/win32.c Index: ruby_2_3/version.h =================================================================== --- ruby_2_3/version.h (revision 55399) +++ ruby_2_3/version.h (revision 55400) @@ -1,6 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_3/version.h#L1 #define RUBY_VERSION "2.3.2" #define RUBY_RELEASE_DATE "2016-06-14" -#define RUBY_PATCHLEVEL 124 +#define RUBY_PATCHLEVEL 125 #define RUBY_RELEASE_YEAR 2016 #define RUBY_RELEASE_MONTH 6 Index: ruby_2_3/include/ruby/win32.h =================================================================== --- ruby_2_3/include/ruby/win32.h (revision 55399) +++ ruby_2_3/include/ruby/win32.h (revision 55400) @@ -403,8 +403,9 @@ __declspec(dllimport) extern int finite( https://github.com/ruby/ruby/blob/trunk/ruby_2_3/include/ruby/win32.h#L403 #define SUFFIX -extern int rb_w32_ftruncate(int fd, off_t length); -extern int rb_w32_truncate(const char *path, off_t length); +extern int rb_w32_ftruncate(int fd, off_t length); +extern int rb_w32_truncate(const char *path, off_t length); +extern int rb_w32_utruncate(const char *path, off_t length); #undef HAVE_FTRUNCATE #define HAVE_FTRUNCATE 1 Index: ruby_2_3/ChangeLog =================================================================== --- ruby_2_3/ChangeLog (revision 55399) +++ ruby_2_3/ChangeLog (revision 55400) @@ -1,3 +1,11 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_3/ChangeLog#L1 +Tue Jun 14 03:02:38 2016 NAKAMURA Usaku <usa@r...> + + * win32/win32.c, include/ruby/win32.h (rb_w32_utruncate): implements new + truncate alternative which accepts UTF-8 path. + + * file.c (truncate): use above function. + [Bug #12340] + Tue Jun 14 02:58:41 2016 Marcus Stollsteimer <sto.mar@w...> * ext/date/date_core.c (Init_date_core): [DOC] Convert DateTime Index: ruby_2_3/test/ruby/test_file_exhaustive.rb =================================================================== --- ruby_2_3/test/ruby/test_file_exhaustive.rb (revision 55399) +++ ruby_2_3/test/ruby/test_file_exhaustive.rb (revision 55400) @@ -60,6 +60,13 @@ class TestFileExhaustive < Test::Unit::T https://github.com/ruby/ruby/blob/trunk/ruby_2_3/test/ruby/test_file_exhaustive.rb#L60 @file end + def utf8_file + return @utf8file if defined? @utf8file + @utf8file = make_tmp_filename("\u3066\u3059\u3068") + make_file("foo", @utf8file) + @utf8file + end + def notownedfile return @notownedfile if defined? @notownedfile if Process.euid != 0 @@ -168,15 +175,15 @@ class TestFileExhaustive < Test::Unit::T https://github.com/ruby/ruby/blob/trunk/ruby_2_3/test/ruby/test_file_exhaustive.rb#L175 end def test_path - file = regular_file - - assert_equal(file, File.open(file) {|f| f.path}) - assert_equal(file, File.path(file)) - o = Object.new - class << o; self; end.class_eval do - define_method(:to_path) { file } + [regular_file, utf8_file].each do |file| + assert_equal(file, File.open(file) {|f| f.path}) + assert_equal(file, File.path(file)) + o = Object.new + class << o; self; end.class_eval do + define_method(:to_path) { file } + end + assert_equal(file, File.path(o)) end - assert_equal(file, File.path(o)) end def assert_integer(n) @@ -259,12 +266,14 @@ class TestFileExhaustive < Test::Unit::T https://github.com/ruby/ruby/blob/trunk/ruby_2_3/test/ruby/test_file_exhaustive.rb#L266 assert_file.directory?(@dir) assert_file.not_directory?(@dir+"/...") assert_file.not_directory?(regular_file) + assert_file.not_directory?(utf8_file) assert_file.not_directory?(nofile) end def test_pipe_p assert_file.not_pipe?(@dir) assert_file.not_pipe?(regular_file) + assert_file.not_pipe?(utf8_file) assert_file.not_pipe?(nofile) assert_file.pipe?(fifo) if fifo end @@ -272,6 +281,7 @@ class TestFileExhaustive < Test::Unit::T https://github.com/ruby/ruby/blob/trunk/ruby_2_3/test/ruby/test_file_exhaustive.rb#L281 def test_symlink_p assert_file.not_symlink?(@dir) assert_file.not_symlink?(regular_file) + assert_file.not_symlink?(utf8_file) assert_file.symlink?(symlinkfile) if symlinkfile assert_file.not_symlink?(hardlinkfile) if hardlinkfile assert_file.not_symlink?(nofile) @@ -280,6 +290,7 @@ class TestFileExhaustive < Test::Unit::T https://github.com/ruby/ruby/blob/trunk/ruby_2_3/test/ruby/test_file_exhaustive.rb#L290 def test_socket_p assert_file.not_socket?(@dir) assert_file.not_socket?(regular_file) + assert_file.not_socket?(utf8_file) assert_file.not_socket?(nofile) assert_file.socket?(socket) if socket end @@ -287,6 +298,7 @@ class TestFileExhaustive < Test::Unit::T https://github.com/ruby/ruby/blob/trunk/ruby_2_3/test/ruby/test_file_exhaustive.rb#L298 def test_blockdev_p assert_file.not_blockdev?(@dir) assert_file.not_blockdev?(regular_file) + assert_file.not_blockdev?(utf8_file) assert_file.not_blockdev?(nofile) assert_file.blockdev?(blockdev) if blockdev end @@ -294,6 +306,7 @@ class TestFileExhaustive < Test::Unit::T https://github.com/ruby/ruby/blob/trunk/ruby_2_3/test/ruby/test_file_exhaustive.rb#L306 def test_chardev_p assert_file.not_chardev?(@dir) assert_file.not_chardev?(regular_file) + assert_file.not_chardev?(utf8_file) assert_file.not_chardev?(nofile) assert_file.chardev?(chardev) if chardev end @@ -301,6 +314,7 @@ class TestFileExhaustive < Test::Unit::T https://github.com/ruby/ruby/blob/trunk/ruby_2_3/test/ruby/test_file_exhaustive.rb#L314 def test_exist_p assert_file.exist?(@dir) assert_file.exist?(regular_file) + assert_file.exist?(utf8_file) assert_file.not_exist?(nofile) end @@ -310,6 +324,12 @@ class TestFileExhaustive < Test::Unit::T https://github.com/ruby/ruby/blob/trunk/ruby_2_3/test/ruby/test_file_exhaustive.rb#L324 assert_file.not_readable?(regular_file) File.chmod(0600, regular_file) assert_file.readable?(regular_file) + + File.chmod(0200, utf8_file) + assert_file.not_readable?(utf8_file) + File.chmod(0600, utf8_file) + assert_file.readable?(utf8_file) + assert_file.not_readable?(nofile) end if POSIX @@ -319,6 +339,12 @@ class TestFileExhaustive < Test::Unit::T https://github.com/ruby/ruby/blob/trunk/ruby_2_3/test/ruby/test_file_exhaustive.rb#L339 assert_file.not_readable_real?(regular_file) File.chmod(0600, regular_file) assert_file.readable_real?(regular_file) + + File.chmod(0200, utf8_file) + assert_file.not_readable_real?(utf8_file) + File.chmod(0600, utf8_file) + assert_file.readable_real?(utf8_file) + assert_file.not_readable_real?(nofile) end if POSIX @@ -329,6 +355,14 @@ class TestFileExhaustive < Test::Unit::T https://github.com/ruby/ruby/blob/trunk/ruby_2_3/test/ruby/test_file_exhaustive.rb#L355 assert_file.not_world_readable?(regular_file) File.chmod(0600, regular_file) assert_file.not_world_readable?(regular_file) + + File.chmod(0006, utf8_file) + assert_file.world_readable?(utf8_file) + File.chmod(0060, utf8_file) + assert_file.not_world_readable?(utf8_file) + File.chmod(0600, utf8_file) + assert_file.not_world_readable?(utf8_file) + assert_file.not_world_readable?(nofile) end if POSIX @@ -338,6 +372,12 @@ class TestFileExhaustive < Test::Unit::T https://github.com/ruby/ruby/blob/trunk/ruby_2_3/test/ruby/test_file_exhaustive.rb#L372 assert_file.not_writable?(regular_file) File.chmod(0600, regular_file) assert_file.writable?(regular_file) + + File.chmod(0400, utf8_file) + assert_file.not_writable?(utf8_file) + File.chmod(0600, utf8_file) + assert_file.writable?(utf8_file) + assert_file.not_writable?(nofile) end if POSIX @@ -347,6 +387,12 @@ class TestFileExhaustive < Test::Unit::T https://github.com/ruby/ruby/blob/trunk/ruby_2_3/test/ruby/test_file_exhaustive.rb#L387 assert_file.not_writable_real?(regular_file) File.chmod(0600, regular_file) assert_file.writable_real?(regular_file) + + File.chmod(0400, utf8_file) + assert_file.not_writable_real?(utf8_file) + File.chmod(0600, utf8_file) + assert_file.writable_real?(utf8_file) + assert_file.not_writable_real?(nofile) end if POSIX @@ -357,6 +403,14 @@ class TestFileExhaustive < Test::Unit::T https://github.com/ruby/ruby/blob/trunk/ruby_2_3/test/ruby/test_file_exhaustive.rb#L403 assert_file.not_world_writable?(regular_file) File.chmod(0600, regular_file) assert_file.not_world_writable?(regular_file) + + File.chmod(0006, utf8_file) + assert_file.world_writable?(utf8_file) + File.chmod(0060, utf8_file) + assert_file.not_world_writable?(utf8_file) + File.chmod(0600, utf8_file) + assert_file.not_world_writable?(utf8_file) + assert_file.not_world_writable?(nofile) end if POSIX @@ -365,6 +419,12 @@ class TestFileExhaustive < Test::Unit::T https://github.com/ruby/ruby/blob/trunk/ruby_2_3/test/ruby/test_file_exhaustive.rb#L419 assert_file.executable?(regular_file) File.chmod(0600, regular_file) assert_file.not_executable?(regular_file) + + File.chmod(0100, utf8_file) + assert_file.executable?(utf8_file) + File.chmod(0600, utf8_file) + assert_file.not_executable?(utf8_file) + assert_file.not_executable?(nofile) end if POSIX @@ -373,18 +433,26 @@ class TestFileExhaustive < Test::Unit::T https://github.com/ruby/ruby/blob/trunk/ruby_2_3/test/ruby/test_file_exhaustive.rb#L433 assert_file.executable_real?(regular_file) File.chmod(0600, regular_file) assert_file.not_executable_real?(regular_file) + + File.chmod(0100, utf8_file) + assert_file.executable_real?(utf8_file) + File.chmod(0600, utf8_file) + assert_file.not_executable_real?(utf8_file) + assert_file.not_executable_real?(nofile) end if POSIX def test_file_p assert_file.not_file?(@dir) assert_file.file?(regular_file) + assert_file.file?(utf8_file) assert_file.not_file?(nofile) end def test_zero_p assert_nothing_raised { File.zero?(@dir) } assert_file.not_zero?(regular_file) + assert_file.not_zero?(utf8_file) assert_file.zero?(zerofile) assert_file.not_zero?(nofile) end @@ -392,31 +460,37 @@ class TestFileExhaustive < Test::Unit::T https://github.com/ruby/ruby/blob/trunk/ruby_2_3/test/ruby/test_file_exhaustive.rb#L460 def test_size_p assert_nothing_raised { File.size?(@dir) } assert_equal(3, File.size?(regular_file)) + assert_equal(3, File.size?(utf8_file)) assert_file.not_size?(zerofile) assert_file.not_size?(nofile) end def test_owned_p assert_file.owned?(regular_file) + assert_file.owned?(utf8_file) assert_file.not_owned?(notownedfile) if notownedfile end if POSIX def test_grpowned_p ## xxx assert_file.grpowned?(regular_file) + assert_file.grpowned?(utf8_file) end if POSIX def test_suid assert_file.not_setuid?(regular_file) + assert_file.not_setuid?(utf8_file) assert_file.setuid?(suidfile) if suidfile end def test_sgid assert_file.not_setgid?(regular_file) + assert_file.not_setgid?(utf8_file) assert_file.setgid?(sgidfile) if sgidfile end def test_sticky assert_file.not_sticky?(regular_file) + assert_file.not_sticky?(utf8_file) assert_file.sticky?(stickyfile) if stickyfile end @@ -427,26 +501,40 @@ class TestFileExhaustive < Test::Unit::T https://github.com/ruby/ruby/blob/trunk/ruby_2_3/test/ruby/test_file_exhaustive.rb#L501 assert_file.not_identical?(nofile, regular_file) end + def path_identical_p(file) + [regular_file, utf8_file].each do |file| + assert_file.identical?(file, file) + assert_file.not_identical?(file, zerofile) + assert_file.not_identical?(file, nofile) + assert_file.not_identical?(nofile, file) + end + end + def test_io_identical_p - open(regular_file) {|f| - assert_file.identical?(f, f) - assert_file.identical?(regular_file, f) - assert_file.identical?(f, regular_file) - } + [regular_file, utf8_file].each do |file| + open(file) {|f| + assert_file.identical?(f, f) + assert_file.identical?(file, f) + assert_file.identical?(f, file) + } + end end def test_closed_io_identical_p - io = open(regular_file) {|f| f} - assert_raise(IOError) { - File.identical?(regular_file, io) - } - File.unlink(regular_file) - assert_file.not_exist?(regular_file) + [regular_file, utf8_file].each do |file| + io = open(file) {|f| f} + assert_raise(IOError) { + File.identical?(file, io) + } + File.unlink(file) + assert_file.not_exist?(file) + end end def test_s_size assert_integer(File.size(@dir)) assert_equal(3, File.size(regular_file)) + assert_equal(3, File.size(utf8_file)) assert_equal(0, File.size(zerofile)) assert_raise(Errno::ENOENT) { File.size(nofile) } end @@ -454,51 +542,62 @@ class TestFileExhaustive < Test::Unit::T https://github.com/ruby/ruby/blob/trunk/ruby_2_3/test/ruby/test_file_exhaustive.rb#L542 def test_ftype assert_equal("directory", File.ftype(@dir)) assert_equal("file", File.ftype(regular_file)) + assert_equal("file", File.ftype(utf8_file)) assert_equal("link", File.ftype(symlinkfile)) if symlinkfile assert_equal("file", File.ftype(hardlinkfile)) if hardlinkfile assert_raise(Errno::ENOENT) { File.ftype(nofile) } end def test_atime - t1 = File.atime(regular_file) - t2 = File.open(regular_file) {|f| f.atime} - assert_kind_of(Time, t1) - assert_kind_of(Time, t2) - assert_equal(t1, t2) + [regular_file, utf8_file].each do |file| + t1 = File.atime(file) + t2 = File.open(file) {|f| f.atime} + assert_kind_of(Time, t1) + assert_kind_of(Time, t2) + assert_equal(t1, t2) + end assert_raise(Errno::ENOENT) { File.atime(nofile) } end def test_mtime - t1 = File.mtime(regular_file) - t2 = File.open(regular_file) {|f| f.mtime} - assert_kind_of(Time, t1) - assert_kind_of(Time, t2) - assert_equal(t1, t2) + [regular_file, utf8_file].each do |file| + t1 = File.mtime(file) + t2 = File.open(file) {|f| f.mtime} + assert_kind_of(Time, t1) + assert_kind_of(Time, t2) + assert_equal(t1, t2) + end assert_raise(Errno::ENOENT) { File.mtime(nofile) } end def test_ctime - t1 = File.ctime(regular_file) - t2 = File.open(regular_file) {|f| f.ctime} - assert_kind_of(Time, t1) - assert_kind_of(Time, t2) - assert_equal(t1, t2) + [regular_file, utf8_file].each do |file| + t1 = File.ctime(file) + t2 = File.open(file) {|f| f.ctime} + assert_kind_of(Time, t1) + assert_kind_of(Time, t2) + assert_equal(t1, t2) + end assert_raise(Errno::ENOENT) { File.ctime(nofile) } end def test_chmod - assert_equal(1, File.chmod(0444, regular_file)) - assert_equal(0444, File.stat(regular_file).mode % 01000) - assert_equal(0, File.open(regular_file) {|f| f.chmod(0222)}) - assert_equal(0222, File.stat(regular_file).mode % 01000) - File.chmod(0600, regular_file) + [regular_file, utf8_file].each do |file| + assert_equal(1, File.chmod(0444, file)) + assert_equal(0444, File.stat(file).mode % 01000) + assert_equal(0, File.open(file) {|f| f.chmod(0222)}) + assert_equal(0222, File.stat(file).mode % 01000) + File.chmod(0600, file) + end assert_raise(Errno::ENOENT) { File.chmod(0600, nofile) } end if POSIX def test_lchmod - assert_equal(1, File.lchmod(0444, regular_file)) - assert_equal(0444, File.stat(regular_file).mode % 01000) - File.lchmod(0600, regular_file) + [regular_file, utf8_file].each do |file| + assert_equal(1, File.lchmod(0444, file)) + assert_equal(0444, File.stat(file).mode % 01000) + File.lchmod(0600, regular_file) + end assert_raise(Errno::ENOENT) { File.lchmod(0600, nofile) } rescue NotImplementedError end if POSIX @@ -513,6 +612,7 @@ class TestFileExhaustive < Test::Unit::T https://github.com/ruby/ruby/blob/trunk/ruby_2_3/test/ruby/test_file_exhaustive.rb#L612 return unless symlinkfile assert_equal("link", File.ftype(symlinkfile)) assert_raise(Errno::EEXIST) { File.symlink(regular_file, regular_file) } + assert_raise(Errno::EEXIST) { File.symlink(utf8_file, utf8_file) } end def test_utime @@ -526,12 +626,14 @@ class TestFileExhaustive < Test::Unit::T https://github.com/ruby/ruby/blob/trunk/ruby_2_3/test/ruby/test_file_exhaustive.rb#L626 return unless hardlinkfile assert_equal("file", File.ftype(hardlinkfile)) assert_raise(Errno::EEXIST) { File.link(regular_file, regular_file) } + assert_raise(Errno::EEXIST) { File.link(utf8_file, utf8_file) } end def test_readlink return unless symlinkfile assert_equal(regular_file, File.readlink(symlinkfile)) assert_raise(Errno::EINVAL) { File.readlink(regular_file) } + assert_raise(Errno::EINVAL) { File.readlink(utf8_file) } assert_raise(Errno::ENOENT) { File.readlink(nofile) } if fs = Encoding.find("filesystem") assert_equal(fs, File.readlink(symlinkfile).encoding) @@ -578,15 +680,21 @@ class TestFileExhaustive < Test::Unit::T https://github.com/ruby/ruby/blob/trunk/ruby_2_3/test/ruby/test_file_exhaustive.rb#L680 def test_unlink assert_equal(1, File.unlink(regular_file)) make_file("foo", regular_file) + + assert_equal(1, File.unlink(utf8_file)) + make_file("foo", utf8_file) + assert_raise(Errno::ENOENT) { File.unlink(nofile) } end def test_rename - assert_equal(0, File.rename(regular_file, nofile)) - assert_file.not_exist?(regular_file) - assert_file.exist?(nofile) - assert_equal(0, File.rename(nofile, regular_file)) - assert_raise(Errno::ENOENT) { File.rename(nofile, regular_file) } + [regular_file, utf8_file].each do |file| + assert_equal(0, File.rename(file, nofile)) + assert_file.not_exist?(file) + assert_file.exist?(nofile) + assert_equal(0, File.rename(nofile, file)) + assert_raise(Errno::ENOENT) { File.rename(nofile, file) } + end end def test_umask @@ -601,10 +709,13 @@ class TestFileExhaustive < Test::Unit::T https://github.com/ruby/ruby/blob/trunk/ruby_2_3/test/ruby/test_file_exhaustive.rb#L709 def test_expand_path assert_equal(regular_file, File.expand_path(File.basename(regular_file), File.dirname(regular_file))) + assert_equal(utf8_file, File.expand_path(File.basename(utf8_file), File.dirname(utf8_file))) if NTFS - assert_equal(regular_file, File.expand_path(regular_file + " ")) - assert_equal(regular_file, File.expand_path(regular_file + ".")) - assert_equal(regular_file, File.expand_path(regular_file + "::$DATA")) + [regular_file, utf8_file].each do |file| + assert_equal(file, File.expand_path(file + " ")) + assert_equal(file, File.expand_path(file + ".")) + assert_equal(file, File.expand_path(file + "::$DATA")) + end assert_match(/\Ac:\//i, File.expand_path('c:'), '[ruby-core:31591]') assert_match(/\Ac:\//i, File.expand_path('c:foo', 'd:/bar')) assert_match(/\Ae:\//i, File.expand_path('e:foo', 'd:/bar')) @@ -966,6 +1077,7 @@ class TestFileExhaustive < Test::Unit::T https://github.com/ruby/ruby/blob/trunk/ruby_2_3/test/ruby/test_file_exhaustive.rb#L1077 def test_basename assert_equal(File.basename(regular_file).sub(/\.test$/, ""), File.basename(regular_file, ".test")) + assert_equal(File.basename(utf8_file).sub(/\.test$/, ""), File.basename(utf8_file, ".test")) assert_equal("", s = File.basename("")) assert_not_predicate(s, :frozen?, '[ruby-core:24199]') assert_equal("foo", s = File.basename("foo")) @@ -974,17 +1086,19 @@ class TestFileExhaustive < Test::Unit (... truncated) -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/