Module: Deployman::Extractor::Zip
- Defined in:
- lib/deployman/extractor/zip.rb
Class Method Summary collapse
-
.extract_file(file, dest) ⇒ Object
extract_file file: “/tmp/repoOnwer-repoName-v2.2.0-0-gb98bf98.zip” dest: “…/customerName/software/repoOnwer/repoName/releases/v2.2.0”.
Class Method Details
.extract_file(file, dest) ⇒ Object
extract_file file: “/tmp/repoOnwer-repoName-v2.2.0-0-gb98bf98.zip” dest: “…/customerName/software/repoOnwer/repoName/releases/v2.2.0”
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/deployman/extractor/zip.rb', line 10 def self.extract_file (file, dest) # dest = "/sandbox/liveserver/customerName/software/repoOnwer/repoName/releases/v2.2.0" # dest_dir = "v2.2.0" # dest_path = "/sandbox/liveserver/customerName/software/repoOwner/repoName/releases/" dest_dir = dest.split("/").last dest_path = dest.chomp(dest_dir) root_folder = false begin # get the full path to the real unzipped folder # e.g. "/sandbox/liveserver/.../releases/repoOnwer-repoName-3940226/" root_folder = File.join(dest_path, Zip::File.open(file).first.name) # lets create all needed dirs FileUtils.mkdir_p(dest_path) # unzip Zip::File.open(file) do |zip_file| Deployman::Component::Spinningclock.show_clock { # unzip zip_file.each do |f| f_path=File.join(dest_path, f.name) FileUtils.mkdir_p(File.dirname(f_path)) zip_file.extract(f, f_path) unless File.exist?(f_path) end } end # rename the unzipped root folder File.rename(root_folder, dest) rescue Exception => e FileUtils.rm_rf(root_folder) if root_folder && File.exists?(root_folder) FileUtils.rm_rf(dest) if File.exists?(dest) warn "ERROR: #{e.message}" raise "Unzipping failed!" end end |