module Zipr
Public Instance Methods
checksums_folder()
click to toggle source
# File lib/zipr/helper.rb, line 59 def checksums_folder "#{@cache_path}/zipr/archive_checksums" end
config()
click to toggle source
# File lib/zipr/config.rb, line 4 def config @config ||= EasyJSON.config(defaults: defaults) end
defaults()
click to toggle source
# File lib/zipr/config.rb, line 8 def defaults { 'paths' => { 'cache' => Dir.tmpdir, }, } end
flattened_paths(source_folder, files)
click to toggle source
returns results of all files found in the array of files, including files found by wildcard, as relative paths.
# File lib/zipr/helper.rb, line 21 def flattened_paths(source_folder, files) return files if source_folder.nil? || source_folder.empty? result = [] source_folder_glob = nil files.each do |entry| if entry.is_a?(Regexp) source_folder_glob ||= Dir.glob("#{source_folder.tr('\\', '/')}/**/*") matched_files = source_folder_glob.select { |path| path =~ entry } result += matched_files.map { |f| slice_source_folder(source_folder, f) } next end standardized_entry = "#{source_folder.tr('\\', '/')}/#{slice_source_folder(source_folder, entry)}" files_found = Dir.glob(standardized_entry) if files_found.empty? result.push(entry) else result += files_found.map { |f| slice_source_folder(source_folder, f) } end end result end
prepend_source_folder(source_folder, entry)
click to toggle source
# File lib/zipr/helper.rb, line 50 def prepend_source_folder(source_folder, entry) return entry.tr('\\', '/') if source_folder.nil? || source_folder.empty? || entry.tr('\\', '/').start_with?(source_folder.tr('\\', '/')) "#{source_folder.tr('\\', '/')}/#{entry.tr('\\', '/')}" end
seven_zip_exe_from_registry()
click to toggle source
# File lib/zipr/helper.rb, line 12 def seven_zip_exe_from_registry key_path = 'SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\7zFM.exe' return nil unless EasyIO::Registry.key_exists?(key_path) # Read path from recommended Windows App Paths registry location # docs: https://msdn.microsoft.com/en-us/library/windows/desktop/ee872121 EasyIO::Registry.read(key_path, 'Path') end
seven_zip_executable_path()
click to toggle source
# File lib/zipr/helper.rb, line 4 def seven_zip_executable_path path = node['seven_zip']['home'] EasyIO.logger.debug "7-zip home: '#{path}'" unless path.nil? path ||= seven_zip_exe_from_registry if OS.windows? EasyIO.logger.debug "7-zip path: '#{path}'" ::File.join(path, OS.windows? ? '7z.exe' : '7z') end
slice_source_folder(source_folder, entry)
click to toggle source
# File lib/zipr/helper.rb, line 55 def slice_source_folder(source_folder, entry) entry.tr('\\', '/').sub(source_folder.tr('\\', '/'), '').reverse.chomp('/').reverse end
wildcard_to_regexp(entry)
click to toggle source
# File lib/zipr/helper.rb, line 44 def wildcard_to_regexp(entry) return entry if entry.is_a?(Regexp) escaped_entry = Regexp.escape(entry).gsub(/\\\*/, '.*') # Convert asterisks to .* /#{escaped_entry}/ end