lib/mcollective/util.rb in mcollective-client-2.7.0 vs lib/mcollective/util.rb in mcollective-client-2.8.0

- old
+ new

@@ -153,31 +153,31 @@ end # Picks a config file defaults to ~/.mcollective # else /etc/mcollective/client.cfg def self.config_file_for_user - # expand_path is pretty lame, it relies on HOME environment - # which isnt't always there so just handling all exceptions - # here as cant find reverting to default + # the set of acceptable config files + config_paths = [] + + # user dotfile begin - config = File.expand_path("~/.mcollective") + # File.expand_path will raise if HOME isn't set, catch it + user_path = File.expand_path("~/.mcollective") + config_paths << user_path + rescue Exception + end - unless File.readable?(config) && File.file?(config) - if self.windows? - config = File.join(self.windows_prefix, "etc", "client.cfg") - else - config = "/etc/mcollective/client.cfg" - end - end - rescue Exception => e - if self.windows? - config = File.join(self.windows_prefix, "etc", "client.cfg") - else - config = "/etc/mcollective/client.cfg" - end + # standard locations + if self.windows? + config_paths << File.join(self.windows_prefix, 'etc', 'client.cfg') + else + config_paths << '/etc/puppetlabs/agent/mcollective/client.cfg' + config_paths << '/etc/mcollective/client.cfg' end - return config + # use the first readable config file, or if none are the first listed + found = config_paths.find_index { |file| File.readable?(file) } || 0 + return config_paths[found] end # Creates a standard options hash def self.default_options {:verbose => false,