Skip to content

Commit

Permalink
Use basic-bsdtar instead of 7zip extraction.
Browse files Browse the repository at this point in the history
This wins on speed: there is no gz/bz2/lzma extraction and
then untar.
  • Loading branch information
jonforums authored and luislavena committed Aug 4, 2010
1 parent ffc1f48 commit 8649800
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 26 deletions.
4 changes: 4 additions & 0 deletions config/ruby_installer.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ module RubyInstaller
# Root folder # Root folder
ROOT = File.expand_path(File.join(File.dirname(__FILE__), "..")) ROOT = File.expand_path(File.join(File.dirname(__FILE__), ".."))


# Console based utilities
SEVEN_ZIP = File.expand_path(File.join(ROOT, 'sandbox', 'extract_utils', '7za.exe'))
BSD_TAR = File.expand_path(File.join(ROOT, 'sandbox', 'extract_utils', 'basic-bsdtar.exe'))

# MinGW files # MinGW files
MinGW = OpenStruct.new( MinGW = OpenStruct.new(
:release => 'current', :release => 'current',
Expand Down
37 changes: 15 additions & 22 deletions rake/extracttask.rb
Original file line number Original file line Diff line number Diff line change
@@ -1,11 +1,5 @@
require 'tmpdir'
require 'fileutils' require 'fileutils'


module RubyInstaller
# absolute path to 7-Zip so it can be working dir agnostic
SEVEN_ZIP = File.expand_path(File.join('sandbox/extract_utils', '7za.exe'))
end

def mv_r(src, dest, options = {}) def mv_r(src, dest, options = {})
if File.directory? src if File.directory? src
d = File.directory?(dest) ? File.join(dest, File.basename(src)) : dest d = File.directory?(dest) ? File.join(dest, File.basename(src)) : dest
Expand All @@ -24,20 +18,15 @@ def mv_r(src, dest, options = {})
def extract(file, target, options = {}) def extract(file, target, options = {})
fail unless File.directory?(target) fail unless File.directory?(target)


# create a temporary folder used to extract files there # based on filetypes, extract the files
tmpdir = File.expand_path(File.join(Dir.tmpdir, "extract_sandbox_#{$$}"))
FileUtils.mkpath(tmpdir) unless File.exist?(tmpdir)

# based on filetypes, extract the intermediate file into the temporary folder
case file case file
# tar.z, tar.gz and tar.bz2 contains .tar files inside, extract into # tar.z, tar.gz, tar.bz2 and tar.lzma contains .tar files inside, use bsdtar to
# temp first # extract the files directly to target directory without the need to first
# extract to a temporary directory as when using 7za.exe
when /(^.+\.tar)\.z$/, /(^.+\.tar)\.gz$/, /(^.+\.tar)\.bz2$/, /(^.+\.tar)\.lzma$/ when /(^.+\.tar)\.z$/, /(^.+\.tar)\.gz$/, /(^.+\.tar)\.bz2$/, /(^.+\.tar)\.lzma$/
seven_zip tmpdir, file bsd_tar_extract(target, file)
seven_zip target, File.join(tmpdir, File.basename($1))
when /(^.+)\.tgz$/ when /(^.+)\.tgz$/
seven_zip tmpdir, file bsd_tar_extract(target, file)
seven_zip target, File.join(tmpdir, "#{File.basename($1)}.tar")
when /(^.+\.zip$)/ when /(^.+\.zip$)/
seven_zip(target, $1) seven_zip(target, $1)
else else
Expand Down Expand Up @@ -67,15 +56,11 @@ def extract(file, target, options = {})
puts "** Removing #{folder}" if Rake.application.options.trace puts "** Removing #{folder}" if Rake.application.options.trace
FileUtils.rm_rf File.join(target, folder) FileUtils.rm_rf File.join(target, folder)
end end

# remove the temporary directory
puts "** Removing #{tmpdir}" if Rake.application.options.trace
FileUtils.rm_rf tmpdir
end end


def seven_zip(target, file) def seven_zip(target, file)
puts "** Extracting #{file} into #{target}" if Rake.application.options.trace puts "** Extracting #{file} into #{target}" if Rake.application.options.trace
sh "\"#{File.expand_path(File.join('sandbox/extract_utils', '7za.exe'))}\" x -y -o\"#{target}\" \"#{file}\" > NUL" sh "\"#{RubyInstaller::SEVEN_ZIP}\" x -y -o\"#{target}\" \"#{file}\" > NUL"
end end


#TODO confirm function returns false upon failing 7-Zip integrity test #TODO confirm function returns false upon failing 7-Zip integrity test
Expand All @@ -94,3 +79,11 @@ def seven_zip_build(source, target, options={})
sfx_arg = '-sfx7z.sfx' if options[:sfx] sfx_arg = '-sfx7z.sfx' if options[:sfx]
sh "\"#{RubyInstaller::SEVEN_ZIP}\" a -mx=9 #{sfx_arg} \"#{target}\" \"#{source}\" > NUL" sh "\"#{RubyInstaller::SEVEN_ZIP}\" a -mx=9 #{sfx_arg} \"#{target}\" \"#{source}\" > NUL"
end end

def bsd_tar_extract(target, file)
puts "** Extracting #{file} into #{target}" if Rake.application.options.trace
absolute_file = File.expand_path(file)
Dir.chdir(target) do
sh "\"#{RubyInstaller::BSD_TAR}\" -xf \"#{absolute_file}\" > NUL"
end
end
8 changes: 4 additions & 4 deletions rakefile.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@
# Add extensions to core Ruby classes # Add extensions to core Ruby classes
require 'rake/core_extensions' require 'rake/core_extensions'


# Added download task from buildr
require 'rake/downloadtask'
require 'rake/extracttask'

# RubyInstaller configuration data # RubyInstaller configuration data
require 'config/ruby_installer' require 'config/ruby_installer'


# DevKit configuration data # DevKit configuration data
require 'config/devkit' require 'config/devkit'


# Added download task from buildr
require 'rake/downloadtask'
require 'rake/extracttask'

# Allow build configuration overrides if override/build_config.rb file # Allow build configuration overrides if override/build_config.rb file
# exists in the RubyInstaller project root directory # exists in the RubyInstaller project root directory
begin begin
Expand Down

0 comments on commit 8649800

Please sign in to comment.