Chapter 09/circuit-oneops-1-master/components/cookbooks/artifact/providers/deploy.rb
# Deletes released versions of the artifact when the number of
# released versions exceeds the :keep value.
Deletes released versions of the artifact when the number of
released versions exceeds the :keep value.
Deletes released versions of the artifact when the number of released versions exceeds the : keep value .
def delete_previous_versions!
  recipe_eval do
    versions_to_delete = []
    keep = new_resource.keep
    delete_first = total = get_previous_version_paths.length
    Chef::Log.info "# of previouse artifacts to keep = #{keep} Current Total = #{total}"
    if total == 0 || total <= keep
      true
    else
      delete_first -= keep
      Chef::Log.info "artifact_deploy[delete_previous_versions!] is deleting #{delete_first} of #{total} old versions (keeping: #{keep})"
      versions_to_delete = get_previous_version_paths.shift(delete_first)
    end
    versions_to_delete.each do |version|
      log "artifact_deploy[delete_previous_versions!] #{version.basename} deleted" do
        level :info
      end
      directory ::File.join(artifact_cache, version.basename) do
        recursive true
        action    :delete
      end
      directory ::File.join(new_resource.deploy_to, 'releases', version.basename) do
        recursive true
        action    :delete
      end
    end
  end
end
def delete_previous_versions! recipe_eval do versions_to_delete = [ ] keep = new_resource . keep delete_first = total = get_previous_version_paths . length Chef :: Log . info "# of previouse artifacts to keep = #{keep} Current Total = #{total}" if total == 0 || total <= keep true else delete_first -= keep Chef :: Log . info "artifact_deploy[delete_previous_versions!] is deleting #{delete_first} of #{total} old versions (keeping: #{keep})" versions_to_delete = get_previous_version_paths . shift ( delete_first ) end versions_to_delete . each do | version | log "artifact_deploy[delete_previous_versions!] #{version.basename} deleted" do level :info end directory :: File . join ( artifact_cache , version . basename ) do recursive true action :delete end directory :: File . join ( new_resource . deploy_to , 'releases' , version . basename ) do recursive true action :delete end end end end
Deletes released versions of the artifact when the number of
released versions exceeds the :keep value.
Deletes released versions of the artifact when the number of released versions exceeds the : keep value .