Method: LibGems::Installer#extract_files
- Defined in:
- lib/libgems/installer.rb
#extract_files ⇒ Object
Reads the file index and extracts each file into the gem directory.
Ensures that files can’t be installed outside the gem directory.
572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 |
# File 'lib/libgems/installer.rb', line 572 def extract_files @gem_dir = File. @gem_dir raise ArgumentError, "format required to extract from" if @format.nil? dirs = [] @format.file_entries.each do |entry, file_data| path = entry['path'].untaint if path =~ /\A\// then # for extra sanity raise LibGems::InstallError, "attempt to install file into #{entry['path'].inspect}" end path = File. File.join(@gem_dir, path) if path !~ /\A#{Regexp.escape @gem_dir}/ then msg = "attempt to install file into %p under %p" % [entry['path'], @gem_dir] raise LibGems::InstallError, msg end FileUtils.rm_rf(path) if File.exists?(path) dir = File.dirname(path) if !dirs.include?(dir) dirs << dir FileUtils.mkdir_p dir end File.open(path, "wb") do |out| out.write file_data end FileUtils.chmod entry['mode'], path say path if LibGems.configuration.really_verbose end end |