mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
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] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_3@55400 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
805e78248f
commit
85ca853a50
6 changed files with 251 additions and 92 deletions
|
@ -1,3 +1,11 @@
|
|||
Tue Jun 14 03:02:38 2016 NAKAMURA Usaku <usa@ruby-lang.org>
|
||||
|
||||
* 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@web.de>
|
||||
|
||||
* ext/date/date_core.c (Init_date_core): [DOC] Convert DateTime
|
||||
|
|
2
file.c
2
file.c
|
@ -100,6 +100,8 @@ int flock(int, int);
|
|||
#define lstat(p, s) rb_w32_ulstati64((p), (s))
|
||||
#undef access
|
||||
#define access(p, m) rb_w32_uaccess((p), (m))
|
||||
#undef truncate
|
||||
#define truncate(p, n) rb_w32_utruncate((p), (n))
|
||||
#undef chmod
|
||||
#define chmod(p, m) rb_w32_uchmod((p), (m))
|
||||
#undef chown
|
||||
|
|
|
@ -403,8 +403,9 @@ __declspec(dllimport) extern int finite(double);
|
|||
|
||||
#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
|
||||
|
|
|
@ -60,6 +60,13 @@ class TestFileExhaustive < Test::Unit::TestCase
|
|||
@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::TestCase
|
|||
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::TestCase
|
|||
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::TestCase
|
|||
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::TestCase
|
|||
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::TestCase
|
|||
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::TestCase
|
|||
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::TestCase
|
|||
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::TestCase
|
|||
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::TestCase
|
|||
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::TestCase
|
|||
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::TestCase
|
|||
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::TestCase
|
|||
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::TestCase
|
|||
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::TestCase
|
|||
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::TestCase
|
|||
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::TestCase
|
|||
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::TestCase
|
|||
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::TestCase
|
|||
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::TestCase
|
|||
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::TestCase
|
|||
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::TestCase
|
|||
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::TestCase
|
|||
|
||||
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::TestCase
|
|||
|
||||
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::TestCase
|
|||
assert_equal("foo", File.basename("foo.ext", ".ext"))
|
||||
assert_equal("foo", File.basename("foo.ext", ".*"))
|
||||
if NTFS
|
||||
basename = File.basename(regular_file)
|
||||
assert_equal(basename, File.basename(regular_file + " "))
|
||||
assert_equal(basename, File.basename(regular_file + "."))
|
||||
assert_equal(basename, File.basename(regular_file + "::$DATA"))
|
||||
basename.chomp!(".test")
|
||||
assert_equal(basename, File.basename(regular_file + " ", ".test"))
|
||||
assert_equal(basename, File.basename(regular_file + ".", ".test"))
|
||||
assert_equal(basename, File.basename(regular_file + "::$DATA", ".test"))
|
||||
assert_equal(basename, File.basename(regular_file + " ", ".*"))
|
||||
assert_equal(basename, File.basename(regular_file + ".", ".*"))
|
||||
assert_equal(basename, File.basename(regular_file + "::$DATA", ".*"))
|
||||
[regular_file, utf8_file].each do |file|
|
||||
basename = File.basename(file)
|
||||
assert_equal(basename, File.basename(file + " "))
|
||||
assert_equal(basename, File.basename(file + "."))
|
||||
assert_equal(basename, File.basename(file + "::$DATA"))
|
||||
basename.chomp!(".test")
|
||||
assert_equal(basename, File.basename(file + " ", ".test"))
|
||||
assert_equal(basename, File.basename(file + ".", ".test"))
|
||||
assert_equal(basename, File.basename(file + "::$DATA", ".test"))
|
||||
assert_equal(basename, File.basename(file + " ", ".*"))
|
||||
assert_equal(basename, File.basename(file + ".", ".*"))
|
||||
assert_equal(basename, File.basename(file + "::$DATA", ".*"))
|
||||
end
|
||||
end
|
||||
if File::ALT_SEPARATOR == '\\'
|
||||
a = "foo/\225\\\\"
|
||||
|
@ -1006,6 +1120,7 @@ class TestFileExhaustive < Test::Unit::TestCase
|
|||
|
||||
def test_dirname
|
||||
assert(regular_file.start_with?(File.dirname(regular_file)))
|
||||
assert_equal(@dir, File.dirname(utf8_file))
|
||||
assert_equal(".", File.dirname(""))
|
||||
assert_incompatible_encoding {|d| File.dirname(d)}
|
||||
if File::ALT_SEPARATOR == '\\'
|
||||
|
@ -1018,6 +1133,7 @@ class TestFileExhaustive < Test::Unit::TestCase
|
|||
|
||||
def test_extname
|
||||
assert_equal(".test", File.extname(regular_file))
|
||||
assert_equal(".test", File.extname(utf8_file))
|
||||
prefixes = ["", "/", ".", "/.", "bar/.", "/bar/."]
|
||||
infixes = ["", " ", "."]
|
||||
infixes2 = infixes + [".ext "]
|
||||
|
@ -1044,9 +1160,11 @@ class TestFileExhaustive < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
def test_split
|
||||
d, b = File.split(regular_file)
|
||||
assert_equal(File.dirname(regular_file), d)
|
||||
assert_equal(File.basename(regular_file), b)
|
||||
[regular_file, utf8_file].each do |file|
|
||||
d, b = File.split(file)
|
||||
assert_equal(File.dirname(file), d)
|
||||
assert_equal(File.basename(file), b)
|
||||
end
|
||||
end
|
||||
|
||||
def test_join
|
||||
|
@ -1089,26 +1207,28 @@ class TestFileExhaustive < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
def test_truncate
|
||||
assert_equal(0, File.truncate(regular_file, 1))
|
||||
assert_file.exist?(regular_file)
|
||||
assert_equal(1, File.size(regular_file))
|
||||
assert_equal(0, File.truncate(regular_file, 0))
|
||||
assert_file.exist?(regular_file)
|
||||
assert_file.zero?(regular_file)
|
||||
make_file("foo", regular_file)
|
||||
assert_raise(Errno::ENOENT) { File.truncate(nofile, 0) }
|
||||
[regular_file, utf8_file].each do |file|
|
||||
assert_equal(0, File.truncate(file, 1))
|
||||
assert_file.exist?(file)
|
||||
assert_equal(1, File.size(file))
|
||||
assert_equal(0, File.truncate(file, 0))
|
||||
assert_file.exist?(file)
|
||||
assert_file.zero?(file)
|
||||
make_file("foo", file)
|
||||
assert_raise(Errno::ENOENT) { File.truncate(nofile, 0) }
|
||||
|
||||
f = File.new(regular_file, "w")
|
||||
assert_equal(0, f.truncate(2))
|
||||
assert_file.exist?(regular_file)
|
||||
assert_equal(2, File.size(regular_file))
|
||||
assert_equal(0, f.truncate(0))
|
||||
assert_file.exist?(regular_file)
|
||||
assert_file.zero?(regular_file)
|
||||
f.close
|
||||
make_file("foo", regular_file)
|
||||
f = File.new(file, "w")
|
||||
assert_equal(0, f.truncate(2))
|
||||
assert_file.exist?(file)
|
||||
assert_equal(2, File.size(file))
|
||||
assert_equal(0, f.truncate(0))
|
||||
assert_file.exist?(file)
|
||||
assert_file.zero?(file)
|
||||
f.close
|
||||
make_file("foo", file)
|
||||
|
||||
assert_raise(IOError) { File.open(regular_file) {|ff| ff.truncate(0)} }
|
||||
assert_raise(IOError) { File.open(file) {|ff| ff.truncate(0)} }
|
||||
end
|
||||
rescue NotImplementedError
|
||||
end
|
||||
|
||||
|
@ -1228,6 +1348,12 @@ class TestFileExhaustive < Test::Unit::TestCase
|
|||
end
|
||||
end
|
||||
|
||||
def test_stat_new_utf8
|
||||
assert_nothing_raised do
|
||||
File::Stat.new(utf8_file)
|
||||
end
|
||||
end
|
||||
|
||||
def test_stat_ftype
|
||||
assert_equal("directory", File::Stat.new(@dir).ftype)
|
||||
assert_equal("file", File::Stat.new(regular_file).ftype)
|
||||
|
@ -1400,10 +1526,12 @@ class TestFileExhaustive < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
def test_size
|
||||
assert_equal(3, File.open(regular_file) {|f| f.size })
|
||||
File.open(regular_file, "a") do |f|
|
||||
f.write("bar")
|
||||
assert_equal(6, f.size)
|
||||
[regular_file, utf8_file].each do |file|
|
||||
assert_equal(3, File.open(file) {|f| f.size })
|
||||
File.open(file, "a") do |f|
|
||||
f.write("bar")
|
||||
assert_equal(6, f.size)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#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
|
||||
|
|
|
@ -5709,21 +5709,41 @@ rb_chsize(HANDLE h, off_t size)
|
|||
}
|
||||
|
||||
/* License: Ruby's */
|
||||
int
|
||||
rb_w32_truncate(const char *path, off_t length)
|
||||
static int
|
||||
w32_truncate(const char *path, off_t length, UINT cp)
|
||||
{
|
||||
HANDLE h;
|
||||
int ret;
|
||||
h = CreateFile(path, GENERIC_WRITE, 0, 0, OPEN_EXISTING, 0, 0);
|
||||
WCHAR *wpath;
|
||||
|
||||
if (!(wpath = mbstr_to_wstr(cp, path, -1, NULL)))
|
||||
return -1;
|
||||
h = CreateFileW(wpath, GENERIC_WRITE, 0, 0, OPEN_EXISTING, 0, 0);
|
||||
if (h == INVALID_HANDLE_VALUE) {
|
||||
errno = map_errno(GetLastError());
|
||||
free(wpath);
|
||||
return -1;
|
||||
}
|
||||
free(wpath);
|
||||
ret = rb_chsize(h, length);
|
||||
CloseHandle(h);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* License: Ruby's */
|
||||
int
|
||||
rb_w32_utruncate(const char *path, off_t length)
|
||||
{
|
||||
return w32_truncate(path, length, CP_UTF8);
|
||||
}
|
||||
|
||||
/* License: Ruby's */
|
||||
int
|
||||
rb_w32_truncate(const char *path, off_t length)
|
||||
{
|
||||
return w32_truncate(path, length, filecp());
|
||||
}
|
||||
|
||||
/* License: Ruby's */
|
||||
int
|
||||
rb_w32_ftruncate(int fd, off_t length)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue