diff options
author | aamine <aamine@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2003-12-12 10:33:24 +0000 |
---|---|---|
committer | aamine <aamine@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2003-12-12 10:33:24 +0000 |
commit | 232b4c20735aad320554d609b71c7a911c991abe (patch) | |
tree | 88b94ac40885cf2e3048b50225c5a303cf47bb85 | |
parent | 6de4020c3069c68d954078d80e8f60c8ebaf9e94 (diff) | |
download | ruby-232b4c20735aad320554d609b71c7a911c991abe.tar.gz |
* lib/fileutils.rb (mkdir): remove trailing `/' from pathes.
* lib/fileutils.rb (rmdir): ditto. [ruby-dev:22238]
* lib/fileutils.rb (rmdir_r): ditto.
* lib/fileutils.rb (fu_copy_dir): check if it is a directory after mkdir(2).
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@5176 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 11 | ||||
-rw-r--r-- | lib/fileutils.rb | 53 | ||||
-rw-r--r-- | test/fileutils/test_fileutils.rb | 19 |
3 files changed, 53 insertions, 30 deletions
@@ -1,3 +1,14 @@ +Fri Dec 12 19:33:06 2003 Minero Aoki <aamine@loveruby.net> + + * lib/fileutils.rb (mkdir): remove trailing `/' from pathes. + + * lib/fileutils.rb (rmdir): ditto. [ruby-dev:22238] + + * lib/fileutils.rb (rmdir_r): ditto. + + * lib/fileutils.rb (fu_copy_dir): check if it is a directory after + mkdir(2). + Fri Dec 12 06:06:09 2003 Nobuyoshi Nakada <nobu@ruby-lang.org> * eval.c (proc_invoke): fix class name in warning message for diff --git a/lib/fileutils.rb b/lib/fileutils.rb index deba1c8fda..d34e6fec4b 100644 --- a/lib/fileutils.rb +++ b/lib/fileutils.rb @@ -143,7 +143,7 @@ module FileUtils mode = options[:mode] || (0777 & ~File.umask) list.each do |dir| - Dir.mkdir dir, mode + Dir.mkdir dir.sub(%r</\z>, ''), mode end end @@ -209,7 +209,7 @@ module FileUtils return if options[:noop] list.each do |dir| - Dir.rmdir dir + Dir.rmdir dir.sub(%r</\z>, '') end end @@ -357,8 +357,11 @@ module FileUtils def fu_copy_dir(src, dest, rel, preserve) #:nodoc: fu_preserve_attr(preserve, "#{src}/#{rel}", "#{dest}/#{rel}") {|s,d| - dir = File.expand_path(d) # to remove '/./' - Dir.mkdir dir unless File.directory?(dir) + begin + Dir.mkdir File.expand_path(d) + rescue => err + raise unless File.directory?(d) + end } Dir.entries("#{src}/#{rel}").each do |fname| if File.directory?(File.join(src,rel,fname)) @@ -585,7 +588,7 @@ module FileUtils end end begin - Dir.rmdir dir + Dir.rmdir dir.sub(%r</\z>, '') rescue Errno::ENOENT raise unless force end @@ -601,9 +604,10 @@ module FileUtils def compare_file(a, b) return false unless File.size(a) == File.size(b) File.open(a, 'rb') {|fa| - File.open(b, 'rb') {|fb| + File.open(b, 'rb') {|fb| return compare_stream(fa, fb) - } } + } + } end alias identical? compare_file @@ -644,11 +648,11 @@ module FileUtils fu_each_src_dest(src, dest) do |s,d| unless File.exist?(d) and compare_file(s,d) - remove_file d, true - st = File.stat(s) if options[:preserve] - copy_file s, d - File.utime st.atime, st.mtime, d if options[:preserve] - File.chmod options[:mode], d if options[:mode] + remove_file d, true + st = File.stat(s) if options[:preserve] + copy_file s, d + File.utime st.atime, st.mtime, d if options[:preserve] + File.chmod options[:mode], d if options[:mode] end end end @@ -694,7 +698,7 @@ module FileUtils File.utime(t, t, fname) rescue Errno::ENOENT File.open(fname, 'a') { - ; + ; } end end @@ -722,23 +726,16 @@ module FileUtils end def fu_each_src_dest0(src, dest) - unless src.is_a?(Array) - yield src.to_str, fu_dest_filename(src.to_str, dest.to_str) - else - dir = dest.to_str - #raise ArgumentError, "not a directory: #{dir}" unless File.directory?(dir) - dir += (dir[-1,1] == '/') ? '' : '/' - src.map {|s| s.to_str }.each do |fname| - yield fname, dir + File.basename(fname) + if src.is_a?(Array) + src.each do |s| + yield s.to_str, File.join(dest, File.basename(s)) end - end - end - - def fu_dest_filename(src, dest) - if File.directory?(dest) - (dest[-1,1] == '/' ? dest : dest + '/') + File.basename(src) else - dest + if File.directory?(dest) + yield src.to_str, File.join(dest, File.basename(src)) + else + yield src.to_str, dest.to_str + end end end diff --git a/test/fileutils/test_fileutils.rb b/test/fileutils/test_fileutils.rb index 6c40780492..03d4f1a1ba 100644 --- a/test/fileutils/test_fileutils.rb +++ b/test/fileutils/test_fileutils.rb @@ -164,6 +164,9 @@ end cp fname, 'tmp' assert_same_file fname, 'tmp/' + File.basename(fname) + cp fname, 'tmp/' + assert_same_file fname, 'tmp/' + File.basename(fname) + cp fname, 'tmp/preserve', :preserve => true assert_same_file fname, 'tmp/preserve' a = File.stat(fname) @@ -221,10 +224,17 @@ end end def test_mv + mkdir 'tmp/dest' TARGETS.each do |fname| cp fname, 'tmp/mvsrc' mv 'tmp/mvsrc', 'tmp/mvdest' assert_same_file fname, 'tmp/mvdest' + + mv 'tmp/mvdest', 'tmp/dest/' + assert_same_file fname, 'tmp/dest/mvdest' + + mv 'tmp/dest/mvdest', 'tmp' + assert_same_file fname, 'tmp/mvdest' end # src==dest (1) same path @@ -474,6 +484,10 @@ end assert_directory 'tmpdatadir' Dir.rmdir 'tmpdatadir' + mkdir 'tmpdatadir/' + assert_directory 'tmpdatadir' + Dir.rmdir 'tmpdatadir' + mkdir 'tmp/mkdirdest' assert_directory 'tmp/mkdirdest' Dir.rmdir 'tmp/mkdirdest' @@ -485,7 +499,8 @@ end # pathname assert_nothing_raised { - mkdir 'tmp/tmpdirtmp' + mkdir Pathname.new('tmp/tmpdirtmp') + mkdir [Pathname.new('tmp/tmpdirtmp2'), Pathname.new('tmp/tmpdirtmp3')] } end @@ -518,7 +533,7 @@ end end rm_rf 'tmpdir' dirs.each do |d| - mkdir_p File.expand_path(d) + mkdir_p "#{Dir.pwd}/#{d}" assert_directory d end rm_rf 'tmpdir' |