diff options
author | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2006-03-03 12:24:53 +0000 |
---|---|---|
committer | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2006-03-03 12:24:53 +0000 |
commit | 192fcacebf45f6344a5edf6d560f88ef3883273b (patch) | |
tree | 02fe98837257c9488889ca0471f0a500563af448 /lib/fileutils.rb | |
parent | 469f1f7b491d58c26553ccf7d5cb60f5f48c7d39 (diff) |
* lib/fileutils.rb (FileUtils.cp_r): implement :remove_destination
option.
* ext/extmk.rb: use :remove_destination to install extension libraries
to avoid SEGV.
[ruby-dev:28417]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@10019 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/fileutils.rb')
-rw-r--r-- | lib/fileutils.rb | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/lib/fileutils.rb b/lib/fileutils.rb index 3e7989a287..d45c6767a2 100644 --- a/lib/fileutils.rb +++ b/lib/fileutils.rb @@ -392,7 +392,7 @@ module FileUtils OPT_TABLE['copy'] = %w( noop verbose preserve ) # - # Options: preserve noop verbose dereference_root + # Options: preserve noop verbose dereference_root remove_destination # # Copies +src+ to +dest+. If +src+ is a directory, this method copies # all its contents recursively. If +dest+ is a directory, copies @@ -415,11 +415,11 @@ module FileUtils # # but this doesn't. # def cp_r(src, dest, options = {}) - fu_check_options options, :preserve, :noop, :verbose, :dereference_root - fu_output_message "cp -r#{options[:preserve] ? 'p' : ''} #{[src,dest].flatten.join ' '}" if options[:verbose] + fu_check_options options, :preserve, :noop, :verbose, :dereference_root, :remove_destination + fu_output_message "cp -r#{options[:preserve] ? 'p' : ''}#{options[:remove_destination] ? ' --remove-destination' : ''} #{[src,dest].flatten.join ' '}" if options[:verbose] return if options[:noop] fu_each_src_dest(src, dest) do |s, d| - copy_entry s, d, options[:preserve], options[:dereference_root] + copy_entry s, d, options[:preserve], options[:dereference_root], options[:remove_destination] end end module_function :cp_r @@ -440,9 +440,12 @@ module FileUtils # # If +dereference_root+ is true, this method dereference tree root. # - def copy_entry(src, dest, preserve = false, dereference_root = false) + # If +remove_destination+ is true, this method removes each destination file before copy. + # + def copy_entry(src, dest, preserve = false, dereference_root = false, remove_destination = false) Entry_.new(src, nil, dereference_root).traverse do |ent| destent = Entry_.new(dest, ent.rel, false) + File.unlink destent.path if remove_destination && File.file?(destent.path) ent.copy destent.path ent.copy_metadata destent.path if preserve end |