Windows_zipfile and empty directories

I'm writing a recipe that downloads a zip file from AWS S3 and unzips it with windows_zipfile but I'm running into an issue that I can't seem to find any info on. The process errors out if there is an empty directory in the zip file anywhere. As soon as I remove the empty directories, the recipe completes without error. Here's a snip of the code from my recipe:

# unzip the file to the new site directory
  windows_zipfile 'site zip' do
  source "#{zip_file_dest}"
  path "#{new_site_dir}"
  action :unzip
  only_if { ::Dir.exist?("#{new_site_dir}") }
end

This is a zip of a website directory and the empty directories may be needed during runtime so I don't want to just delete them. I didn't see any other options to windows_zipfile that might allow for the empty directories.

Has anybody else had this problem?

@phpbutcher,

You might want to try out our new archive_file resource in Chef Infra Client 15. It avoids a lot of the issues with the older windows_zipfile resource by using native system libraries for handling archives. https://docs.chef.io/resource_archive_file.html

-Tim

Thanks Tim, I tried this:

archive_file 'site zip' do
  destination "#{new_site_dir}"
  path "#{zip_file_dest}"
  action :extract
  only_if { ::Dir.exist?("#{new_site_dir}") }
end

and even though the recipe completes without error, the new site directory is empty. Am I missing something for this resource to make it work correctly on a Windows server? For the record, I'm running this as a local client and I'm using Chef Infra Client 15.2.20.

I should add that when this resource runs, it reports as (up to date) but I don't know why.

 * archive_file[site zip] action extract (up to date)

Thanks for your help!
Marty

Thanks for your help Tim, I got it working. For anybody else with this issue, the archive_file resource does work as Tim suggested and doesn't have the same issue with empty directories as windows_zipfile, but there was one thing tripping me up. Because the directory that I was having the resource expand the zip to already existed, Chef was returning (up to date) but not extracting the zip to it. I ran Chef in debug mode and that's where this was:

DEBUG: Not extracting archive as M:\Websites\Z3950Service_2019-08-20-074913 exists and resource not set to overwrite.

Thanks again

1 Like