manageiq-smartstate 0.5.4 → 0.5.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a0ef0a15e10489e8bc2a06cf1cf8a1732fc9cade
4
- data.tar.gz: db6e93260808919d00578cfdfb1251fae213016d
3
+ metadata.gz: cd8eb1fbab5fe0cf25e935e7173c43f6cb928b36
4
+ data.tar.gz: 6254ef672dd4700f40da31c1b4c98d79b7217510
5
5
  SHA512:
6
- metadata.gz: 6f85a2daa2ed024ef55f16bdf88ae9d713a4d0ca705fd4d57ddd13b0fdaa87d6f68273a6fc8b41f337bd6a63e4f4618a3c5348d073d6c8861362f9b1cb49eaf7
7
- data.tar.gz: 68a90dea48f0a0ceefed907e16701c0fe495bfacc46652763046328c3acdc71a899aa4e6348c7bb9300f0ada79d56dd214fefcb41c5c62e1fdb11a94e2474fa4
6
+ metadata.gz: eaa532b372c70837dfaf164ba463374a6235291e5517385469be72d95e6fc60dd3cdb957ac32d1f7ecdb14f87a372785bbe196a10a43d995129906203d38de89
7
+ data.tar.gz: bba8041436423755f0a234c566168a7831159da571605638290789a3f9e7246fdda6e75912a2bc9d3b50f1ef236fed74094c284369357a3fc4c2184326642951
@@ -1,5 +1,5 @@
1
1
  module ManageIQ
2
2
  module Smartstate
3
- VERSION = "0.5.4".freeze
3
+ VERSION = "0.5.5".freeze
4
4
  end
5
5
  end
