Class: Bosh::Director::TarGzipper

Inherits:
Object
  • Object
show all
Defined in:
lib/bosh/director/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
33
34
35
36
# File 'lib/bosh/director/tar_gzipper.rb', line 11

def compress(base_dir, sources, dest, options={})
  sources = [*sources]

  sources.each do |source|
    raise "Sources must have a path depth of 1 and contain no '#{File::SEPARATOR}'" if source.include?(File::SEPARATOR)
  end

  base_dir_path = Pathname.new(base_dir)

  unless base_dir_path.exist?
    raise "The base directory #{base_dir} could not be found."
  end

  unless base_dir_path.absolute?
    raise "The base directory #{base_dir} is not an absolute path."
  end

  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