Class: Puppet::ModuleTool::Tar::Mini

Inherits:
Object
  • Object
show all
Defined in:
lib/puppet/module_tool/tar/mini.rb

Instance Method Summary collapse

Instance Method Details

#pack(sourcedir, destfile) ⇒ Object


32
33
34
35
36
37
38
39
40
41
# File 'lib/puppet/module_tool/tar/mini.rb', line 32

def pack(sourcedir, destfile)
  Zlib::GzipWriter.open(destfile) do |writer|
    Archive::Tar::Minitar.pack(sourcedir, writer) do |step, name, stats|
      # TODO smcclellan 2017-10-31 Set permissions here when this yield block
      # executes before the header is written. As it stands, the `stats`
      # argument isn't mutable in a way that will effect the desired mode for
      # the file.
    end
  end
end

#unpack(sourcefile, destdir, _) ⇒ Object


2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/puppet/module_tool/tar/mini.rb', line 2

def unpack(sourcefile, destdir, _)
  Zlib::GzipReader.open(sourcefile) do |reader|
    # puppet doesn't have a hard dependency on minitar, so we
    # can't be certain which version is installed. If it's 0.9
    # or above then we can prevent minitar from fsync'ing each
    # extracted file and directory, otherwise fallback to the
    # old behavior
    args = [reader, destdir, find_valid_files(reader)]
    spec = Gem::Specification.find_by_name('minitar')
    if spec && spec.version >= Gem::Version.new('0.9')
      args << {:fsync => false}
    end
    Archive::Tar::Minitar.unpack(*args) do |action, name, stats|
      case action
      when :dir
        validate_entry(destdir, name)
        set_dir_mode!(stats)
        Puppet.debug("Extracting: #{destdir}/#{name}")
      when :file_start
        # Octal string of the old file mode.
        validate_entry(destdir, name)
        set_file_mode!(stats)
        Puppet.debug("Extracting: #{destdir}/#{name}")
      end
      set_default_user_and_group!(stats)
      stats
    end
  end
end