summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Green <tgreen@opscode.com>2012-07-20 19:15:34 -0400
committerjtimberman <joshua@opscode.com>2012-08-06 14:30:05 -0600
commitb41a4c42acf43d84f7a35bc2e5523c62e5be8323 (patch)
treedfabbdca1e4b61059ddf433cf0d371d0def39c13
parent7624b1e4569525bcb2608f233ad2b9f46524d217 (diff)
downloadmixlib-shellout-b41a4c42acf43d84f7a35bc2e5523c62e5be8323.tar.gz
use constants and refactor windows path processing.
-rw-r--r--providers/zipfile.rb20
1 files changed, 10 insertions, 10 deletions
diff --git a/providers/zipfile.rb b/providers/zipfile.rb
index 5b43dcf..c34abce 100644
--- a/providers/zipfile.rb
+++ b/providers/zipfile.rb
@@ -43,6 +43,9 @@ end
action :zip do
ensure_rubyzip_gem_installed
+ # sanitize paths for windows.
+ @new_resource.source.downcase.gsub!(::File::SEPARATOR, ::File::ALT_SEPARATOR)
+ @new_resource.path.downcase.gsub!(::File::SEPARATOR, ::File::ALT_SEPARATOR)
Chef::Log.debug("zip #{@new_resource.source} => #{@new_resource.path} (overwrite=#{@new_resource.overwrite})")
if @new_resource.overwrite == false && ::File.exists?(@new_resource.path)
@@ -52,21 +55,18 @@ action :zip do
if ::File.exists?(@new_resource.path)
::File.unlink(@new_resource.path)
end
- # Only supporting compression of a single directory (recursively).
+ # only supporting compression of a single directory (recursively).
if ::File.directory?(@new_resource.source)
z = Zip::ZipFile.new(@new_resource.path, true)
- unless @new_resource.source =~ /\/$/
- @new_resource.source << '\\'
+ unless @new_resource.source =~ /::File::ALT_SEPARATOR$/
+ @new_resource.source << ::File::ALT_SEPARATOR
end
Find.find(@new_resource.source) do |f|
- f = f.downcase.gsub(/\\/, '/')
- source = @new_resource.source.downcase.gsub(/\\/, '/')
- # ignore the root directory.
- next if f == source
+ f.downcase.gsub!(::File::SEPARATOR, ::File::ALT_SEPARATOR)
+ # don't add root directory to the zipfile.
+ next if f == @new_resource.source
# strip the root directory from the filename before adding it to the zipfile.
- zip_fname = f.sub(/#{source}/, '')
- zip_fname.gsub!(/\//, '\\')
- f = f.downcase.gsub(/\//, '\\')
+ zip_fname = f.sub(@new_resource.source, '')
Chef::Log.debug("adding #{zip_fname} to archive, sourcefile is: #{f}")
z.add(zip_fname, f)
end