Class: Chef::Provider::ZipFile

Inherits:
Chef::Provider show all
Includes:
Mixin::EnforceOwnershipAndPermissions, Garcon
Defined in:
lib/garcon/chef/provider/zip_file.rb

Constant Summary

Constants included from Garcon

Garcon::VERSION

Instance Method Summary collapse

Methods included from Garcon

auto_terminate_all_executors?, auto_terminate_global_executors?, coercer, coercer=, config, configuration, crypto, crypto=, disable_auto_termination_of_all_executors!, disable_auto_termination_of_global_executors!, global_fast_executor, global_io_executor, global_timer_set, included, #inspect, kill_global_executors, monotonic_time, new_fast_executor, new_io_executor, physical_processor_count, processor_count, secret, secret=, shutdown_global_executors, #terminal_dimensions, timer, #to_s, wait_for_global_executors_termination, warn

Constructor Details

#initialize(new_resource, run_context) ⇒ ZipFile

Returns a new instance of ZipFile.



76
77
78
79
# File 'lib/garcon/chef/provider/zip_file.rb', line 76

def initialize(new_resource, run_context)
  super
  __zip__ unless defined?(Zip)
end

Instance Method Details

#action_unzipObject



104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/garcon/chef/provider/zip_file.rb', line 104

def action_unzip
  converge_by "Unzip #{r.source} to #{r.path}" do
    Zip::File.open(cached_file) do |zip|
      zip.each do |entry|
        path = ::File.join(r.path, entry.name)
        FileUtils.mkdir_p(::File.dirname(path))
        if r.overwrite && ::File.exist?(path) && !::File.directory?(path)
          FileUtils.rm(path)
        end
        zip.extract(entry, path)
      end
    end
    do_acl_changes
    ::File.unlink(cached_file) if r.remove_after
    r.updated_by_last_action(true)
  end
end

#action_zipObject



122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
# File 'lib/garcon/chef/provider/zip_file.rb', line 122

def action_zip
  if ::File.exists?(r.path) && !r.overwrite
    Chef::Log.info "#{r.path} already exists - nothing to do"
  else
    ::File.unlink(r.path) if ::File.exists?(r.path)
    if ::File.directory?(r.source)
      converge_by "Zip #{r.source}" do
        z = Zip::File.new(r.path, true)
        Find.find(r.source) do |f|
          next if f == r.source
          zip_fname = f.sub(r.source, '')
          z.add(zip_fname, f)
        end
        z.close
        do_acl_changes
        r.updated_by_last_action(true)
      end
    else
      Chef::Log.warn 'A valid directory must be specified for ziping.'
    end
  end
end

#load_current_resourceChef::Provider::ZipFile

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Load and return the current resource.



99
100
101
102
# File 'lib/garcon/chef/provider/zip_file.rb', line 99

def load_current_resource
  @current_resource ||= Chef::Resource::ZipFile.new(r.name)
  @current_resource
end

Implementation components should follow symlinks when managing access control (e.g., use chmod instead of lchmod even if the path we’re managing is a symlink).

Returns:



149
150
151
# File 'lib/garcon/chef/provider/zip_file.rb', line 149

def manage_symlink_access?
  false
end

#whyrun_supported?TrueClass, FalseClass

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Boolean indicating if WhyRun is supported by this provider.

Returns:



90
91
92
# File 'lib/garcon/chef/provider/zip_file.rb', line 90

def whyrun_supported?
  true
end