Skip to content

Commit 95b21df

Browse files
committed
(#8660) Default config dir to %PROGRAMDATA% on Windows
The puppet install.rb script now defaults the config directory to %PROGRAMDATA%\PuppetLabs\puppet\etc on Windows. This is more inline with Windows best-practices, as this directory is used to store application data across all users. The PROGRAMDATA environment variable also takes into account alternate system drives, by using the SYSTEMDRIVE environment variable. Note that the Dir::COMMON_APPDATA constant is so named because it corresponds to the CSIDL_COMMON_APPDATA constant, which on 2000, XP, and 2003 is %ALLUSERSPROFILE%\Application Data, and on Vista, Win7 and 2008 is %SYSTEMDRIVE%\ProgramData. This commit also updates puppet's default run_mode var and conf directories when running as "root" to match the install script, and fixes the spec test, which was looking in the Dir::WINDOWS directory. Reviewed-by: Cameron Thomas <cameron@puppetlabs.com>
1 parent ca3396e commit 95b21df

3 files changed

Lines changed: 7 additions & 4 deletions

File tree

install.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,9 @@ def prepare_installation
243243

244244
if not InstallOptions.configdir.nil?
245245
configdir = InstallOptions.configdir
246+
elsif $operatingsystem == "windows"
247+
require 'win32/dir'
248+
configdir = File.join(Dir::COMMON_APPDATA, "PuppetLabs", "puppet", "etc")
246249
else
247250
configdir = "/etc/puppet"
248251
end

lib/puppet/util/run_mode.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,14 @@ def user?
2727

2828
def conf_dir
2929
which_dir(
30-
(Puppet.features.microsoft_windows? ? File.join(Dir::WINDOWS, "puppet", "etc") : "/etc/puppet"),
30+
(Puppet.features.microsoft_windows? ? File.join(Dir::COMMON_APPDATA, "PuppetLabs", "puppet", "etc") : "/etc/puppet"),
3131
"~/.puppet"
3232
)
3333
end
3434

3535
def var_dir
3636
which_dir(
37-
(Puppet.features.microsoft_windows? ? File.join(Dir::WINDOWS, "puppet", "var") : "/var/lib/puppet"),
37+
(Puppet.features.microsoft_windows? ? File.join(Dir::COMMON_APPDATA, "PuppetLabs", "puppet", "var") : "/var/lib/puppet"),
3838
"~/.puppet/var"
3939
)
4040
end

spec/unit/util/run_mode_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
it "should have confdir /etc/puppet when run as root" do
1010
Puppet.features.stubs(:root?).returns(true)
11-
etcdir = Puppet.features.microsoft_windows? ? File.join(Dir::WINDOWS, "puppet", "etc") : '/etc/puppet'
11+
etcdir = Puppet.features.microsoft_windows? ? File.join(Dir::COMMON_APPDATA, "PuppetLabs", "puppet", "etc") : '/etc/puppet'
1212
# REMIND: issue with windows backslashes
1313
@run_mode.conf_dir.should == File.expand_path(etcdir)
1414
end
@@ -21,7 +21,7 @@
2121

2222
it "should have vardir /var/lib/puppet when run as root" do
2323
Puppet.features.stubs(:root?).returns(true)
24-
vardir = Puppet.features.microsoft_windows? ? File.join(Dir::WINDOWS, "puppet", "var") : '/var/lib/puppet'
24+
vardir = Puppet.features.microsoft_windows? ? File.join(Dir::COMMON_APPDATA, "PuppetLabs", "puppet", "var") : '/var/lib/puppet'
2525
# REMIND: issue with windows backslashes
2626
@run_mode.var_dir.should == File.expand_path(vardir)
2727
end

0 commit comments

Comments
 (0)