tap icon indicating copy to clipboard operation
tap copied to clipboard

Update tap-gen to cleanup empty directories

Open thinkerbot opened this issue 14 years ago • 0 comments

  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

thinkerbot avatar Jul 14 '10 15:07 thinkerbot