summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoraamine <aamine@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-12-01 05:18:46 +0000
committeraamine <aamine@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-12-01 05:18:46 +0000
commite5690fcd6dd932b3cf28ebc42f6b42498e161e97 (patch)
tree2c0598ed28b3fc4c6fa690c4a8a98652e7489ed0
parentd8d81b35a43655a9009b1e7a11e22d28ef3ead2d (diff)
* 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
-rw-r--r--ChangeLog8
-rw-r--r--lib/fileutils.rb6
-rw-r--r--test/fileutils/test_fileutils.rb55
3 files changed, 51 insertions, 18 deletions
diff --git a/ChangeLog b/ChangeLog
index f55ad9aeac..33ed913651 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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
diff --git a/lib/fileutils.rb b/lib/fileutils.rb
index ee62f5838b..e71ac864d4 100644
--- a/lib/fileutils.rb
+++ b/lib/fileutils.rb
@@ -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
diff --git a/test/fileutils/test_fileutils.rb b/test/fileutils/test_fileutils.rb
index 9fb0991752..8b759cc596 100644
--- a/test/fileutils/test_fileutils.rb
+++ b/test/fileutils/test_fileutils.rb
@@ -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'
+ # src==dest (2) symlink and its target
+ File.symlink 'cptmp', 'tmp/symlink'
assert_raises(Errno::EEXIST) {
- ln 'tmp/cptmp', 'tmp/cptmp_symlink'
+ ln 'tmp/cptmp', 'tmp/symlink' # normal file -> symlink
}
- File.symlink 'cptmp', 'tmp/symlink'
assert_raises(Errno::EEXIST) {
- ln 'tmp/symlink', 'tmp/symlink'
+ 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