├── .delivery └── project.toml ├── .github ├── CODEOWNERS ├── ISSUE_TEMPLATE.md └── PULL_REQUEST_TEMPLATE.md ├── .gitignore ├── .rubocop.yml ├── .travis.yml ├── Berksfile ├── CHANGELOG.md ├── CONTRIBUTING.md ├── Gemfile ├── LICENSE ├── README.md ├── TESTING.md ├── appveyor.yml ├── chefignore ├── kitchen.appveyor.yml ├── kitchen.dokken.yml ├── kitchen.yml ├── metadata.rb ├── recipes └── default.rb ├── resources └── file.rb ├── spec └── .gitkeep └── test └── cookbooks └── test ├── files ├── tourism.tar.gz ├── tourism.tar.xz └── tourism.zip ├── metadata.rb └── recipes └── default.rb /.delivery/project.toml: -------------------------------------------------------------------------------- 1 | remote_file = "https://raw.githubusercontent.com/chef-cookbooks/community_cookbook_tools/master/delivery/project.toml" 2 | -------------------------------------------------------------------------------- /.github/CODEOWNERS: -------------------------------------------------------------------------------- 1 | * @chef-cookbooks/cookbook_engineering_team 2 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | ### Cookbook version 2 | [Version of the cookbook where you are encountering the issue] 3 | 4 | ### Chef-client version 5 | [Version of chef-client in your environment] 6 | 7 | ### Platform Details 8 | [Operating system distribution and release version. Cloud provider if running in the cloud] 9 | 10 | ### Scenario: 11 | [What you are trying to achieve and you can't?] 12 | 13 | ### Steps to Reproduce: 14 | [If you are filing an issue what are the things we need to do in order to repro your problem? How are you using this cookbook or any resources it includes?] 15 | 16 | ### Expected Result: 17 | [What are you expecting to happen as the consequence of above reproduction steps?] 18 | 19 | ### Actual Result: 20 | [What actually happens after the reproduction steps? Include the error output or a link to a gist if possible.] 21 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | ### Description 2 | 3 | [Describe what this change achieves] 4 | 5 | ### Issues Resolved 6 | 7 | [List any existing issues this PR resolves] 8 | 9 | ### Check List 10 | 11 | - [ ] All tests pass. See 12 | - [ ] New functionality includes testing. 13 | - [ ] New functionality has been documented in the README if applicable 14 | - [ ] All commits have been signed for the Developer Certificate of Origin. See 15 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.rbc 2 | .config 3 | coverage 4 | InstalledFiles 5 | lib/bundler/man 6 | pkg 7 | rdoc 8 | spec/reports 9 | test/tmp 10 | test/version_tmp 11 | tmp 12 | *_Store 13 | *~ 14 | *# 15 | .#* 16 | \#*# 17 | .*.sw[a-z] 18 | *.un~ 19 | *.tmp 20 | *.bk 21 | *.bkup 22 | 23 | # ruby/bundler files 24 | .ruby-version 25 | .ruby-gemset 26 | .rvmrc 27 | Gemfile.lock 28 | .bundle 29 | *.gem 30 | 31 | # YARD artifacts 32 | .yardoc 33 | _yardoc 34 | doc/ 35 | .idea 36 | 37 | # chef stuff 38 | Berksfile.lock 39 | .kitchen 40 | .kitchen.local.yml 41 | vendor/ 42 | .coverage/ 43 | .zero-knife.rb 44 | Policyfile.lock.json 45 | 46 | # vagrant stuff 47 | .vagrant/ 48 | .vagrant.d/ 49 | .kitchen/ 50 | -------------------------------------------------------------------------------- /.rubocop.yml: -------------------------------------------------------------------------------- 1 | require: 2 | - cookstyle 3 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: required 2 | dist: xenial 3 | 4 | addons: 5 | apt: 6 | sources: 7 | - chef-current-xenial 8 | packages: 9 | - chefdk 10 | 11 | # Don't `bundle install` which takes about 1.5 mins 12 | install: echo "skip bundle install" 13 | 14 | branches: 15 | only: 16 | - master 17 | 18 | services: docker 19 | 20 | env: 21 | matrix: 22 | - INSTANCE=default-amazonlinux 23 | - INSTANCE=default-amazonlinux-2 24 | - INSTANCE=default-centos-6 25 | - INSTANCE=default-centos-7 26 | - INSTANCE=default-debian-8 27 | - INSTANCE=default-debian-9 28 | - INSTANCE=default-fedora-latest 29 | - INSTANCE=default-opensuse-leap 30 | - INSTANCE=default-ubuntu-1604 31 | - INSTANCE=default-ubuntu-1804 32 | 33 | before_script: 34 | - sudo iptables -L DOCKER || ( echo "DOCKER iptables chain missing" ; sudo iptables -N DOCKER ) 35 | - eval "$(chef shell-init bash)" 36 | - chef --version 37 | - cookstyle --version 38 | - foodcritic --version 39 | 40 | script: KITCHEN_LOCAL_YAML=kitchen.dokken.yml kitchen verify ${INSTANCE} 41 | 42 | matrix: 43 | include: 44 | - script: 45 | - chef exec delivery local all 46 | env: UNIT_AND_LINT=1 47 | -------------------------------------------------------------------------------- /Berksfile: -------------------------------------------------------------------------------- 1 | source 'https://supermarket.chef.io' 2 | 3 | metadata 4 | 5 | group :test, :integration do 6 | cookbook 'test', path: 'test/cookbooks/test' 7 | end 8 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # libarchive Cookbook CHANGELOG 2 | 3 | This file is used to list changes made in each version of the libarchive cookbook. 4 | 5 | ## 2.1.0 (2018-09-14) 6 | 7 | - Add Windows support 8 | - Add support for NO_OVERWRITE_NEWER 9 | 10 | ## 2.0.0 (2018-04-07) 11 | 12 | This cookbook now utilizes the libarchive built into Chef 14 to extract archives. There is no longer a need to install libarchive packages onto the host and because of this the cookbook now works on any platform supported by Chef. The libarchive_file resource has been renamed archive_file and the default recipe no longer performs any installation actions. 13 | 14 | ## 1.0.0 (2017-04-03) 15 | 16 | - Convert file LWRP to custom resource 17 | 18 | ## 0.7.1 (2017-03-30) 19 | 20 | - Update license string to standard Apache-2.0 21 | - Update maintainer information 22 | - Add source_url and issue_url 23 | - Add apt-update for debian platforms in test cookbook 24 | - Remove EOL platforms from .kitchen.yml 25 | - Add ubuntu-16.04, update latest centos 6, 7 platforms in .kitchen.yml 26 | - Modify test suite to use test cookbook 27 | 28 | ## 0.7.0 (2017-03-15) 29 | 30 | - Remove broken support for CentOS 5 and the yum-epel cookbook dependency 31 | - Remove the inclusion of apt::default in the default recipe. Apt updating is up to the user in a base role or cookbook 32 | - Resolve cookstyle warnings 33 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | Please refer to 2 | https://github.com/chef-cookbooks/community_cookbook_documentation/blob/master/CONTRIBUTING.MD 3 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | # This gemfile provides additional gems for testing and releasing this cookbook 2 | # It is meant to be installed on top of ChefDK which provides the majority 3 | # of the necessary gems for testing this cookbook 4 | # 5 | # Run 'chef exec bundle install' to install these dependencies 6 | 7 | source 'https://rubygems.org' 8 | 9 | gem 'community_cookbook_releaser' 10 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright 2013-2015, Jamie Winsor 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # libarchive-cookbook 2 | 3 | [![Build Status](https://travis-ci.org/chef-cookbooks/libarchive.svg?branch=master)](https://travis-ci.org/chef-cookbooks/libarchive) [![Cookbook Version](https://img.shields.io/cookbook/v/libarchive.svg)](https://supermarket.chef.io/cookbooks/libarchive) 4 | 5 | Resources for extracting archives of all types with Chef 6 | 7 | ## Deprecated 8 | 9 | The `archive_file` resource is now built into Chef Infra Client 15+ so this cookbook is no longer necessary. 10 | 11 | ## Requirements 12 | 13 | - Chef >= 14.0 14 | 15 | ## Supported Platforms 16 | 17 | - Ubuntu / Debian 18 | - RHEL / Amazon / Fedora 19 | - SLES / openSUSE 20 | - Windows 21 | 22 | ## Usage 23 | 24 | ```ruby 25 | archive_file "my_archive.tar.gz" do 26 | path "/path/to/artifact/my_archive.tar.gz" 27 | destination "/path/to/extraction" 28 | owner "reset" 29 | group "reset" 30 | 31 | action :extract 32 | end 33 | ``` 34 | 35 | ## archive_file Resource 36 | 37 | ### Actions 38 | 39 | - **extract** - extracts the contents of the archive to the destination on disk. (default) 40 | 41 | ### Properties 42 | 43 | - **path** - filepath to the archive to extract (name attribute) 44 | - **owner** - set the owner of the extracted files 45 | - **group** - set the group of the extracted files 46 | - **mode** - set the mode of the extracted files 47 | - **destination** - filepath to extract the contents of the archive to 48 | - **options** - an array of symbols representing extraction flags. See extract options below. 49 | 50 | ### Extract Options 51 | 52 | - `:no_overwrite` - don't overwrite files if they already exist 53 | 54 | ## License and Authors 55 | 56 | - Author:: Jamie Winsor ([jamie@vialstudios.com](mailto:jamie@vialstudios.com)) 57 | - Author:: Tim Smith ([tsmith@chef.io](mailto:tsmith@chef.io)) 58 | - Author:: John Bellone ([jbellone@bloomberg.net](mailto:jbellone@bloomberg.net)) 59 | - Author:: Jennifer Davis ([sigje@chef.io](mailto:sigje@chef.io)) 60 | 61 | ``` 62 | Licensed under the Apache License, Version 2.0 (the "License"); 63 | you may not use this file except in compliance with the License. 64 | You may obtain a copy of the License at 65 | 66 | http://www.apache.org/licenses/LICENSE-2.0 67 | 68 | Unless required by applicable law or agreed to in writing, software 69 | distributed under the License is distributed on an "AS IS" BASIS, 70 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 71 | See the License for the specific language governing permissions and 72 | limitations under the License. 73 | ``` 74 | -------------------------------------------------------------------------------- /TESTING.md: -------------------------------------------------------------------------------- 1 | Please refer to 2 | https://github.com/chef-cookbooks/community_cookbook_documentation/blob/master/TESTING.MD 3 | -------------------------------------------------------------------------------- /appveyor.yml: -------------------------------------------------------------------------------- 1 | environment: 2 | machine_user: vagrant 3 | machine_pass: vagrant 4 | KITCHEN_LOCAL_YAML: kitchen.appveyor.yml 5 | 6 | branches: 7 | only: 8 | - master 9 | 10 | # Do not build on tags (GitHub only) 11 | skip_tags: true 12 | 13 | #faster cloning 14 | clone_depth: 1 15 | 16 | # Install the latest nightly of ChefDK 17 | install: 18 | - ps: (& cmd /c); iex (irm https://omnitruck.chef.io/install.ps1); Install-Project -Project chefdk -channel current 19 | - ps: 'Get-CimInstance win32_operatingsystem -Property Caption, OSArchitecture, Version | fl Caption, OSArchitecture, Version' 20 | - ps: $PSVersionTable 21 | - c:\opscode\chefdk\bin\chef.bat exec ruby --version 22 | - ps: secedit /export /cfg $env:temp/export.cfg 23 | - ps: ((get-content $env:temp/export.cfg) -replace ('PasswordComplexity = 1', 'PasswordComplexity = 0')) | Out-File $env:temp/export.cfg 24 | - ps: ((get-content $env:temp/export.cfg) -replace ('MinimumPasswordLength = 8', 'MinimumPasswordLength = 0')) | Out-File $env:temp/export.cfg 25 | - ps: secedit /configure /db $env:windir/security/new.sdb /cfg $env:temp/export.cfg /areas SECURITYPOLICY 26 | - ps: net user /add $env:machine_user $env:machine_pass 27 | - ps: net localgroup administrators $env:machine_user /add 28 | 29 | build_script: 30 | - ps: c:\opscode\chefdk\bin\chef.bat shell-init powershell | iex; cmd /c c:\opscode\chefdk\bin\chef.bat --version 31 | 32 | test_script: 33 | - c:\opscode\chefdk\bin\cookstyle --version 34 | - c:\opscode\chefdk\bin\chef.bat exec foodcritic --version 35 | - c:\opscode\chefdk\bin\chef.bat exec delivery local all 36 | - c:\opscode\chefdk\bin\chef.bat exec kitchen verify 37 | 38 | deploy: off 39 | -------------------------------------------------------------------------------- /chefignore: -------------------------------------------------------------------------------- 1 | # Put files/directories that should be ignored in this file when uploading 2 | # to a chef-server or supermarket. 3 | # Lines that start with '# ' are comments. 4 | 5 | # OS generated files # 6 | ###################### 7 | .DS_Store 8 | Icon? 9 | nohup.out 10 | ehthumbs.db 11 | Thumbs.db 12 | 13 | # SASS # 14 | ######## 15 | .sass-cache 16 | 17 | # EDITORS # 18 | ########### 19 | \#* 20 | .#* 21 | *~ 22 | *.sw[a-z] 23 | *.bak 24 | REVISION 25 | TAGS* 26 | tmtags 27 | *_flymake.* 28 | *_flymake 29 | *.tmproj 30 | .project 31 | .settings 32 | mkmf.log 33 | 34 | ## COMPILED ## 35 | ############## 36 | a.out 37 | *.o 38 | *.pyc 39 | *.so 40 | *.com 41 | *.class 42 | *.dll 43 | *.exe 44 | */rdoc/ 45 | 46 | # Testing # 47 | ########### 48 | .rspec 49 | spec/* 50 | spec/fixtures/* 51 | test/* 52 | features/* 53 | examples/* 54 | Procfile 55 | .kitchen* 56 | .rubocop.yml 57 | spec/* 58 | .travis.yml 59 | .foodcritic 60 | appveyor.yml 61 | 62 | # SCM # 63 | ####### 64 | .git 65 | */.git 66 | .gitignore 67 | .gitmodules 68 | .gitconfig 69 | .gitattributes 70 | .svn 71 | */.bzr/* 72 | */.hg/* 73 | */.svn/* 74 | 75 | # Berkshelf # 76 | ############# 77 | Berksfile 78 | Berksfile.lock 79 | cookbooks/* 80 | tmp 81 | 82 | # Policyfile # 83 | ############## 84 | Policyfile.rb 85 | Policyfile.lock.json 86 | 87 | # Cookbooks # 88 | ############# 89 | CONTRIBUTING* 90 | CHANGELOG* 91 | TESTING* 92 | 93 | -------------------------------------------------------------------------------- /kitchen.appveyor.yml: -------------------------------------------------------------------------------- 1 | --- 2 | driver: 3 | name: proxy 4 | host: localhost 5 | reset_command: "exit 0" 6 | port: 5985 7 | username: <%= ENV["machine_user"] %> 8 | password: <%= ENV["machine_pass"] %> 9 | 10 | platforms: 11 | - name: windows-2012R2 12 | -------------------------------------------------------------------------------- /kitchen.dokken.yml: -------------------------------------------------------------------------------- 1 | driver: 2 | name: dokken 3 | privileged: true # because Docker and SystemD/Upstart 4 | chef_version: <%= ENV['CHEF_VERSION'] || 'current' %> 5 | 6 | transport: 7 | name: dokken 8 | 9 | provisioner: 10 | name: dokken 11 | deprecations_as_errors: true 12 | 13 | verifier: 14 | name: inspec 15 | 16 | platforms: 17 | - name: amazonlinux 18 | driver: 19 | image: dokken/amazonlinux 20 | pid_one_command: /sbin/init 21 | 22 | - name: amazonlinux-2 23 | driver: 24 | image: dokken/amazonlinux-2 25 | pid_one_command: /usr/lib/systemd/systemd 26 | 27 | - name: debian-8 28 | driver: 29 | image: dokken/debian-8 30 | pid_one_command: /bin/systemd 31 | intermediate_instructions: 32 | - RUN /usr/bin/apt-get update 33 | 34 | - name: debian-9 35 | driver: 36 | image: dokken/debian-9 37 | pid_one_command: /bin/systemd 38 | intermediate_instructions: 39 | - RUN /usr/bin/apt-get update 40 | 41 | - name: centos-6 42 | driver: 43 | image: dokken/centos-6 44 | pid_one_command: /sbin/init 45 | 46 | - name: centos-7 47 | driver: 48 | image: dokken/centos-7 49 | pid_one_command: /usr/lib/systemd/systemd 50 | 51 | - name: fedora-latest 52 | driver: 53 | image: dokken/fedora-latest 54 | pid_one_command: /usr/lib/systemd/systemd 55 | 56 | - name: ubuntu-16.04 57 | driver: 58 | image: dokken/ubuntu-16.04 59 | pid_one_command: /bin/systemd 60 | intermediate_instructions: 61 | - RUN /usr/bin/apt-get update 62 | 63 | - name: ubuntu-18.04 64 | driver: 65 | image: dokken/ubuntu-18.04 66 | pid_one_command: /bin/systemd 67 | intermediate_instructions: 68 | - RUN /usr/bin/apt-get update 69 | 70 | - name: opensuse-leap 71 | driver: 72 | image: dokken/opensuse-leap-42 73 | pid_one_command: /bin/systemd 74 | -------------------------------------------------------------------------------- /kitchen.yml: -------------------------------------------------------------------------------- 1 | driver: 2 | name: vagrant 3 | 4 | provisioner: 5 | name: chef_zero 6 | deprecations_as_errors: true 7 | 8 | verifier: 9 | name: inspec 10 | 11 | platforms: 12 | - name: amazonlinux-2 13 | - name: centos-6 14 | - name: centos-7 15 | - name: debian-8 16 | - name: debian-9 17 | - name: fedora-28 18 | - name: freebsd-11 19 | - name: opensuse-leap-42 20 | - name: ubuntu-16.04 21 | - name: ubuntu-18.04 22 | - name: windows-2016 23 | driver: 24 | box: chef/windows-server-2016-standard 25 | 26 | suites: 27 | - name: default 28 | run_list: 29 | - recipe[test] 30 | -------------------------------------------------------------------------------- /metadata.rb: -------------------------------------------------------------------------------- 1 | name 'libarchive' 2 | maintainer 'Chef Software, Inc.' 3 | maintainer_email 'cookbooks@chef.io' 4 | license 'Apache-2.0' 5 | description 'A library cookbook for extracting archive files' 6 | long_description 'A library cookbook for extracting archive files' 7 | version '2.1.0' 8 | 9 | %w(windows ubuntu debian redhat centos suse opensuse opensuseleap scientific oracle amazon).each do |os| 10 | supports os 11 | end 12 | 13 | source_url 'https://github.com/chef-cookbooks/libarchive' 14 | issues_url 'https://github.com/chef-cookbooks/libarchive/issues' 15 | chef_version '>= 14.0' 16 | 17 | gem 'ffi-libarchive' 18 | -------------------------------------------------------------------------------- /recipes/default.rb: -------------------------------------------------------------------------------- 1 | Chef::Log.warn('The libarchive::default recipe is no longer needed and should not be included on runlists') 2 | -------------------------------------------------------------------------------- /resources/file.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Cookbook Name:: libarchive 3 | # Resource:: file 4 | # 5 | # Copyright:: 2017-2018 Chef Software, Inc. 6 | # Author:: Jamie Winsor () 7 | # Author:: Tim Smith () 8 | # 9 | 10 | resource_name :archive_file 11 | provides :libarchive_file 12 | 13 | description 'Use the archive_file resource to extract archive files to disk. This resource uses the libarchive library to extract multiple archive formats including tar, gzip, bzip, and zip formats.' 14 | 15 | property :path, String, 16 | name_property: true, 17 | coerce: proc { |f| ::File.expand_path(f) }, 18 | description: "An optional property to set the file path to the archive to extract if it differs from the resource block's name." 19 | 20 | property :owner, String, 21 | description: 'The owner of the extracted files.' 22 | 23 | property :group, String, 24 | description: 'The group of the extracted files.' 25 | 26 | property :mode, [String, Integer], 27 | description: 'The mode of the extracted files.', 28 | default: '755' 29 | 30 | property :destination, String, 31 | description: 'The file path to extract the archive file to.', 32 | required: true 33 | 34 | property :options, [Array, Symbol], 35 | description: 'An array of symbols representing extraction flags. Example: :no_overwrite to prevent overwriting files on disk. By default this properly sets :time which preserves the modification timestamps of files in the archive when writing them to disk.', 36 | default: lazy { [:time] } 37 | 38 | property :overwrite, [TrueClass, FalseClass, :auto], 39 | description: 'Should the resource overwrite the destination file contents if they already exist? If set to :auto the date stamp of files within the archive will be compared to those on disk and disk contents will be overwritten if they differ. This may cause unintented consequences if on disk date stamps are changed between runs, which will result in the files being overwritten during each client run. Make sure to properly test any change to this property.', 40 | default: false 41 | 42 | # backwards compatibility for the legacy names when we only had an :extract action 43 | alias_method :extract_options, :options 44 | alias_method :extract_to, :destination 45 | 46 | require 'fileutils' 47 | 48 | action :extract do 49 | description 'Extract and archive file.' 50 | 51 | unless ::File.exist?(new_resource.path) 52 | raise Errno::ENOENT, "No archive found at #{new_resource.path}! Cannot continue." 53 | end 54 | 55 | if !::File.exist?(new_resource.destination) 56 | Chef::Log.trace("File or directory does not exist at destination path: #{new_resource.destination}") 57 | 58 | converge_by("create directory #{new_resource.destination}") do 59 | FileUtils.mkdir_p(new_resource.destination, mode: new_resource.mode.to_i) 60 | end 61 | 62 | extract(new_resource.path, new_resource.destination, Array(new_resource.options)) 63 | else 64 | Chef::Log.trace("File or directory exists at destination path: #{new_resource.destination}.") 65 | 66 | if new_resource.overwrite == true || 67 | (new_resource.overwrite == :auto && archive_differs_from_disk?(new_resource.path, new_resource.destination)) 68 | Chef::Log.debug("Overwriting existing content at #{new_resource.destination} due to resource's overwrite property settings.") 69 | 70 | extract(new_resource.path, new_resource.destination, Array(new_resource.options)) 71 | else 72 | Chef::Log.debug("Not extracting archive as #{new_resource.destination} exists and resource not set to overwrite.") 73 | end 74 | end 75 | 76 | if new_resource.owner || new_resource.group 77 | converge_by("set owner of #{new_resource.destination} to #{new_resource.owner}:#{new_resource.group}") do 78 | FileUtils.chown_R(new_resource.owner, new_resource.group, new_resource.destination) 79 | end 80 | end 81 | end 82 | 83 | action_class do 84 | # This can't be a constant since we might not have required 'ffi-libarchive' yet. 85 | def extract_option_map 86 | { 87 | owner: Archive::EXTRACT_OWNER, 88 | permissions: Archive::EXTRACT_PERM, 89 | time: Archive::EXTRACT_TIME, 90 | no_overwrite: Archive::EXTRACT_NO_OVERWRITE, 91 | acl: Archive::EXTRACT_ACL, 92 | fflags: Archive::EXTRACT_FFLAGS, 93 | extended_information: Archive::EXTRACT_XATTR, 94 | xattr: Archive::EXTRACT_XATTR, 95 | no_overwrite_newer: Archive::EXTRACT_NO_OVERWRITE_NEWER, 96 | } 97 | end 98 | 99 | # try to determine if the resource has updated or not by checking for files that are in the 100 | # archive, but not on disk or files with a non-matching mtime 101 | # 102 | # @param [String] src 103 | # @param [String] dest 104 | # 105 | # @return [Boolean] 106 | def archive_differs_from_disk?(src, dest) 107 | require 'ffi-libarchive' 108 | 109 | modified = false 110 | Dir.chdir(dest) do 111 | archive = Archive::Reader.open_filename(src) 112 | Chef::Log.trace("Beginning the comparison of file mtime between contents of #{src} and #{dest}") 113 | archive.each_entry do |e| 114 | pathname = ::File.expand_path(e.pathname) 115 | if ::File.exist?(pathname) 116 | Chef::Log.trace("#{pathname} mtime is #{::File.mtime(pathname)} and archive is #{e.mtime}") 117 | modified = true unless ::File.mtime(pathname) == e.mtime 118 | else 119 | Chef::Log.trace("#{pathname} doesn't exist on disk, but exists in the archive") 120 | modified = true 121 | end 122 | end 123 | end 124 | modified 125 | end 126 | 127 | # extract the archive 128 | # 129 | # @param [String] src 130 | # @param [String] dest 131 | # @param [Array] options 132 | # 133 | # @return [void] 134 | def extract(src, dest, options = []) 135 | require 'ffi-libarchive' 136 | 137 | converge_by("extract #{src} to #{dest}") do 138 | flags = [options].flatten.map { |option| extract_option_map[option] }.compact.reduce(:|) 139 | 140 | Dir.chdir(dest) do 141 | archive = Archive::Reader.open_filename(src) 142 | 143 | archive.each_entry do |e| 144 | archive.extract(e, flags.to_i) 145 | end 146 | archive.close 147 | end 148 | end 149 | end 150 | end 151 | -------------------------------------------------------------------------------- /spec/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chef-boneyard/libarchive/afd9eafa37454c64edf9919ebb0e5ad5fbac59fb/spec/.gitkeep -------------------------------------------------------------------------------- /test/cookbooks/test/files/tourism.tar.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chef-boneyard/libarchive/afd9eafa37454c64edf9919ebb0e5ad5fbac59fb/test/cookbooks/test/files/tourism.tar.gz -------------------------------------------------------------------------------- /test/cookbooks/test/files/tourism.tar.xz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chef-boneyard/libarchive/afd9eafa37454c64edf9919ebb0e5ad5fbac59fb/test/cookbooks/test/files/tourism.tar.xz -------------------------------------------------------------------------------- /test/cookbooks/test/files/tourism.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chef-boneyard/libarchive/afd9eafa37454c64edf9919ebb0e5ad5fbac59fb/test/cookbooks/test/files/tourism.zip -------------------------------------------------------------------------------- /test/cookbooks/test/metadata.rb: -------------------------------------------------------------------------------- 1 | name 'test' 2 | version '0.0.1' 3 | depends 'libarchive' 4 | -------------------------------------------------------------------------------- /test/cookbooks/test/recipes/default.rb: -------------------------------------------------------------------------------- 1 | %w(tourism.tar.gz tourism.tar.xz tourism.zip).each do |archive| 2 | cookbook_file File.join(Chef::Config[:file_cache_path], archive) do 3 | source archive 4 | end 5 | 6 | archive_file archive do 7 | path File.join(Chef::Config[:file_cache_path], archive) 8 | extract_to File.join(Chef::Config[:file_cache_path], archive.gsub('.', '_')) 9 | end 10 | end 11 | --------------------------------------------------------------------------------