Module: ChangedRpmFilesHelper

Defined in:
lib/changed_rpm_files_helper.rb

Overview

Copyright © 2013-2014 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

#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



61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/changed_rpm_files_helper.rb', line 61

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



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/changed_rpm_files_helper.rb', line 75

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



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/changed_rpm_files_helper.rb', line 19

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(" ")

  # 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 << "mode" if rpm_changes[1] == "M"
    changes << "md5" if rpm_changes[2] == "5"
    changes << "user" if rpm_changes[5] == "U"
    changes << "group" if rpm_changes[6] == "G"
  end
  [path, changes, type]
end

#parse_stat_line(line) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/changed_rpm_files_helper.rb', line 44

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