Skip to content

Commit

Permalink
Adding merge_zip support.
Browse files Browse the repository at this point in the history
  • Loading branch information
iced committed Feb 24, 2014
1 parent 6dba527 commit 2d2d62a
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 8 deletions.
6 changes: 3 additions & 3 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
PATH
remote: .
specs:
iron_worker_ng (1.2.0)
iron_worker_ng (1.3.0)
bundler
iron_core (>= 1.0.0)
rubyzip (>= 1.0.0)
rubyzip (= 0.9.9)

GEM
remote: https://rubygems.org/
Expand Down Expand Up @@ -58,7 +58,7 @@ GEM
rest_client (>= 1.7.1)
rest_client (1.7.2)
netrc (~> 0.7.7)
rubyzip (1.1.0)
rubyzip (0.9.9)
simple_oauth (0.2.0)
test-unit (2.5.5)
thread_safe (0.1.3)
Expand Down
2 changes: 1 addition & 1 deletion iron_worker_ng.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Gem::Specification.new do |gem|

gem.add_runtime_dependency 'iron_core', '>= 1.0.0'
gem.add_runtime_dependency 'bundler'
gem.add_runtime_dependency 'rubyzip', '>= 1.0.0'
gem.add_runtime_dependency 'rubyzip', '= 0.9.9'

This comment has been minimized.

Copy link
@akshayrawat

akshayrawat Jun 5, 2014

This is nasty. You've downgraded and fixed the RubyZip version to an exact one which was released 2 years ago. Most newer gems have installation problems with this, since they need RubyZip >= 1.0.0 (released a year ago).

Issue raised

This comment has been minimized.

Copy link
@akshayrawat

akshayrawat Jun 5, 2014

This is preventing a couple of my apps to upgrade to iron_worker_ng 1.5.0, since i've other gems which need rubyzip >= 1.0.0


gem.add_development_dependency 'test-unit'
gem.add_development_dependency 'minitest'
Expand Down
2 changes: 2 additions & 0 deletions lib/iron_worker_ng/code/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
require 'iron_worker_ng/feature/common/merge_file'
require 'iron_worker_ng/feature/common/merge_dir'
require 'iron_worker_ng/feature/common/merge_deb'
require 'iron_worker_ng/feature/common/merge_zip'
require 'iron_worker_ng/feature/common/set_env'

module IronWorkerNG
Expand All @@ -30,6 +31,7 @@ class Base
include IronWorkerNG::Feature::Common::MergeFile::InstanceMethods
include IronWorkerNG::Feature::Common::MergeDir::InstanceMethods
include IronWorkerNG::Feature::Common::MergeDeb::InstanceMethods
include IronWorkerNG::Feature::Common::MergeZip::InstanceMethods
include IronWorkerNG::Feature::Common::SetEnv::InstanceMethods

def initialize(*args, &block)
Expand Down
6 changes: 3 additions & 3 deletions lib/iron_worker_ng/code/container/zip.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'zip'
require 'zip/zip'

Zip.continue_on_exists_proc = true
Zip.options[:continue_on_exists_proc] = true

module IronWorkerNG
module Code
Expand All @@ -10,7 +10,7 @@ def initialize
super

@name = @name + '.zip'
@zip = ::Zip::File.open(@name, ::Zip::File::CREATE)
@zip = ::Zip::ZipFile.open(@name, ::Zip::ZipFile::CREATE)
end

def add(dest, src)
Expand Down
68 changes: 68 additions & 0 deletions lib/iron_worker_ng/feature/common/merge_zip.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
module IronWorkerNG
module Feature
module Common
module MergeZip
class Feature < IronWorkerNG::Feature::Base
attr_reader :path
attr_reader :dest

def initialize(code, path, dest)
super(code)

@path = path
@dest = dest + (dest.empty? || dest.end_with?('/') ? '' : '/')
end

def bundle(container)
IronCore::Logger.debug 'IronWorkerNG', "Bundling zip with path='#{@path}' and dest='#{@dest}'"

if (not @code.full_remote_build) || (not IronWorkerNG::Fetcher.remote?(rebase(@path)))
tmp_dir_name = ::Dir.tmpdir + '/' + ::Dir::Tmpname.make_tmpname('iron-worker-ng-', 'zip')

::Dir.mkdir(tmp_dir_name)

IronWorkerNG::Fetcher.fetch_to_file(rebase(@path)) do |zip|
zipf = ::Zip::ZipFile.open(zip)
zipf.restore_permissions = true

zipf.each do |f|
next if zipf.get_entry(f).ftype == :directory

zipf.get_entry(f).extract(tmp_dir_name + '/' + File.basename(f.name))

container_add(container, @dest + f.name, tmp_dir_name + '/' + File.basename(f.name), true)

FileUtils.rm(tmp_dir_name + '/' + File.basename(f.name))
end
end

FileUtils.rm_rf(tmp_dir_name)
end
end

def build_command
if @code.remote_build_command || @code.full_remote_build
if @code.full_remote_build && IronWorkerNG::Fetcher.remote?(rebase(@path))
"zip '#{rebase(@path)}', '#{@dest}'"
else
"zip '#{@code.dest_dir}#{@dest}#{File.basename(@path)}', '#{@dest}'"
end
else
nil
end
end
end

module InstanceMethods
def merge_zip(path, dest = '')
IronCore::Logger.info 'IronWorkerNG', "Merging zip with path='#{path}' and dest='#{dest}'"

@features << IronWorkerNG::Feature::Common::MergeZip::Feature.new(self, path, dest)
end

alias :zip :merge_zip
end
end
end
end
end
2 changes: 1 addition & 1 deletion lib/iron_worker_ng/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module IronWorkerNG
VERSION = '1.2.0'
VERSION = '1.3.0'

def self.version
VERSION
Expand Down

0 comments on commit 2d2d62a

Please sign in to comment.