@@ -0,0 +1,132 @@
1
+ module FindClassMethods
2
+ # Return directory entries matching specified glob pattern
3
+ #
4
+ # @param glob_pattern [String] pattern to match
5
+ # @param flags [Integer] file match flags
6
+ # @yield block invoked with each match if specified
7
+ #
8
+ # @see VfsRealFile.fnmatch
9
+ # @see FindClassMethods#dir_and_glob which does most of the work regarding globbing
10
+ # @see FindClassMethods#find which retrieves stats information & dir entries for found files
11
+ #
12
+ def self.glob(glob_pattern, filesys, flags = 0)
13
+ @fs = filesys
14
+ return [] unless (glob = dir_and_glob(glob_pattern))
15
+
16
+ ra = []
17
+ find(@search_path, glob_depth(glob)) do |p|
18
+ p = check_file(p, glob, flags)
19
+ p && block_given? ? yield(p) : ra << p
20
+ end
21
+ ra.sort_by(&:downcase)
22
+ end
23
+
24
+ #
25
+ # Determine if the file returned from "find" will be used or skipped.
26
+ #
27
+ def self.check_file(file, glob, flags)
28
+ return nil if file == @search_path
29
+
30
+ if @search_path == File::SEPARATOR
31
+ file.sub!(File::SEPARATOR, "")
32
+ else
33
+ file.sub!("#{@search_path}#{File::SEPARATOR}", "")
34
+ end
35
+
36
+ return nil if file == "" || !File.fnmatch(glob, file, flags)
37
+
38
+ @specified_path ? File.join(@specified_path, file) : file
39
+ end
40
+
41
+ #
42
+ # Modified version of Find.find:
43
+ # - Accepts only a single path.
44
+ # - Can be restricted by depth - optimization for glob searches.
45
+ #
46
+ # @param path [String] starting directory of the find
47
+ # @param max_depth [Integer] max number of levels to decend befroelookup
48
+ # @yield files found
49
+ #
50
+ def self.find(path, max_depth = nil)
51
+ block_given? || (return enum_for(__method__, path, max_depth))
52
+
53
+ depths = [0]
54
+ paths = [path.dup]
55
+
56
+ while (file = paths.shift)
57
+ depth = depths.shift
58
+ yield file.dup.taint
59
+ next if max_depth && depth + 1 > max_depth
60
+
61
+ get_dir_entries(file).each do |f|
62
+ f = File.join(file, f)
63
+ paths.unshift f.untaint
64
+ depths.unshift depth + 1
65
+ end
66
+ end
67
+ end
68
+
69
+ def self.get_dir_entries(directory)
70
+ return [] unless @fs.fileExists?(directory) && @fs.fileDirectory?(directory)
71
+
72
+ files = @fs.dirEntries(directory)
73
+ files.difference([".", ".."])
74
+ files.sort!
75
+ files.reverse_each
76
+ rescue Errno::ENOENT, Errno::EACCES, Errno::ENOTDIR, Errno::ELOOP, Errno::ENAMETOOLONG
77
+ $log.info "find: while-loop @fs.dirEntries #{directory} returned an error"
78
+ []
79
+ end
80
+
81
+ GLOB_CHARS = '*?[{'.freeze
82
+ def self.glob_str?(str)
83
+ str.gsub(/\\./, "X").count(GLOB_CHARS) != 0
84
+ end
85
+
86
+ # Returns files matching glob pattern
87
+ #
88
+ # @api private
89
+ # @param glob_pattern [String,Regex] pattern to search for
90
+ # @return [String] paths to files found
91
+ #
92
+ def self.dir_and_glob(glob_pattern)
93
+ stripped_path = glob_pattern.sub(/^[a-zA-Z]:/, "")
94
+ glob_path = Pathname.new(stripped_path)
95
+ @search_path = File::SEPARATOR
96
+ @specified_path = File::SEPARATOR
97
+
98
+ unless glob_path.absolute?
99
+ @search_path = Dir.getwd
100
+ @specified_path = nil
101
+ end
102
+
103
+ components = path_components(glob_path)
104
+ @search_path = File.expand_path(@search_path, "/")
105
+ @fs.fileExists?(@search_path) ? File.join(components) : nil
106
+ end
107
+
108
+ def self.path_components(glob_path, search_path = @search_path)
109
+ components = glob_path.each_filename.to_a
110
+ while (comp = components.shift)
111
+ if glob_str?(comp)
112
+ components.unshift(comp)
113
+ break
114
+ end
115
+ @search_path = File.join(search_path, comp)
116
+ @specified_path = @specified_path ? File.join(@specified_path, comp) : comp
117
+ end
118
+ components
119
+ end
120
+
121
+ # Return max levels which glob pattern may resolve to
122
+ #
123
+ # @api private
124
+ # @param glob_pattern [String,Regex] pattern to search for
125
+ # @return [Integer] max levels which pattern may match
126
+ def self.glob_depth(glob_pattern)
127
+ path_components = Pathname(glob_pattern).each_filename.to_a
128
+ return nil if path_components.include?('**')
129
+
130
+ path_components.length
131
+ end
132
+ end
@@ -1,6 +1,7 @@
1
1
  require 'time'
2
2
  require 'metadata/util/win32/peheader'
3
3
  require 'metadata/util/win32/versioninfo'
4
+ require 'metadata/util/find_class_methods'
4
5
  require 'util/miq-xml'
5
6
  require 'ostruct'
6
7
  require 'util/miq-encode'
@@ -54,29 +55,35 @@ class MD5deep
54
55
  def scan_glob(filename)
55
56
  filename.tr!("\\", "/")
56
57
  startDir = File.dirname(filename)
57
- globPattern = File.basename(filename)
58
58
  @xml.root.add_attribute("base_path", startDir)
59
- @fs.chdir(startDir)
59
+ path_prefix = startDir[0, 2]
60
+ @drive_letter = path_prefix.match?(/^\w\:/) ? path_prefix : ""
60
61
 
61
62
  # First check if we are passed a fully qualifed file name
62
63
  if @fs.fileExists?(filename)
63
- isDir?(filename) ? process_dir_as_file(startDir, globPattern, @xml.root) : processFile(startDir, globPattern, @xml.root)
64
+ base_file = File.basename(filename)
65
+ isDir?(filename) ? process_dir_as_file(startDir, base_file, @xml.root) : processFile(startDir, base_file, @xml.root)
64
66
  else
65
67
  # If the file is not found then process the data as a glob pattern.
