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:
parent
d8d81b35a4
commit
e5690fcd6d
3 changed files with 52 additions and 19 deletions
|
@ -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>
|
Mon Dec 1 09:28:14 2003 NAKAMURA Usaku <usa@ruby-lang.org>
|
||||||
|
|
||||||
* bcc32/Makefile.sub, win32/Makefile.sub, wince/Makefile.sub
|
* bcc32/Makefile.sub, win32/Makefile.sub, wince/Makefile.sub
|
||||||
|
|
|
@ -719,12 +719,12 @@ module FileUtils
|
||||||
|
|
||||||
def fu_each_src_dest0( src, dest )
|
def fu_each_src_dest0( src, dest )
|
||||||
unless src.is_a?(Array)
|
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
|
else
|
||||||
dir = dest
|
dir = dest.to_str
|
||||||
#raise ArgumentError, "not a directory: #{dir}" unless File.directory?(dir)
|
#raise ArgumentError, "not a directory: #{dir}" unless File.directory?(dir)
|
||||||
dir += (dir[-1,1] == '/') ? '' : '/'
|
dir += (dir[-1,1] == '/') ? '' : '/'
|
||||||
src.each do |fname|
|
src.map {|s| s.to_str }.each do |fname|
|
||||||
yield fname, dir + File.basename(fname)
|
yield fname, dir + File.basename(fname)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -9,9 +9,8 @@ require 'fileasserts'
|
||||||
require 'tmpdir'
|
require 'tmpdir'
|
||||||
require 'test/unit'
|
require 'test/unit'
|
||||||
|
|
||||||
|
|
||||||
def have_drive_letter?
|
def have_drive_letter?
|
||||||
/djgpp|mswin|mingw|bcc|wince|emx/ === RUBY_PLATFORM
|
/djgpp|mswin(?!ce)|mingw|bcc|emx/ === RUBY_PLATFORM
|
||||||
end
|
end
|
||||||
|
|
||||||
def have_file_perm?
|
def have_file_perm?
|
||||||
|
@ -30,6 +29,12 @@ def have_symlink?
|
||||||
HAVE_SYMLINK
|
HAVE_SYMLINK
|
||||||
end
|
end
|
||||||
|
|
||||||
|
case RUBY_PLATFORM
|
||||||
|
when /openbsd/, /freebsd/
|
||||||
|
ErrorOnLoopedSymlink = Errno::ELOOP
|
||||||
|
when /linux/, /netbsd/, /cygwin/, // # FIXME
|
||||||
|
ErrorOnLoopedSymlink = Errno::EEXIST
|
||||||
|
end
|
||||||
|
|
||||||
class TestFileUtils < Test::Unit::TestCase
|
class TestFileUtils < Test::Unit::TestCase
|
||||||
|
|
||||||
|
@ -109,7 +114,6 @@ class TestFileUtils < Test::Unit::TestCase
|
||||||
File.utime t-4, t-4, 'data/newer'
|
File.utime t-4, t-4, 'data/newer'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
def test_pwd
|
def test_pwd
|
||||||
assert_equal Dir.pwd, pwd()
|
assert_equal Dir.pwd, pwd()
|
||||||
|
|
||||||
|
@ -154,16 +158,21 @@ end
|
||||||
assert_equal a.gid, b.gid
|
assert_equal a.gid, b.gid
|
||||||
end
|
end
|
||||||
|
|
||||||
# src==dest
|
# src==dest (1) same path
|
||||||
touch 'tmp/cptmp'
|
touch 'tmp/cptmp'
|
||||||
assert_raises(ArgumentError) {
|
assert_raises(ArgumentError) {
|
||||||
cp 'tmp/cptmp', 'tmp/cptmp'
|
cp 'tmp/cptmp', 'tmp/cptmp'
|
||||||
}
|
}
|
||||||
if have_symlink?
|
if have_symlink?
|
||||||
|
# src==dest (2) symlink and its target
|
||||||
File.symlink 'cptmp', 'tmp/cptmp_symlink'
|
File.symlink 'cptmp', 'tmp/cptmp_symlink'
|
||||||
assert_raises(ArgumentError) {
|
assert_raises(ArgumentError) {
|
||||||
cp 'tmp/cptmp', 'tmp/cptmp_symlink'
|
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'
|
File.symlink 'symlink', 'tmp/symlink'
|
||||||
assert_raises(Errno::ELOOP) {
|
assert_raises(Errno::ELOOP) {
|
||||||
cp 'tmp/symlink', 'tmp/symlink'
|
cp 'tmp/symlink', 'tmp/symlink'
|
||||||
|
@ -185,16 +194,21 @@ end
|
||||||
assert_same_file fname, 'tmp/mvdest'
|
assert_same_file fname, 'tmp/mvdest'
|
||||||
end
|
end
|
||||||
|
|
||||||
# src==dest
|
# src==dest (1) same path
|
||||||
touch 'tmp/cptmp'
|
touch 'tmp/cptmp'
|
||||||
assert_raises(ArgumentError) {
|
assert_raises(ArgumentError) {
|
||||||
mv 'tmp/cptmp', 'tmp/cptmp'
|
mv 'tmp/cptmp', 'tmp/cptmp'
|
||||||
}
|
}
|
||||||
if have_symlink?
|
if have_symlink?
|
||||||
|
# src==dest (2) symlink and its target
|
||||||
File.symlink 'cptmp', 'tmp/cptmp_symlink'
|
File.symlink 'cptmp', 'tmp/cptmp_symlink'
|
||||||
assert_raises(ArgumentError) {
|
assert_raises(ArgumentError) {
|
||||||
mv 'tmp/cptmp', 'tmp/cptmp_symlink'
|
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'
|
File.symlink 'symlink', 'tmp/symlink'
|
||||||
assert_raises(Errno::ELOOP) {
|
assert_raises(Errno::ELOOP) {
|
||||||
mv 'tmp/symlink', 'tmp/symlink'
|
mv 'tmp/symlink', 'tmp/symlink'
|
||||||
|
@ -293,19 +307,24 @@ end
|
||||||
File.unlink 'tmp/' + File.basename(fname)
|
File.unlink 'tmp/' + File.basename(fname)
|
||||||
end
|
end
|
||||||
|
|
||||||
# src==dest
|
# src==dest (1) same path
|
||||||
touch 'tmp/cptmp'
|
touch 'tmp/cptmp'
|
||||||
assert_raises(Errno::EEXIST) {
|
assert_raises(Errno::EEXIST) {
|
||||||
ln 'tmp/cptmp', 'tmp/cptmp'
|
ln 'tmp/cptmp', 'tmp/cptmp'
|
||||||
}
|
}
|
||||||
if have_symlink?
|
if have_symlink?
|
||||||
File.symlink 'tmp/cptmp', 'tmp/cptmp_symlink'
|
# src==dest (2) symlink and its target
|
||||||
assert_raises(Errno::EEXIST) {
|
|
||||||
ln 'tmp/cptmp', 'tmp/cptmp_symlink'
|
|
||||||
}
|
|
||||||
File.symlink 'cptmp', 'tmp/symlink'
|
File.symlink 'cptmp', 'tmp/symlink'
|
||||||
assert_raises(Errno::EEXIST) {
|
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
|
||||||
end
|
end
|
||||||
|
@ -319,7 +338,7 @@ if have_symlink?
|
||||||
rm_f 'tmp/lnsdest'
|
rm_f 'tmp/lnsdest'
|
||||||
end
|
end
|
||||||
assert_nothing_raised {
|
assert_nothing_raised {
|
||||||
ln_s 'tmp/symlink', 'tmp/symlink'
|
ln_s 'symlink', 'tmp/symlink'
|
||||||
}
|
}
|
||||||
assert_symlink 'tmp/symlink'
|
assert_symlink 'tmp/symlink'
|
||||||
end
|
end
|
||||||
|
@ -334,6 +353,9 @@ if have_symlink?
|
||||||
ln_sf fname, 'tmp/lnsdest'
|
ln_sf fname, 'tmp/lnsdest'
|
||||||
ln_sf fname, 'tmp/lnsdest'
|
ln_sf fname, 'tmp/lnsdest'
|
||||||
end
|
end
|
||||||
|
assert_nothing_raised {
|
||||||
|
ln_sf 'symlink', 'tmp/symlink'
|
||||||
|
}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -390,9 +412,6 @@ end
|
||||||
rm_rf 'tmp/tmp'
|
rm_rf 'tmp/tmp'
|
||||||
end
|
end
|
||||||
|
|
||||||
def try_mkdirp( dirs, del )
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_uptodate?
|
def test_uptodate?
|
||||||
Dir.chdir('data') {
|
Dir.chdir('data') {
|
||||||
assert( uptodate?('newest', %w(old newer notexist)) )
|
assert( uptodate?('newest', %w(old newer notexist)) )
|
||||||
|
@ -417,18 +436,24 @@ end
|
||||||
File.unlink 'tmp/aaa'
|
File.unlink 'tmp/aaa'
|
||||||
File.unlink 'tmp/bbb'
|
File.unlink 'tmp/bbb'
|
||||||
|
|
||||||
# src==dest
|
# src==dest (1) same path
|
||||||
touch 'tmp/cptmp'
|
touch 'tmp/cptmp'
|
||||||
assert_raises(ArgumentError) {
|
assert_raises(ArgumentError) {
|
||||||
install 'tmp/cptmp', 'tmp/cptmp'
|
install 'tmp/cptmp', 'tmp/cptmp'
|
||||||
}
|
}
|
||||||
if have_symlink?
|
if have_symlink?
|
||||||
|
# src==dest (2) symlink and its target
|
||||||
File.symlink 'cptmp', 'tmp/cptmp_symlink'
|
File.symlink 'cptmp', 'tmp/cptmp_symlink'
|
||||||
assert_raises(ArgumentError) {
|
assert_raises(ArgumentError) {
|
||||||
install 'tmp/cptmp', 'tmp/cptmp_symlink'
|
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'
|
File.symlink 'symlink', 'tmp/symlink'
|
||||||
assert_raises(Errno::ELOOP) {
|
assert_raises(Errno::ELOOP) {
|
||||||
|
# File#install invokes open(2), always ELOOP must be raised
|
||||||
install 'tmp/symlink', 'tmp/symlink'
|
install 'tmp/symlink', 'tmp/symlink'
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue