From 7b042af43eb12253e3c87a20da81cd42a89ca379 Mon Sep 17 00:00:00 2001 From: topac Date: Fri, 17 Apr 2015 16:14:49 +0200 Subject: [PATCH 1/4] fix comparison with version numbers like x.x.xa (with final letter) --- lib/knapsack/recipe.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/knapsack/recipe.rb b/lib/knapsack/recipe.rb index e7bc909..ec4f4b2 100644 --- a/lib/knapsack/recipe.rb +++ b/lib/knapsack/recipe.rb @@ -54,7 +54,7 @@ def self.find_by_name name, *requirements dependency = Gem::Dependency.new(name, *requirements) candidates = _all.select { |r| - dependency.match? r.name, r.version + dependency.match? r.name, r.version.to_s.gsub(/[a-z]/i, "") }.sort_by { |r| r.version } candidates.last From f654e9e440efa319115f8cc9fa676b5365f36c00 Mon Sep 17 00:00:00 2001 From: topac Date: Fri, 17 Apr 2015 16:14:57 +0200 Subject: [PATCH 2/4] cosmetic --- lib/knapsack/recipe.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/knapsack/recipe.rb b/lib/knapsack/recipe.rb index ec4f4b2..ef47047 100644 --- a/lib/knapsack/recipe.rb +++ b/lib/knapsack/recipe.rb @@ -267,7 +267,7 @@ def announce(action) when :download "Fetching files..." when :extract - "Extracting files into work directory" + "Extracting files into working directory" when :configure "Configuring" when :compile From 61e54e03cdfe36cf8153d8aa0a0afb3e3146b474 Mon Sep 17 00:00:00 2001 From: topac Date: Fri, 17 Apr 2015 16:15:31 +0200 Subject: [PATCH 3/4] do not rely on external commands (tar and curl) --- lib/knapsack/utils.rb | 38 +++++++++++++++++++++++++++++--------- 1 file changed, 29 insertions(+), 9 deletions(-) diff --git a/lib/knapsack/utils.rb b/lib/knapsack/utils.rb index e3cec85..8ab96c3 100644 --- a/lib/knapsack/utils.rb +++ b/lib/knapsack/utils.rb @@ -3,7 +3,10 @@ require "digest/md5" require "digest/sha2" require "fileutils" +require "open-uri" require "psych" +require 'zlib' +require 'rubygems/package' module Knapsack module Utils @@ -12,12 +15,9 @@ def download(url, filename) ensure_tree File.dirname(filename) - cmd = ["curl", "-L", "-s", "-S", url, "-o", filename] + tmpfile = open(url, ssl_verify_mode: OpenSSL::SSL::VERIFY_NONE) - pid = Process.spawn(*cmd, :err => [:child, :out], :out => IO::NULL) - _, status = Process.wait2(pid) - - status.success? + File.open(filename, "wb") { |file| file.write(tmpfile.read) } end module_function :download @@ -38,12 +38,32 @@ def extract(filename, target, options = {}) raise failure_message % ["MD5", options[:md5], digest] end - cmd = ["tar", "-xf", filename, "-C", target] + file = File.open(filename, "rb") + + Gem::Package::TarReader.new(Zlib::GzipReader.new(file)) do |tar| + symlinks = {} + + tar.each do |entry| + dest = File.join(target, entry.full_name) + + if entry.header.typeflag != '2' + FileUtils.mkdir_p(File.dirname(dest)) + else + src = File.dirname(dest) + "/" + entry.header.linkname + symlinks[src] = dest + end - pid = Process.spawn(*cmd, :err => [:child, :out], :out => IO::NULL) - _, status = Process.wait2(pid) + if entry.file? + File.open(dest, "wb") { |f| f.write(entry.read) } + end + end + + symlinks.each do |src, dest| + FileUtils.cp_r(src, dest) + end + end - status.success? || options[:ignore_extract_errors] + file.close end module_function :extract From 792268d96b18ef5dea41ef3cbdcdf53c2a5f51ac Mon Sep 17 00:00:00 2001 From: topac Date: Fri, 17 Apr 2015 17:09:30 +0200 Subject: [PATCH 4/4] Revert "cosmetic" This reverts commit 40bd3d7132c0b9a91aa06ae61e909437199395e4. --- lib/knapsack/recipe.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/knapsack/recipe.rb b/lib/knapsack/recipe.rb index ef47047..ec4f4b2 100644 --- a/lib/knapsack/recipe.rb +++ b/lib/knapsack/recipe.rb @@ -267,7 +267,7 @@ def announce(action) when :download "Fetching files..." when :extract - "Extracting files into working directory" + "Extracting files into work directory" when :configure "Configuring" when :compile