class WinRM::FS::Core::ShellZipFactory

Creates a zip file by shelling out to the zip command

Attributes

basedir[R]
options[R]
paths[R]
zip_definition[R]
zip_file[R]

Public Class Methods

new(zip_definition) click to toggle source
# File lib/winrm-fs/core/temp_zip_file.rb, line 79
def initialize(zip_definition)
  @zip_definition = zip_definition
  @zip_file = zip_definition.zip_file
  @basedir = zip_definition.basedir
  @paths = zip_definition.paths
  @options = build_options.push('--names-stdin').join(' ')
end

Public Instance Methods

build() click to toggle source
# File lib/winrm-fs/core/temp_zip_file.rb, line 87
def build
  Dir.chdir(basedir) do
    # zip doesn't like the file that already exists
    output = %x`zip #{zip_definition.path}.tmp #{options} < #{write_file_list.path}`
    fail "zip command failed: #{output}" unless $CHILD_STATUS.success?

    FileUtils.mv("#{zip_definition.path}.tmp", "#{zip_definition.path}")
  end
end

Private Instance Methods

build_options() click to toggle source
# File lib/winrm-fs/core/temp_zip_file.rb, line 106
def build_options
  zip_definition.options.map do | key, value |
    prefix = key.length > 1 ? '--' : '-'
    if value == true
      "#{prefix}#{key}"
    else
      "#{prefix}#{key} #{value}"
    end
  end
end
write_file_list() click to toggle source
# File lib/winrm-fs/core/temp_zip_file.rb, line 99
def write_file_list
  file_list = Tempfile.new('file_list')
  file_list.puts paths.join("\n")
  file_list.close
  file_list
end