Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions lib/puppet/gettext/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
module Puppet::GettextConfig
LOCAL_PATH = File.absolute_path('../../../locales', File.dirname(__FILE__))
POSIX_PATH = File.absolute_path('../../../../../share/locale', File.dirname(__FILE__))
RUBY_CONFIG_PATH = RbConfig::CONFIG["localedir"]
WINDOWS_PATH = File.absolute_path('../../../../../../puppet/share/locale', File.dirname(__FILE__))

# This is the only domain name that won't be a symbol, making it unique from environments.
Expand Down Expand Up @@ -194,8 +195,8 @@ def self.puppet_locale_path
LOCAL_PATH
elsif Puppet::Util::Platform.windows? && Puppet::FileSystem.exist?(WINDOWS_PATH)
WINDOWS_PATH
elsif !Puppet::Util::Platform.windows? && Puppet::FileSystem.exist?(POSIX_PATH)
POSIX_PATH
elsif !Puppet::Util::Platform.windows?
[POSIX_PATH, RUBY_CONFIG_PATH].find {|path| Puppet::FileSystem.exist?(path) }
else
nil
end
Expand All @@ -206,7 +207,7 @@ def self.puppet_locale_path
# @param [String] conf_path the path to the gettext config file
# @return [Symbol] :mo if in a package structure, :po otherwise
def self.translation_mode(conf_path)
if WINDOWS_PATH == conf_path || POSIX_PATH == conf_path
if WINDOWS_PATH == conf_path || POSIX_PATH == conf_path || RUBY_CONFIG_PATH == conf_path
:mo
else
:po
Expand Down
23 changes: 13 additions & 10 deletions lib/puppet/util/run_mode.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ def log_dir

private

def find_or_first(*dirs)
dirs.find {|d| File.directory?(d) } || dirs.first
end
##
# select the system or the user directory depending on the context of
# this process. The most common use is determining filesystem path
Expand All @@ -65,43 +68,43 @@ def which_dir(system, user)

class UnixRunMode < RunMode
def conf_dir
which_dir("/etc/puppetlabs/puppet", "~/.puppetlabs/etc/puppet")
which_dir(find_or_first("/etc/puppetlabs/puppet", "/etc/puppet"), "~/.puppetlabs/etc/puppet")
end

def code_dir
which_dir("/etc/puppetlabs/code", "~/.puppetlabs/etc/code")
which_dir(find_or_first("/etc/puppetlabs/code", "/etc/puppet/code"), "~/.puppetlabs/etc/code")
end

def var_dir
which_dir("/opt/puppetlabs/puppet/cache", "~/.puppetlabs/opt/puppet/cache")
which_dir(find_or_first("/opt/puppetlabs/puppet/cache", "/var/cache/puppet"), "~/.puppetlabs/opt/puppet/cache")
end

def public_dir
which_dir("/opt/puppetlabs/puppet/public", "~/.puppetlabs/opt/puppet/public")
which_dir(find_or_first("/opt/puppetlabs/puppet/public", "/usr/share/puppet/public"), "~/.puppetlabs/opt/puppet/public")
end

def run_dir
which_dir("/var/run/puppetlabs", "~/.puppetlabs/var/run")
which_dir(find_or_first("/var/run/puppetlabs", "/run/puppet"), "~/.puppetlabs/var/run")
end

def log_dir
which_dir("/var/log/puppetlabs/puppet", "~/.puppetlabs/var/log")
which_dir(find_or_first("/var/log/puppetlabs/puppet", "/var/log/puppet"), "~/.puppetlabs/var/log")
end

def pkg_config_path
'/opt/puppetlabs/puppet/lib/pkgconfig'
find_or_first('/opt/puppetlabs/puppet/lib/pkgconfig', "/usr/share/pkgconfig", "/usr/lib64/pkgconfig", "/usr/lib/pkgconfig")
end

def gem_cmd
'/opt/puppetlabs/puppet/bin/gem'
find_or_first('/opt/puppetlabs/puppet/bin/gem', "/usr/bin/gem")
end

def common_module_dir
'/opt/puppetlabs/puppet/modules'
find_or_first('/opt/puppetlabs/puppet/modules', "/usr/local/lib/puppet-modules")
end

def vendor_module_dir
'/opt/puppetlabs/puppet/vendor_modules'
find_or_first('/opt/puppetlabs/puppet/vendor_modules', "/usr/lib/puppet-modules")
end
end

Expand Down
6 changes: 5 additions & 1 deletion spec/unit/defaults_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,12 @@

