Module: ChangedRpmFilesHelper

Defined in:
lib/changed_rpm_files_helper.rb

Overview

Copyright © 2013-2015 SUSE LLC

This program is free software; you can redistribute it and/or modify it under the terms of version 3 of the GNU General Public License as published by the Free Software Foundation.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, contact SUSE LLC.

To contact SUSE about this file by physical or electronic mail, you may find current contact information at www.suse.com

Instance Method Summary collapse

Instance Method Details

#expected_tag?(character, position) ⇒ Boolean

Returns:

  • (Boolean)


19
20
21
22
23
24
25
26
# File 'lib/changed_rpm_files_helper.rb', line 19

def expected_tag?(character, position)
  if @rpm_changes[position] == character
    true
  else
    @unknown_tag ||= ![".", "?"].include?(@rpm_changes[position])
    false
  end
end

#get_file_properties(system, cur_files) ⇒ Object

get path data for list of files cur_files is guaranteed to not exceed max command line length



88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/changed_rpm_files_helper.rb', line 88

def get_file_properties(system, cur_files)
  ret = {}
  out = system.run_command(
      "stat", "--printf", "%a:%U:%G:%u:%g:%n\\n",
      *cur_files,
      :stdout => :capture
  )
  out.each_line do |l|
    path, values = parse_stat_line(l)
    ret[path] = values
  end
  ret
end

#get_path_data(system, paths) ⇒ Object



102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/changed_rpm_files_helper.rb', line 102

def get_path_data(system, paths)
  ret = {}
  path_index = 0
  # arbitrary number for maximum command line length that should always work
  max_len = 50000
  cur_files = []
  cur_len = 0
  while path_index < paths.size
    if cur_files.empty? || paths[path_index].size + cur_len + 1 < max_len
      cur_files << paths[path_index]
      cur_len += paths[path_index].size + 1
      path_index += 1
    else
      ret.merge!(get_file_properties(system, cur_files))
      cur_files.clear
      cur_len = 0
    end
  end
  ret.merge!(get_file_properties(system, cur_files)) unless cur_files.empty?
  ret
end

#parse_rpm_changes_line(line) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/changed_rpm_files_helper.rb', line 28

def parse_rpm_changes_line(line)
  # rpm provides lines per config file where first 9 characters indicate which
  # properties of the file are modified
  @rpm_changes, *fields = line.split(" ")
  # nine rpm changes are known
  @unknown_tag = @rpm_changes.size > 9

  # For config or documentation files there's an additional field which
  # contains "c" or "d"
  type = fields[0].start_with?("/") ? "" : fields.shift
  path = fields.join(" ")

  changes = []
  if @rpm_changes == "missing"
    changes << "deleted"
  elsif @rpm_changes == "........." && path.end_with?(" (replaced)")
    changes << "replaced"
    path.slice!(/ \(replaced\)$/)
  else
    changes << "size" if expected_tag?("S", 0)
    changes << "mode" if expected_tag?("M", 1)
    changes << "md5" if expected_tag?("5", 2)
    changes << "device_number" if expected_tag?("D", 3)
    changes << "link_path" if expected_tag?("L", 4)
    changes << "user" if expected_tag?("U", 5)
    changes << "group" if expected_tag?("G", 6)
    changes << "time" if expected_tag?("T", 7)
    changes << "capabilities" if @rpm_changes.size > 8 && expected_tag?("P", 8)
  end

  if @unknown_tag
    changes << "other_rpm_changes"
  end

  if @rpm_changes.include?("?")
    message = "Could not perform all tests on rpm changes for file '#{path}'."
    Machinery.logger.warn(message)
    Machinery::Ui.warn("Warning: #{message}")
  end

  [path, changes, type]
end

#parse_stat_line(line) ⇒ Object



71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/changed_rpm_files_helper.rb', line 71

def parse_stat_line(line)
  mode, user, group, uid, gid, *path = line.split(":")

  user = uid if user == "UNKNOWN"
  group = gid if group == "UNKNOWN"

  [path.join(":").chomp,
    {
      :mode  => mode,
      :user  => user,
      :group => group
    }
  ]
end