lib/rake/common/ziptask.rb in rake-delphi-0.0.16 vs lib/rake/common/ziptask.rb in rake-delphi-0.0.17
- old
+ new
@@ -1,9 +1,10 @@
# encoding: utf-8
require 'zlib'
require 'rake/common/classes'
+require 'rake/common/logger'
require 'rake/helpers/raketask'
module Rake
module Delphi
class GZip < BasicTask
@@ -39,60 +40,39 @@
Logger.trace(Logger::VERBOSE, [zipfile, files])
raise "zipfile name is not defined!" if zipfile.nil? || zipfile.empty?
@norubyzip = nil
@options = options || {}
begin
- require 'zipruby'
+ require 'zip/zip'
rescue LoadError
- begin
- require 'zip/zip'
- rescue LoadError
- @norubyzip = true
- end
+ @norubyzip = true
end
- raise "no ZIP library (nor zipruby nor rubyzip) found!" if @norubyzip
- if defined? Zip::Archive
- # zipruby used
- Logger.trace(Logger::VERBOSE, '`zipruby` gem is used')
- Zip::Archive.open(zipfile, Zip::CREATE | Zip::TRUNC) do |z|
- files.each do |f|
- zip_addfile(z, f)
- end
+ raise "no ZIP library (rubyzip) found!" if @norubyzip
+ # work with rubyzip
+ Logger.trace(Logger::VERBOSE, '`rubyzip` gem is used')
+ File.unlink(zipfile) if File.exists?(zipfile) && ! @options[:add]
+ Zip.options[:continue_on_exists_proc] = true
+ Zip::ZipFile.open(zipfile, Zip::ZipFile::CREATE) do |z|
+ files.each do |f|
+ zip_addfile(z, f)
end
- else
- # work with rubyzip
- Logger.trace(Logger::VERBOSE, '`rubyzip` gem is used')
- File.unlink(zipfile) if File.exists?(zipfile)
- Zip.options[:continue_on_exists_proc] = true
- Zip::ZipFile.open(zipfile, Zip::ZipFile::CREATE) do |z|
- files.each do |f|
- zip_addfile(z, f)
- end
- end
end
end
private
def zip_addfile(zipfile, file)
return if ! File.exists?(file)
filename = File.basename(file)
@task.out "Zipping #{file}..."
- if defined? Zip::Archive
- if @options[:preserve_paths]
- if ! zipfile.locate_name(File.dirname(file))
- zipfile.add_dir(File.dirname(file))
- end
- filename = file
- end
- zipfile.add_file(filename, file)
- else
- if @options[:preserve_paths]
- dir = File.dirname(file)
- # avoid "./<filename>" entries (instead of "<filename>")
- filename = File.join(dir, filename) if dir != '.'
- end
- zipfile.add(filename, file)
+ if @options[:preserve_paths]
+ dir = File.dirname(file)
+ # avoid "./<filename>" entries (instead of "<filename>")
+ filename = File.join(dir, filename) if dir != '.'
+
+ # remove leading slash (for absolute paths)
+ filename.gsub!(/^\//, '')
end
+ zipfile.add(filename, file)
end
end
end
end