1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* lib/fileutils.rb (fu_each_src_dest0): call #to_str to allow Pathname for arguments. [ruby-core:01795]

* test/fileutils/test_fileutils.rb: does much strict test on "same" files detecting.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@5071 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
aamine 2003-12-01 05:18:46 +00:00
parent d8d81b35a4
commit e5690fcd6d
3 changed files with 52 additions and 19 deletions

View file

@ -1,3 +1,11 @@
Mon Dec 1 14:17:49 2003 Minero Aoki <aamine@loveruby.net>
* lib/fileutils.rb (fu_each_src_dest0): call #to_str to allow
Pathname for arguments. [ruby-core:01795]
* test/fileutils/test_fileutils.rb: does much strict test on
"same" files detecting.
Mon Dec 1 09:28:14 2003 NAKAMURA Usaku <usa@ruby-lang.org>
* bcc32/Makefile.sub, win32/Makefile.sub, wince/Makefile.sub

View file

@ -719,12 +719,12 @@ module FileUtils
def fu_each_src_dest0( src, dest )
unless src.is_a?(Array)
yield src, fu_dest_filename(src, dest)
yield src.to_str, fu_dest_filename(src.to_str, dest.to_str)
else
dir = dest
dir = dest.to_str
#raise ArgumentError, "not a directory: #{dir}" unless File.directory?(dir)
dir += (dir[-1,1] == '/') ? '' : '/'
src.each do |fname|
src.map {|s| s.to_str }.each do |fname|
yield fname, dir + File.basename(fname)
end
end

View file

@ -9,9 +9,8 @@ require 'fileasserts'
require 'tmpdir'
require 'test/unit'
def have_drive_letter?
/djgpp|mswin|mingw|bcc|wince|emx/ === RUBY_PLATFORM
/djgpp|mswin(?!ce)|mingw|bcc|emx/ === RUBY_PLATFORM
end
def have_file_perm?
@ -30,6 +29,12 @@ def have_symlink?
HAVE_SYMLINK
end
case RUBY_PLATFORM
when /openbsd/, /freebsd/
ErrorOnLoopedSymlink = Errno::ELOOP
when /linux/, /netbsd/, /cygwin/, // # FIXME
ErrorOnLoopedSymlink = Errno::EEXIST
end
class TestFileUtils < Test::Unit::TestCase
@ -109,7 +114,6 @@ class TestFileUtils < Test::Unit::TestCase
File.utime t-4, t-4, 'data/newer'
end
def test_pwd
assert_equal Dir.pwd, pwd()
@ -154,16 +158,21 @@ end
assert_equal a.gid, b.gid
end
# src==dest
# src==dest (1) same path
touch 'tmp/cptmp'
assert_raises(ArgumentError) {
cp 'tmp/cptmp', 'tmp/cptmp'
}
if have_symlink?
# src==dest (2) symlink and its target
File.symlink 'cptmp', 'tmp/cptmp_symlink'
assert_raises(ArgumentError) {
cp 'tmp/cptmp', 'tmp/cptmp_symlink'
}
assert_raises(ArgumentError) {
cp 'tmp/cptmp_symlink', 'tmp/cptmp'
}
# src==dest (3) looped symlink
File.symlink 'symlink', 'tmp/symlink'
assert_raises(Errno::ELOOP) {
cp 'tmp/symlink', 'tmp/symlink'
@ -185,16 +194,21 @@ end
assert_same_file fname, 'tmp/mvdest'
end
# src==dest
# src==dest (1) same path
touch 'tmp/cptmp'
assert_raises(ArgumentError) {
mv 'tmp/cptmp', 'tmp/cptmp'
}
if have_symlink?
# src==dest (2) symlink and its target
File.symlink 'cptmp', 'tmp/cptmp_symlink'
assert_raises(ArgumentError) {
mv 'tmp/cptmp', 'tmp/cptmp_symlink'
}
assert_raises(ArgumentError) {
mv 'tmp/cptmp_symlink', 'tmp/cptmp'
}
# src==dest (3) looped symlink
File.symlink 'symlink', 'tmp/symlink'
assert_raises(Errno::ELOOP) {
mv 'tmp/symlink', 'tmp/symlink'
@ -293,19 +307,24 @@ end
File.unlink 'tmp/' + File.basename(fname)
end
# src==dest
# src==dest (1) same path
touch 'tmp/cptmp'
assert_raises(Errno::EEXIST) {
ln 'tmp/cptmp', 'tmp/cptmp'
}
if have_symlink?
File.symlink 'tmp/cptmp', 'tmp/cptmp_symlink'
assert_raises(Errno::EEXIST) {
ln 'tmp/cptmp', 'tmp/cptmp_symlink'
}
# src==dest (2) symlink and its target
File.symlink 'cptmp', 'tmp/symlink'
assert_raises(Errno::EEXIST) {
ln 'tmp/symlink', 'tmp/symlink'
ln 'tmp/cptmp', 'tmp/symlink' # normal file -> symlink
}
assert_raises(Errno::EEXIST) {
ln 'tmp/symlink', 'tmp/cptmp' # symlink -> normal file
}
# src==dest (3) looped symlink
File.symlink 'cptmp_symlink', 'tmp/cptmp_symlink'
assert_raises(ErrorOnLoopedSymlink) {
ln 'tmp/cptmp_symlink', 'tmp/cptmp_symlink'
}
end
end
@ -319,7 +338,7 @@ if have_symlink?
rm_f 'tmp/lnsdest'
end
assert_nothing_raised {
ln_s 'tmp/symlink', 'tmp/symlink'
ln_s 'symlink', 'tmp/symlink'
}
assert_symlink 'tmp/symlink'
end
@ -334,6 +353,9 @@ if have_symlink?
ln_sf fname, 'tmp/lnsdest'
ln_sf fname, 'tmp/lnsdest'
end
assert_nothing_raised {
ln_sf 'symlink', 'tmp/symlink'
}
end
end
@ -390,9 +412,6 @@ end
rm_rf 'tmp/tmp'
end
def try_mkdirp( dirs, del )
end
def test_uptodate?
Dir.chdir('data') {
assert( uptodate?('newest', %w(old newer notexist)) )
@ -417,18 +436,24 @@ end
File.unlink 'tmp/aaa'
File.unlink 'tmp/bbb'
# src==dest
# src==dest (1) same path
touch 'tmp/cptmp'
assert_raises(ArgumentError) {
install 'tmp/cptmp', 'tmp/cptmp'
}
if have_symlink?
# src==dest (2) symlink and its target
File.symlink 'cptmp', 'tmp/cptmp_symlink'
assert_raises(ArgumentError) {
install 'tmp/cptmp', 'tmp/cptmp_symlink'
}
assert_raises(ArgumentError) {
install 'tmp/cptmp_symlink', 'tmp/cptmp'
}
# src==dest (3) looped symlink
File.symlink 'symlink', 'tmp/symlink'
assert_raises(Errno::ELOOP) {
# File#install invokes open(2), always ELOOP must be raised
install 'tmp/symlink', 'tmp/symlink'
}
end