Module: Selenium::WebDriver::Zipper

Defined in:
lib/monkey-patches/webdriver-patches.rb

Class Method Summary collapse

Class Method Details

.zip(path) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/monkey-patches/webdriver-patches.rb', line 43

def self.zip(path)
  # can't use Tempfile here since it doesn't support File::BINARY mode on 1.8
  # can't use Dir.mktmpdir(&blk) because of http://jira.codehaus.org/browse/JRUBY-4082
  tmp_dir = Dir.mktmpdir
  begin
    zip_path = File.join(tmp_dir, "webdriver-zip")

    Zip::ZipFile.open(zip_path, Zip::ZipFile::CREATE) { |zip|
      ::Find.find(path) do |file|
        next if File.directory?(file)
        entry = file.sub("#{path}/", '')
        #PATCH begin
        entry = Zip::ZipEntry.new(zip_path, entry)
        entry.follow_symlinks = true
        #PATCH end - nothing removed from original

        zip.add entry, file
      end
    }

    File.open(zip_path, "rb") { |io| Base64.strict_encode64 io.read }
  ensure
    FileUtils.rm_rf tmp_dir
  end
end