Skip to content

Commit

Permalink
Don't fall back to FileUtils.cp_r, use FileUtils.mv recursively
Browse files Browse the repository at this point in the history
  • Loading branch information
snaury committed Aug 21, 2009
1 parent 79496ee commit 397a4b6
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions rake/extracttask.rb
@@ -1,6 +1,21 @@
require 'tmpdir'
require 'fileutils'

def mv_r(src, dest, options = {})
if File.directory? src
d = File.directory?(dest) ? File.join(dest, File.basename(src)) : dest
if File.directory? d
Dir.glob(File.join(src, '*')).each do |s|
mv_r(s, d, options)
end
else
FileUtils.mv(src, dest, options)
end
else
FileUtils.mv(src, dest, options)
end
end

def extract(file, target, options = {})
fail unless File.directory?(target)

Expand Down Expand Up @@ -40,11 +55,7 @@ def extract(file, target, options = {})

contents.each do |c|
puts "** Moving out #{c} from #{folder} and drop into #{target}" if Rake.application.options.trace
if File.directory? File.join(target, c)
FileUtils.cp_r File.join(target, folder, c), target
else
FileUtils.mv File.join(target, folder, c), target, :force => true
end
mv_r File.join(target, folder, c), target
end

# remove the now empty folder
Expand Down

0 comments on commit 397a4b6

Please sign in to comment.