summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/puppet/config.rb17
-rwxr-xr-xtest/other/config.rb30
2 files changed, 47 insertions, 0 deletions
diff --git a/lib/puppet/config.rb b/lib/puppet/config.rb
index 18bd21693..638f1d34f 100644
--- a/lib/puppet/config.rb
+++ b/lib/puppet/config.rb
@@ -174,6 +174,23 @@ class Config
@created = []
end
+ # Make a directory with the appropriate user, group, and mode
+ def mkdir(default)
+ obj = nil
+ unless obj = @config[default]
+ raise ArgumentError, "Unknown default %s" % default
+ end
+
+ unless obj.is_a? CFile
+ raise ArgumentError, "Default %s is not a file" % default
+ end
+
+ Puppet::Util.asuser(obj.owner, obj.group) do
+ mode = obj.mode || 0750
+ Dir.mkdir(obj.value, mode)
+ end
+ end
+
# Return all of the parameters associated with a given section.
def params(section)
section = section.intern if section.is_a? String
diff --git a/test/other/config.rb b/test/other/config.rb
index 2714eab17..23c0e2725 100755
--- a/test/other/config.rb
+++ b/test/other/config.rb
@@ -551,6 +551,36 @@ yay = /a/path
assert_equal(group.gid, File.stat(path).gid, "GIDS are not equal")
end
end
+
+ def test_mkdir
+ path = tempfile()
+ mode = 0755
+
+ config = mkconfig
+
+ args = { :default => path, :mode => mode }
+
+ user = nonrootuser()
+ group = nonrootgroup()
+
+ if Process.uid == 0
+ args[:owner] = user.name
+ args[:group] = group.name
+ end
+
+ config.setdefaults(:testing, :mydir => args)
+
+ assert_nothing_raised {
+ config.mkdir(:mydir)
+ }
+
+ assert_equal(mode, filemode(path), "Modes are not equal")
+
+ if Process.uid == 0
+ assert_equal(user.uid, File.stat(path).uid, "UIDS are not equal")
+ assert_equal(group.gid, File.stat(path).gid, "GIDS are not equal")
+ end
+ end
end
# $Id$