Skip to content

Commit

Permalink
Fix bug where unset HOME would cause chef to crash
Browse files Browse the repository at this point in the history
Issue chef#3153
When running chef with HOME unset (going to be a common case on
the nixs), Chef will crash when it uses the all_homes function.
  • Loading branch information
jaym committed Mar 27, 2015
1 parent eaa56e5 commit 9b8f47c
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/chef/util/path_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -196,19 +196,19 @@ def self.all_homes(*args)
paths << ENV['HOMESHARE'] + ENV['HOMEPATH'] if ENV['HOMESHARE'] && ENV['HOMEPATH']
paths << ENV['USERPROFILE']
end
paths << Dir.home
paths << Dir.home if ENV['HOME']

# Depending on what environment variables we're using, the slashes can go in any which way.
# Just change them all to / to keep things consistent.
# Note: Maybe this is a bad idea on some unixy systems where \ might be a valid character depending on
# the particular brand of kool-aid you consume. This code assumes that \ and / are both
# path separators on any system being used.
paths = paths.map { |home_path| home_path.gsub(path_separator, ::File::SEPARATOR) if home_path }

# Filter out duplicate paths and paths that don't exist.
valid_paths = paths.select { |home_path| home_path && Dir.exists?(home_path) }
valid_paths = valid_paths.uniq

# Join all optional path elements at the end.
# If a block is provided, invoke it - otherwise just return what we've got.
joined_paths = valid_paths.map { |home_path| File.join(home_path, *args) }
Expand Down

0 comments on commit 9b8f47c

Please sign in to comment.