thinkerbot / tap

A framework for creating configurable, distributable tasks and workflows.
http://tap.rubyforge.org
20 stars 0 forks source link

Update tap-gen to cleanup empty directories #14

Open thinkerbot opened 14 years ago

thinkerbot commented 14 years ago
  def directory(target, options={})
    target = path(target)

    case
    when !File.exists?(target)
      log_relative :missing, target
    when !File.directory?(target)
      log_relative 'not a directory', target
    when target == Dir.pwd
    when !Root.empty?(target)
      paths = Dir.glob File.join(target, '**/*')
      paths.unshift(target)

      paths.sort.reverse_each do |path|
        if Root.empty?(path)
          log_relative :rm, path
          FileUtils.rmdir(path) unless pretend
        else
          log_relative('not empty', path)
        end
      end

    else
      log_relative :rm, target
      FileUtils.rmdir(target) unless pretend
    end

    target
  end