Skip to content
This repository has been archived by the owner on Sep 17, 2021. It is now read-only.

Commit

Permalink
* lib/fileutils.rb (fu_each_src_dest0): call #to_str to allow Pathnam…
Browse files Browse the repository at this point in the history
…e 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
  • Loading branch information
aamine committed Dec 1, 2003
1 parent d8d81b3 commit e5690fc
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 18 deletions.
8 changes: 8 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
Mon Dec 1 14:17:49 2003 Minero Aoki <[email protected]>

* 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 <[email protected]>

* bcc32/Makefile.sub, win32/Makefile.sub, wince/Makefile.sub
Expand Down
6 changes: 3 additions & 3 deletions lib/fileutils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -719,12 +719,12 @@ def fu_each_src_dest( src, dest )

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
Expand Down
55 changes: 40 additions & 15 deletions test/fileutils/test_fileutils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@
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?
Expand All @@ -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

Expand Down Expand Up @@ -109,7 +114,6 @@ def prepare_time_data
File.utime t-4, t-4, 'data/newer'
end


def test_pwd
assert_equal Dir.pwd, pwd()

Expand Down Expand Up @@ -154,16 +158,21 @@ def test_cp
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'
Expand All @@ -185,16 +194,21 @@ def test_mv
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'
Expand Down Expand Up @@ -293,19 +307,24 @@ def test_ln
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
Expand All @@ -319,7 +338,7 @@ def test_ln_s
rm_f 'tmp/lnsdest'
end
assert_nothing_raised {
ln_s 'tmp/symlink', 'tmp/symlink'
ln_s 'symlink', 'tmp/symlink'
}
assert_symlink 'tmp/symlink'
end
Expand All @@ -334,6 +353,9 @@ def test_ln_sf
ln_sf fname, 'tmp/lnsdest'
ln_sf fname, 'tmp/lnsdest'
end
assert_nothing_raised {
ln_sf 'symlink', 'tmp/symlink'
}
end
end

Expand Down Expand Up @@ -390,9 +412,6 @@ def test_mkdir_p
rm_rf 'tmp/tmp'
end

def try_mkdirp( dirs, del )
end

def test_uptodate?
Dir.chdir('data') {
assert( uptodate?('newest', %w(old newer notexist)) )
Expand All @@ -417,18 +436,24 @@ def test_install
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
Expand Down

0 comments on commit e5690fc

Please sign in to comment.