Class: Machinery::Rpm

Inherits:
Object show all
Defined in:
lib/rpm.rb

Overview

Rpm represents an RPM package on the disk.

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ Rpm

Returns a new instance of Rpm.



20
21
22
# File 'lib/rpm.rb', line 20

def initialize(path)
  @path = path
end

Instance Method Details

#diff(file, local_file) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/rpm.rb', line 24

def diff(file, local_file)
  begin
    cpio = Machinery::LoggedCheetah.run("rpm2cpio", @path, stdout: :capture)
    original_config = Machinery::LoggedCheetah.run(
      "cpio", "-iv", "--to-stdout", ".#{file}", stdin: cpio, stdout: :capture
    )
  rescue Cheetah::ExecutionFailed => e
    Machinery.logger.error(e.stderr)
    return nil
  end

  begin
    Machinery::LoggedCheetah.run(
      "diff", "-u", "--label", "#{File.join("a", file)}", "--from-file=-",
       "--label", "#{File.join("b", file)}", local_file,
      stdin: original_config,
      stdout: :capture
    )
  rescue Cheetah::ExecutionFailed => e
    # diff exits with 1 when there are changes
    if e.status.exitstatus == 1
      e.stdout
    else
      Machinery.logger.error(e.stderr)
      return nil
    end
  end
end