describe 'vendormoduledir' do
it 'includes the default vendormoduledir', :unless => Puppet::Util::Platform.windows? do
@run_mode = Puppet::Util::UnixRunMode.new('fake')
allow(Puppet).to receive(:run_mode) { @run_mode }
allow(@run_mode).to receive(:find_or_first).and_return('/opt/puppetlabs/puppet/vendor_modules')

expect(
Puppet[:vendormoduledir]
Puppet.default_vendormoduledir
).to eq('/opt/puppetlabs/puppet/vendor_modules')
end

Expand Down
26 changes: 22 additions & 4 deletions spec/unit/util/run_mode_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

describe "#conf_dir" do
it "has confdir /etc/puppetlabs/puppet when run as root" do
allow(@run_mode).to receive(:find_or_first).and_return('/etc/puppetlabs/puppet')
as_root { expect(@run_mode.conf_dir).to eq(File.expand_path('/etc/puppetlabs/puppet')) }
end

Expand All @@ -32,6 +33,7 @@

describe "#code_dir" do
it "has codedir /etc/puppetlabs/code when run as root" do
allow(@run_mode).to receive(:find_or_first).and_return('/etc/puppetlabs/code')
as_root { expect(@run_mode.code_dir).to eq(File.expand_path('/etc/puppetlabs/code')) }
end

Expand All @@ -52,6 +54,7 @@

describe "#var_dir" do
it "has vardir /opt/puppetlabs/puppet/cache when run as root" do
allow(@run_mode).to receive(:find_or_first).and_return('/opt/puppetlabs/puppet/cache')
as_root { expect(@run_mode.var_dir).to eq(File.expand_path('/opt/puppetlabs/puppet/cache')) }
end

Expand All @@ -62,6 +65,7 @@

describe "#public_dir" do
it "has publicdir /opt/puppetlabs/puppet/public when run as root" do
allow(@run_mode).to receive(:find_or_first).and_return('/opt/puppetlabs/puppet/public')
as_root { expect(@run_mode.public_dir).to eq(File.expand_path('/opt/puppetlabs/puppet/public')) }
end

Expand All @@ -73,6 +77,7 @@
describe "#log_dir" do
describe "when run as root" do
it "has logdir /var/log/puppetlabs/puppet" do
allow(@run_mode).to receive(:find_or_first).and_return('/var/log/puppetlabs/puppet')
as_root { expect(@run_mode.log_dir).to eq(File.expand_path('/var/log/puppetlabs/puppet')) }
end
end
Expand All @@ -87,6 +92,7 @@
describe "#run_dir" do
describe "when run as root" do
it "has rundir /var/run/puppetlabs" do
allow(@run_mode).to receive(:find_or_first).and_return('/var/run/puppetlabs')
as_root { expect(@run_mode.run_dir).to eq(File.expand_path('/var/run/puppetlabs')) }
end
end
Expand All @@ -99,19 +105,31 @@
end

describe "#pkg_config_path" do
it { expect(@run_mode.pkg_config_path).to eq('/opt/puppetlabs/puppet/lib/pkgconfig') }
it "has pkg config path /opt/puppetlabs/puppet/lib/pkgconfig" do
allow(@run_mode).to receive(:find_or_first).and_return('/opt/puppetlabs/puppet/lib/pkgconfig')
expect(@run_mode.pkg_config_path).to eq('/opt/puppetlabs/puppet/lib/pkgconfig')
end
end

describe "#gem_cmd" do
it { expect(@run_mode.gem_cmd).to eq('/opt/puppetlabs/puppet/bin/gem') }
it "has gem cmd /opt/puppetlabs/puppet/bin/gem" do
allow(@run_mode).to receive(:find_or_first).and_return('/opt/puppetlabs/puppet/bin/gem')
expect(@run_mode.gem_cmd).to eq('/opt/puppetlabs/puppet/bin/gem')
end
end

describe "#common_module_dir" do
it { expect(@run_mode.common_module_dir).to eq('/opt/puppetlabs/puppet/modules') }
it "has common module dir /opt/puppetlabs/puppet/modules" do
allow(@run_mode).to receive(:find_or_first).and_return('/opt/puppetlabs/puppet/modules')
expect(@run_mode.common_module_dir).to eq('/opt/puppetlabs/puppet/modules')
end
end

describe "#vendor_module_dir" do
it { expect(@run_mode.vendor_module_dir).to eq('/opt/puppetlabs/puppet/vendor_modules') }
it "has vendor module dir /opt/puppetlabs/puppet/vendor_modules" do
allow(@run_mode).to receive(:find_or_first).and_return('/opt/puppetlabs/puppet/vendor_modules')
expect(@run_mode.vendor_module_dir).to eq('/opt/puppetlabs/puppet/vendor_modules')
end
end
end

Expand Down