populate

in lib/taste_tester/client.rb [131:186]


    def populate(stream, writer, path, destination)
      full_path = File.join(File.join(TasteTester::Config.repo, path))
      return unless File.directory?(full_path)
      chefignores = Chef::Cookbook::Chefignore.new(full_path)
      
      
      Dir.chdir(full_path) do
        look_at = ['']
        while (prefix = look_at.pop)
          Dir.glob(File.join("#{prefix}**", '*'), File::FNM_DOTMATCH) do |p|
            minus_first = p.split(
              File::SEPARATOR,
            )[1..-1].join(File::SEPARATOR)
            next if chefignores.ignored?(p) ||
              chefignores.ignored?(minus_first)
            name = File.join(destination, p)
            if File.directory?(p)
              
              
              
              if minus_first == '' && File.symlink?(p)
                look_at.push("#{p}#{File::SEPARATOR}")
              end
            elsif File.symlink?(p)
              
              
              
              
              
              fail 'Add support for long symlink paths' if name.size > 100
              
              
              
              symlink = {
                :name => name,
                :mode => 0644,
                :typeflag => '2',
                :size => 0,
                :linkname => File.readlink(p),
                :prefix => '',
              }
              stream.write(Minitar::PosixHeader.new(symlink))
            else
              File.open(p, 'rb') do |r|
                writer.add_file_simple(
                  name, :mode => 0644, :size => File.size(r)
                ) do |d, _opts|
                  IO.copy_stream(r, d)
                end
              end
            end
          end
        end
      end
    end