Author: boisvert
Date: Tue Oct 12 01:43:52 2010
New Revision: 1021584
URL: http://svn.apache.org/viewvc?rev=1021584&view=rev
Log:
Check for possible corruption usign Java's ZipInputStream since it's stricter
than rubyzip.
These checks would have caught BUILDR-517 early.
Modified:
buildr/trunk/lib/buildr/packaging/ziptask.rb
buildr/trunk/spec/packaging/archive_spec.rb
Modified: buildr/trunk/lib/buildr/packaging/ziptask.rb
URL:
http://svn.apache.org/viewvc/buildr/trunk/lib/buildr/packaging/ziptask.rb?rev=1021584&r1=1021583&r2=1021584&view=diff
==============================================================================
--- buildr/trunk/lib/buildr/packaging/ziptask.rb (original)
+++ buildr/trunk/lib/buildr/packaging/ziptask.rb Tue Oct 12 01:43:52 2010
@@ -59,11 +59,11 @@ module Buildr
Zip::ZipOutputStream.open name do |zip|
seen = {}
mkpath = lambda do |dir|
- unless dir == '.' || seen[dir]
- mkpath.call File.dirname(dir)
- dirname = (dir[-1..-1] =~ /\/$/) ? dir : dir + '/'
+ dirname = (dir[-1..-1] =~ /\/$/) ? dir : dir + '/'
+ unless dir == '.' || seen[dirname]
+ mkpath.call File.dirname(dirname)
zip.put_next_entry(dirname, compression_level)
- seen[dir] = true
+ seen[dirname] = true
end
end
Modified: buildr/trunk/spec/packaging/archive_spec.rb
URL:
http://svn.apache.org/viewvc/buildr/trunk/spec/packaging/archive_spec.rb?rev=1021584&r1=1021583&r2=1021584&view=diff
==============================================================================
--- buildr/trunk/spec/packaging/archive_spec.rb (original)
+++ buildr/trunk/spec/packaging/archive_spec.rb Tue Oct 12 01:43:52 2010
@@ -200,15 +200,16 @@ describe 'ArchiveTask', :shared=>true do
archive(@archive).include(@files.first, :as=>'test/sample').invoke
inspect_archive { |archive| @files.each { |f|
archive['test/sample'].should eql(content_for(@files.first)) } }
end
-
+
it 'should archive directory into specified alias, without using "."' do
archive(@archive).include(@dir, :as=>'.').invoke
inspect_archive { |archive| archive.keys.should_not include(".") }
end
-
+
it 'should archive directories into specified alias, even if it has the same
name' do
+ p "dir #...@dir}"
archive(@archive).include(@dir, :as=>File.basename(@dir)).invoke
- inspect_archive { |archive|
+ inspect_archive { |archive|
archive.keys.should_not include "#{File.basename(@dir)}"
}
end
@@ -399,6 +400,22 @@ describe ZipTask do
before { @archive = File.expand_path('test.zip') }
define_method(:archive) { |file| zip(file) }
+ after do
+ checkZip(@archive)
+ end
+
+ # Check for possible corruption usign Java's ZipInputStream since it's
stricter than rubyzip
+ def checkZip(file)
+ return unless File.exist?(file)
+ zip =
Java.java.util.zip.ZipInputStream.new(Java.java.io.FileInputStream.new(file))
+ while entry = zip.getNextEntry do
+ # just iterate over all entries
+ end
+ zip.close()
+ end
+
+
+
def inspect_archive
entries = {}
Zip::ZipFile.open @archive do |zip|
@@ -432,7 +449,7 @@ describe ZipTask do
archive(@archive).invoke
inspect_archive { |archive| archive.keys.should include('code/') }
end
-
+
it 'should have path object that includes empty dirs' do
archive(@archive).path('code').include(Dir["#...@dir}/*"])
archive(@archive).invoke
@@ -585,7 +602,7 @@ describe Unzip do
Rake::Task.clear ; rm_rf @target
unzip(@target=>@zip).include('test/**/*').target.invoke
FileList[File.join(@target, 'test/path/*')].size.should be(2)
-
+
Rake::Task.clear ; rm_rf @target
unzip(@target=>@zip).include('test/*').target.invoke
FileList[File.join(@target, 'test/path/*')].size.should be(2)
@@ -702,4 +719,5 @@ describe Unzip do
task = unzip(@target=>@zip)
task.from_path('foo').should be(task.path('foo'))
end
+
end