Class: Bosh::Director::Core::TarGzipper

Inherits:
Object
  • Object
show all
Defined in:
lib/bosh/director/core/tar_gzipper.rb

Instance Method Summary collapse

Instance Method Details

#compress(base_dir, sources, dest, options = {}) ⇒ Object

Parameters:

  • base_dir (String)

    the directory from which the tar command is run

  • sources (String, Array)

    the relative paths to include

  • dest (String)

    the destination filename for the tgz output

  • options (Hash) (defaults to: {})

    the options for compress

Options Hash (options):

  • :copy_first (Boolean)

    copy the source to a temp dir before archiving



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/bosh/director/core/tar_gzipper.rb', line 11

def compress(base_dir, sources, dest, options = {})
  sources = [*sources]
  sources.each do |source|
    source = source.gsub(%r(^\./), '')
    if source.include?(File::SEPARATOR)
      raise "Sources must have a path depth of 1 and contain no '#{File::SEPARATOR}'"
    end
  end

  base_dir_path = Pathname.new(base_dir)
  raise "The base directory #{base_dir} could not be found." unless base_dir_path.exist?
  raise "The base directory #{base_dir} is not an absolute path." unless base_dir_path.absolute?

  if options[:copy_first]
    Dir.mktmpdir do |tmpdir|
      FileUtils.cp_r(sources.map { |s| File.join(base_dir, s) }, "#{tmpdir}/")
      tar(tmpdir, dest, sources)
    end
  else
    tar(base_dir, dest, sources)
  end
end