66
- @fs.dirGlob(globPattern) do |f|
67
- # $log.info "Glob file found: [#{f}]"
68
- # Passing "startDir" as the first parameter is a work-around for issues
69
- # when scanning Win VMs from Linux where the path returned from dirGlob
70
- # do not include the drive letter.
71
- # Below is the original line
72
- # processFile(File.dirname(f), File.basename(f), @xml.root)
73
- processFile(startDir, File.basename(f), @xml.root)
74
- end
68
+ process_each_glob_file(filename)
75
69
  end
76
70
  @xml
77
71
  end
78
72
 
73
+ def process_each_glob_file(file_name)
74
+ FindClassMethods.glob(file_name, @fs) do |f|
75
+ # Passing "startDir" as the first parameter is a work-around for issues
76
+ # when scanning Win VMs from Linux where the path returned from dirGlob
77
+ # do not include the drive letter.
78
+ processFile(File.dirname(f), File.basename(f), @xml.root)
79
+ end
80
+ rescue => err
81
+ $log.info "scan_glob: Exception #{err} rescued"
82
+ $log.debug err.backtrace.join("\n")
83
+ end
84
+
79
85
  def read_fs(path, xmlNode)
86
+ @drive_letter = @drive_letter.nil? ? "" : @drive_letter
80
87
  if @fs
81
88
  @fs.dirForeach(path) { |x| processFile(path, x, xmlNode) }
82
89
  @fs.dirForeach(path) { |x| processDir(path, x, xmlNode) }
@@ -91,7 +98,7 @@ class MD5deep
91
98
 
92
99
  def processDir(path, x, xmlNode)
93
100
  if x != "." && x != ".."
94
- currFile = File.join(path, x)
101
+ currFile = File.join(@drive_letter, path, x)
95
102
 
96
103
  begin
97
104
  if File.directory?(currFile)
@@ -110,7 +117,7 @@ class MD5deep
110
117
 
111
118
  def process_dir_as_file(path, x, xml_node)
112
119
  if x != "." && x != ".."
113
- curr_dir = File.join(path, x)
120
+ curr_dir = File.join(@drive_letter, path, x)
114
121
  if isDir?(curr_dir)
115
122
  xml_file_node = xml_node.add_element("file", "name" => x, "fqname" => curr_dir)
116
123
  stat_hash = {}
@@ -122,7 +129,7 @@ class MD5deep
122
129
 
123
130
  def processFile(path, x, xmlNode)
124
131
  if (@opts.exclude.include?(x) == false) && x[0..0] != "$"
125
- currFile = File.join(path, x)
132
+ currFile = File.join(@drive_letter, path, x)
126
133
 
127
134
  begin
128
135
  # unless File.directory?(currFile) then
@@ -150,13 +157,14 @@ class MD5deep
150
157
  fh.close if fh.kind_of?(File) && !fh.closed?
151
158
  end
152
159
  end
160
+ $log.debug "processFile: finished @xml is #{@xml}"
153
161
  end
154
162
 
155
163
  def process_pe_header(pe_hdr, xml_file_node)
156
164
  xml_file_node.add_element("versioninfo", pe_hdr.versioninfo) if @opts.versioninfo && pe_hdr.versioninfo.present?
157
165
  xml_file_node.add_element("libraries", "imports" => pe_hdr.getImportList) if @opts.imports && pe_hdr.imports.present?
158
166
  rescue TypeError => err
159
- $log.info "processFile: TypeError handling PEheader; skipping PEheader info"
167
+ $log.info "process_pe_header: TypeError handling PEheader; skipping PEheader info"
160
168
  $log.debug err.backtrace.join("\n")
161
169
  end
162
170
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: manageiq-smartstate
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.4
4
+ version: 0.5.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - ManageIQ Developers
@@ -525,6 +525,7 @@ files:
525
525
  - lib/metadata/linux/MiqConaryPackages.rb
526
526
  - lib/metadata/linux/MiqRpmPackages.rb
527
527
  - lib/metadata/util/event_log_filter.rb
528
+ - lib/metadata/util/find_class_methods.rb
528
529
  - lib/metadata/util/md5deep.rb
529
530
  - lib/metadata/util/win32/Win32Accounts.rb
530
531
  - lib/metadata/util/win32/Win32EventLog.rb