Permalink
Browse files

Use basic-bsdtar instead of 7zip extraction.

This wins on speed: there is no gz/bz2/lzma extraction and
then untar.
  • Loading branch information...
1 parent ffc1f48 commit 8649800623a36d3eea64843eb41140d0e23e6bcf @jonforums jonforums committed with luislavena Aug 4, 2010
Showing with 23 additions and 26 deletions.
  1. +4 −0 config/ruby_installer.rb
  2. +15 −22 rake/extracttask.rb
  3. +4 −4 rakefile.rb
View
4 config/ruby_installer.rb
@@ -5,6 +5,10 @@ module RubyInstaller
# Root folder
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 = OpenStruct.new(
:release => 'current',
View
37 rake/extracttask.rb
@@ -1,11 +1,5 @@
-require 'tmpdir'
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 = {})
if File.directory? src
d = File.directory?(dest) ? File.join(dest, File.basename(src)) : dest
@@ -24,20 +18,15 @@ def mv_r(src, dest, options = {})
def extract(file, target, options = {})
fail unless File.directory?(target)
- # create a temporary folder used to extract files there
- 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
+ # based on filetypes, extract the files
case file
- # tar.z, tar.gz and tar.bz2 contains .tar files inside, extract into
- # temp first
+ # tar.z, tar.gz, tar.bz2 and tar.lzma contains .tar files inside, use bsdtar to
+ # 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$/
- seven_zip tmpdir, file
- seven_zip target, File.join(tmpdir, File.basename($1))
+ bsd_tar_extract(target, file)
when /(^.+)\.tgz$/
- seven_zip tmpdir, file
- seven_zip target, File.join(tmpdir, "#{File.basename($1)}.tar")
+ bsd_tar_extract(target, file)
when /(^.+\.zip$)/
seven_zip(target, $1)
else
@@ -67,15 +56,11 @@ def extract(file, target, options = {})
puts "** Removing #{folder}" if Rake.application.options.trace
FileUtils.rm_rf File.join(target, folder)
end
-
- # remove the temporary directory
- puts "** Removing #{tmpdir}" if Rake.application.options.trace
- FileUtils.rm_rf tmpdir
end
def seven_zip(target, file)
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
#TODO confirm function returns false upon failing 7-Zip integrity test
@@ -94,3 +79,11 @@ def seven_zip_build(source, target, options={})
sfx_arg = '-sfx7z.sfx' if options[:sfx]
sh "\"#{RubyInstaller::SEVEN_ZIP}\" a -mx=9 #{sfx_arg} \"#{target}\" \"#{source}\" > NUL"
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
View
8 rakefile.rb
@@ -11,16 +11,16 @@
# Add extensions to core Ruby classes
require 'rake/core_extensions'
-# Added download task from buildr
-require 'rake/downloadtask'
-require 'rake/extracttask'
-
# RubyInstaller configuration data
require 'config/ruby_installer'
# DevKit configuration data
require 'config/devkit'
+# Added download task from buildr
+require 'rake/downloadtask'
+require 'rake/extracttask'
+
# Allow build configuration overrides if override/build_config.rb file
# exists in the RubyInstaller project root directory
begin

0 comments on commit 8649800

Please sign in to comment.