mirror of
https://github.com/inspec/inspec
synced 2024-11-23 13:13:22 +00:00
Merge pull request #5317 from vsingh-msys/VSingh/fix-dir-home
Fix issue Dir.home would break when HOME env absent
This commit is contained in:
commit
744f091ae6
1 changed files with 8 additions and 2 deletions
|
@ -1,15 +1,21 @@
|
|||
require_relative "utils/install_context"
|
||||
|
||||
module Inspec
|
||||
|
||||
extend Inspec::InstallContextHelpers
|
||||
|
||||
def self.config_dir
|
||||
ENV["INSPEC_CONFIG_DIR"] ? ENV["INSPEC_CONFIG_DIR"] : File.join(Dir.home, ".inspec")
|
||||
ENV["INSPEC_CONFIG_DIR"] || File.join(home_path, ".inspec")
|
||||
end
|
||||
|
||||
def self.src_root
|
||||
@src_root ||= File.expand_path(File.join(__FILE__, "../../.."))
|
||||
end
|
||||
|
||||
def self.home_path
|
||||
Dir.home
|
||||
rescue ArgumentError, NoMethodError
|
||||
# If ENV['HOME'] is not set, Dir.home will fail due to expanding the ~. Fallback to Etc.
|
||||
require "etc" unless defined?(Etc)
|
||||
Etc.getpwuid.dir
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue