puppet 0.13.6 → 0.16.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of puppet might be problematic. Click here for more details.

Files changed (149) hide show
  1. data/CHANGELOG +57 -0
  2. data/Rakefile +38 -410
  3. data/bin/puppet +14 -12
  4. data/bin/puppetca +1 -3
  5. data/bin/puppetd +25 -7
  6. data/bin/puppetdoc +161 -104
  7. data/bin/puppetmasterd +4 -4
  8. data/conf/epm.list +8 -0
  9. data/conf/redhat/client.init +6 -1
  10. data/conf/redhat/no-chuser-0.15.1.patch +38 -0
  11. data/conf/redhat/puppet.spec +20 -5
  12. data/conf/redhat/puppetd.conf +1 -1
  13. data/conf/redhat/puppetmasterd.conf +1 -1
  14. data/conf/redhat/server.init +2 -4
  15. data/examples/code/snippets/{casestatement → casestatement.pp} +12 -1
  16. data/examples/code/snippets/selectorvalues.pp +15 -0
  17. data/examples/code/snippets/singleselector.pp +22 -0
  18. data/examples/code/snippets/tag.pp +9 -0
  19. data/ext/module_puppet +1 -1
  20. data/install.rb +303 -303
  21. data/lib/puppet.rb +7 -9
  22. data/lib/puppet/client.rb +18 -5
  23. data/lib/puppet/client/dipper.rb +12 -10
  24. data/lib/puppet/client/master.rb +113 -41
  25. data/lib/puppet/client/pelement.rb +20 -0
  26. data/lib/puppet/config.rb +113 -6
  27. data/lib/puppet/element.rb +1 -3
  28. data/lib/puppet/event.rb +12 -23
  29. data/lib/puppet/filetype.rb +93 -5
  30. data/lib/puppet/inifile.rb +201 -0
  31. data/lib/puppet/log.rb +18 -6
  32. data/lib/puppet/parameter.rb +80 -29
  33. data/lib/puppet/parser/ast.rb +6 -4
  34. data/lib/puppet/parser/ast/caseopt.rb +13 -4
  35. data/lib/puppet/parser/ast/casestatement.rb +2 -2
  36. data/lib/puppet/parser/ast/component.rb +4 -14
  37. data/lib/puppet/parser/ast/hostclass.rb +1 -1
  38. data/lib/puppet/parser/ast/leaf.rb +12 -0
  39. data/lib/puppet/parser/ast/node.rb +4 -4
  40. data/lib/puppet/parser/ast/objectdef.rb +5 -51
  41. data/lib/puppet/parser/ast/selector.rb +2 -0
  42. data/lib/puppet/parser/ast/tag.rb +26 -0
  43. data/lib/puppet/parser/interpreter.rb +89 -74
  44. data/lib/puppet/parser/lexer.rb +4 -3
  45. data/lib/puppet/parser/parser.rb +440 -378
  46. data/lib/puppet/parser/scope.rb +844 -887
  47. data/lib/puppet/server.rb +12 -1
  48. data/lib/puppet/server/authconfig.rb +166 -0
  49. data/lib/puppet/server/authstore.rb +8 -6
  50. data/lib/puppet/server/ca.rb +23 -26
  51. data/lib/puppet/server/filebucket.rb +24 -23
  52. data/lib/puppet/server/fileserver.rb +116 -47
  53. data/lib/puppet/server/master.rb +58 -19
  54. data/lib/puppet/server/pelement.rb +176 -0
  55. data/lib/puppet/server/rights.rb +78 -0
  56. data/lib/puppet/server/servlet.rb +19 -6
  57. data/lib/puppet/sslcertificates.rb +4 -2
  58. data/lib/puppet/sslcertificates/ca.rb +66 -34
  59. data/lib/puppet/storage.rb +20 -26
  60. data/lib/puppet/transaction.rb +49 -92
  61. data/lib/puppet/type.rb +142 -35
  62. data/lib/puppet/type/cron.rb +29 -14
  63. data/lib/puppet/type/exec.rb +92 -35
  64. data/lib/puppet/type/group.rb +29 -11
  65. data/lib/puppet/type/nameservice.rb +50 -1
  66. data/lib/puppet/type/nameservice/netinfo.rb +68 -1
  67. data/lib/puppet/type/nameservice/objectadd.rb +1 -0
  68. data/lib/puppet/type/package.rb +150 -109
  69. data/lib/puppet/type/package/apple.rb +27 -0
  70. data/lib/puppet/type/package/apt.rb +1 -0
  71. data/lib/puppet/type/package/darwinport.rb +97 -0
  72. data/lib/puppet/type/package/dpkg.rb +10 -2
  73. data/lib/puppet/type/package/freebsd.rb +19 -0
  74. data/lib/puppet/type/package/{bsd.rb → openbsd.rb} +36 -7
  75. data/lib/puppet/type/package/ports.rb +98 -0
  76. data/lib/puppet/type/package/rpm.rb +43 -7
  77. data/lib/puppet/type/package/sun.rb +53 -36
  78. data/lib/puppet/type/package/yum.rb +5 -16
  79. data/lib/puppet/type/parsedtype.rb +41 -29
  80. data/lib/puppet/type/parsedtype/host.rb +13 -5
  81. data/lib/puppet/type/parsedtype/mount.rb +250 -0
  82. data/lib/puppet/type/parsedtype/port.rb +8 -6
  83. data/lib/puppet/type/pfile.rb +284 -30
  84. data/lib/puppet/type/pfile/checksum.rb +96 -68
  85. data/lib/puppet/type/pfile/content.rb +16 -13
  86. data/lib/puppet/type/pfile/ensure.rb +64 -126
  87. data/lib/puppet/type/pfile/group.rb +12 -5
  88. data/lib/puppet/type/pfile/mode.rb +16 -4
  89. data/lib/puppet/type/pfile/source.rb +47 -73
  90. data/lib/puppet/type/pfile/target.rb +81 -0
  91. data/lib/puppet/type/pfile/uid.rb +10 -3
  92. data/lib/puppet/type/pfilebucket.rb +12 -3
  93. data/lib/puppet/type/schedule.rb +5 -1
  94. data/lib/puppet/type/service.rb +138 -66
  95. data/lib/puppet/type/service/debian.rb +9 -3
  96. data/lib/puppet/type/service/init.rb +51 -56
  97. data/lib/puppet/type/service/smf.rb +16 -6
  98. data/lib/puppet/type/state.rb +71 -32
  99. data/lib/puppet/type/symlink.rb +12 -7
  100. data/lib/puppet/type/tidy.rb +5 -1
  101. data/lib/puppet/type/user.rb +116 -20
  102. data/lib/puppet/type/yumrepo.rb +314 -0
  103. data/lib/puppet/util.rb +84 -14
  104. data/test/client/client.rb +41 -18
  105. data/test/client/master.rb +50 -4
  106. data/test/executables/puppetbin.rb +31 -4
  107. data/test/executables/puppetca.rb +18 -2
  108. data/test/language/ast.rb +201 -31
  109. data/test/language/interpreter.rb +8 -2
  110. data/test/{parser → language}/lexer.rb +1 -1
  111. data/test/language/node.rb +84 -0
  112. data/test/{parser → language}/parser.rb +1 -1
  113. data/test/language/scope.rb +101 -2
  114. data/test/language/snippets.rb +23 -2
  115. data/test/other/config.rb +99 -1
  116. data/test/other/filetype.rb +95 -0
  117. data/test/other/inifile.rb +114 -0
  118. data/test/other/log.rb +3 -2
  119. data/test/other/transactions.rb +55 -10
  120. data/test/puppet/utiltest.rb +25 -1
  121. data/test/puppettest.rb +140 -46
  122. data/test/server/authconfig.rb +56 -0
  123. data/test/server/bucket.rb +32 -18
  124. data/test/server/fileserver.rb +75 -30
  125. data/test/server/master.rb +27 -4
  126. data/test/server/pelement.rb +298 -0
  127. data/test/server/rights.rb +41 -0
  128. data/test/server/server.rb +2 -2
  129. data/test/tagging/tagging.rb +100 -1
  130. data/test/types/basic.rb +3 -3
  131. data/test/types/cron.rb +24 -1
  132. data/test/types/exec.rb +99 -1
  133. data/test/types/file.rb +298 -2
  134. data/test/types/filebucket.rb +4 -15
  135. data/test/types/filesources.rb +43 -14
  136. data/test/types/group.rb +1 -13
  137. data/test/types/mount.rb +277 -0
  138. data/test/types/package.rb +164 -33
  139. data/test/types/parameter.rb +107 -0
  140. data/test/types/port.rb +2 -1
  141. data/test/types/service.rb +37 -2
  142. data/test/types/state.rb +92 -0
  143. data/test/types/symlink.rb +30 -2
  144. data/test/types/tidy.rb +2 -14
  145. data/test/types/type.rb +35 -1
  146. data/test/types/user.rb +110 -1
  147. data/test/types/yumrepo.rb +95 -0
  148. metadata +316 -290
  149. data/test/types/filetype.rb +0 -160
@@ -16,6 +16,43 @@ module Puppet
16
16
  @validtypes.include?(type)
17
17
  end
18
18
 
19
+ @validtypes.each do |ctype|
20
+ newvalue(ctype) do
21
+ handlesum()
22
+ end
23
+ end
24
+
25
+ str = @validtypes.join("|")
26
+
27
+ newvalue(/^\{#{str}\}/) do
28
+ handlesum()
29
+ end
30
+
31
+ newvalue(:nosum) do
32
+ # nothing
33
+ :nochange
34
+ end
35
+
36
+ # Convert from the sum type to the stored checksum.
37
+ munge do |value|
38
+ unless defined? @checktypes
39
+ @checktypes = []
40
+ end
41
+
42
+ if value =~ /^\{(\w+)\}(.+)$/
43
+ @checktypes << $1
44
+ #return $2
45
+ return value
46
+ else
47
+ if FileTest.directory?(@parent[:path])
48
+ value = "time"
49
+ end
50
+ value = super(value)
51
+ @checktypes << value
52
+ return getcachedsum()
53
+ end
54
+ end
55
+
19
56
  def checktype
20
57
  @checktypes[0]
21
58
  end
@@ -80,15 +117,17 @@ module Puppet
80
117
  # Calculate the sum from disk.
81
118
  def getsum(checktype)
82
119
  sum = ""
120
+
121
+ checktype = checktype.intern if checktype.is_a? String
83
122
  case checktype
84
- when "md5", "md5lite":
123
+ when :md5, :md5lite:
85
124
  unless FileTest.file?(@parent[:path])
86
125
  @parent.info "Cannot MD5 sum directory %s" %
87
126
  @parent[:path]
88
127
 
89
- # because we cannot sum directories, just delete ourselves
90
- # from the file so we won't sync
91
- @parent.delete(self[:path])
128
+ @should = [nil]
129
+ @is = nil
130
+ #@parent.delete(self[:path])
92
131
  return
93
132
  else
94
133
  begin
@@ -100,7 +139,7 @@ module Puppet
100
139
  text = file.read(512)
101
140
  end
102
141
  if text.nil?
103
- self.info "Not checksumming empty file %s" %
142
+ self.debug "Not checksumming empty file %s" %
104
143
  @parent[:path]
105
144
  sum = 0
106
145
  else
@@ -117,35 +156,60 @@ module Puppet
117
156
  @parent.delete(self.class.name)
118
157
  end
119
158
  end
120
- when "timestamp","mtime":
159
+ when :timestamp, :mtime:
121
160
  sum = @parent.stat.mtime.to_s
122
161
  #sum = File.stat(@parent[:path]).mtime.to_s
123
- when "time":
162
+ when :time:
124
163
  sum = @parent.stat.ctime.to_s
125
164
  #sum = File.stat(@parent[:path]).ctime.to_s
126
165
  else
127
166
  raise Puppet::Error, "Invalid sum type %s" % checktype
128
167
  end
129
168
 
130
- return sum
169
+ return "{#{checktype}}" + sum.to_s
170
+ #return sum.to_s
131
171
  end
132
172
 
133
- # Convert from the sum type to the stored checksum.
134
- munge do |value|
135
- unless defined? @checktypes
136
- @checktypes = []
137
- end
138
- unless self.class.validtype?(value)
139
- self.fail "Invalid checksum type '%s'" % value
173
+ # At this point, we don't actually modify the system, we modify
174
+ # the stored state to reflect the current state, and then kick
175
+ # off an event to mark any changes.
176
+ def handlesum
177
+ if @is.nil?
178
+ raise Puppet::Error, "Checksum state for %s is somehow nil" %
179
+ @parent.name
140
180
  end
141
181
 
142
- if FileTest.directory?(@parent[:path])
143
- value = "time"
144
- end
182
+ if @is == :absent
183
+ self.retrieve
184
+
185
+ if self.insync?
186
+ self.debug "Checksum is already in sync"
187
+ return nil
188
+ end
189
+ #@parent.debug "%s(%s): after refresh, is '%s'" %
190
+ # [self.class.name,@parent.name,@is]
145
191
 
146
- @checktypes << value
192
+ # If we still can't retrieve a checksum, it means that
193
+ # the file still doesn't exist
194
+ if @is == :absent
195
+ # if they're copying, then we won't worry about the file
196
+ # not existing yet
197
+ unless @parent.state(:source)
198
+ self.warning(
199
+ "File %s does not exist -- cannot checksum" %
200
+ @parent[:path]
201
+ )
202
+ end
203
+ return nil
204
+ end
205
+ end
147
206
 
148
- return getcachedsum()
207
+ # If the sums are different, then return an event.
208
+ if self.updatesum
209
+ return :file_changed
210
+ else
211
+ return nil
212
+ end
149
213
  end
150
214
 
151
215
  # Even though they can specify multiple checksums, the insync?
@@ -156,12 +220,20 @@ module Puppet
156
220
  @checktypes = ["md5"]
157
221
  end
158
222
 
159
- unless FileTest.exists?(@parent[:path])
223
+ stat = nil
224
+ unless stat = @parent.stat
160
225
  self.is = :absent
161
226
  return
162
227
  end
163
228
 
164
- if FileTest.directory?(@parent[:path]) and @checktypes[0] =~ /md5/
229
+ if stat.ftype == "link" and @parent[:links] != :follow
230
+ self.debug "Not checksumming symlink"
231
+ #@parent.delete(:checksum)
232
+ self.is = self.should
233
+ return
234
+ end
235
+
236
+ if stat.ftype == "directory" and @checktypes[0] =~ /md5/
165
237
  @checktypes = ["time"]
166
238
  end
167
239
 
@@ -187,49 +259,6 @@ module Puppet
187
259
  #@parent.debug "checksum state is %s" % self.is
188
260
  end
189
261
 
190
-
191
- # At this point, we don't actually modify the system, we modify
192
- # the stored state to reflect the current state, and then kick
193
- # off an event to mark any changes.
194
- def sync
195
- if @is.nil?
196
- raise Puppet::Error, "Checksum state for %s is somehow nil" %
197
- @parent.name
198
- end
199
-
200
- if @is == :absent
201
- self.retrieve
202
-
203
- if self.insync?
204
- self.debug "Checksum is already in sync"
205
- return nil
206
- end
207
- #@parent.debug "%s(%s): after refresh, is '%s'" %
208
- # [self.class.name,@parent.name,@is]
209
-
210
- # If we still can't retrieve a checksum, it means that
211
- # the file still doesn't exist
212
- if @is == :absent
213
- # if they're copying, then we won't worry about the file
214
- # not existing yet
215
- unless @parent.state(:source)
216
- self.warning(
217
- "File %s does not exist -- cannot checksum" %
218
- @parent[:path]
219
- )
220
- end
221
- return nil
222
- end
223
- end
224
-
225
- # If the sums are different, then return an event.
226
- if self.updatesum
227
- return :file_changed
228
- else
229
- return nil
230
- end
231
- end
232
-
233
262
  # Store the new sum to the state db.
234
263
  def updatesum
235
264
  result = false
@@ -259,8 +288,7 @@ module Puppet
259
288
  #@parent.debug "@is: %s; @should: %s" % [@is,@should]
260
289
  result = true
261
290
  else
262
- @parent.debug "Creating checksum %s of type %s" %
263
- [@is,@checktypes[0]]
291
+ @parent.debug "Creating checksum %s" % @is
264
292
  result = false
265
293
  end
266
294
  state[@checktypes[0]] = @is
@@ -269,4 +297,4 @@ module Puppet
269
297
  end
270
298
  end
271
299
 
272
- # $Id: checksum.rb 947 2006-02-25 00:26:14Z luke $
300
+ # $Id: checksum.rb 1126 2006-04-20 20:55:02Z luke $
@@ -27,10 +27,23 @@ module Puppet
27
27
  # We should probably take advantage of existing md5 sums if they're there,
28
28
  # but I really don't feel like dealing with the complexity right now.
29
29
  def retrieve
30
- unless FileTest.exists?(@parent[:path])
30
+ stat = nil
31
+ unless stat = @parent.stat
31
32
  @is = :absent
32
33
  return
33
34
  end
35
+
36
+ if stat.ftype == "link" and @parent[:links] == :ignore
37
+ self.is = self.should
38
+ return
39
+ end
40
+
41
+ # Don't even try to manage the content on directories
42
+ if stat.ftype == "directory" and @parent[:links] == :ignore
43
+ @parent.delete(:content)
44
+ return
45
+ end
46
+
34
47
  begin
35
48
  @is = File.read(@parent[:path])
36
49
  rescue => detail
@@ -43,17 +56,7 @@ module Puppet
43
56
 
44
57
  # Just write our content out to disk.
45
58
  def sync
46
- begin
47
- File.open(@parent[:path], "w") { |f|
48
- f.print self.should
49
- f.flush
50
- }
51
- rescue => detail
52
- raise Puppet::Error, "Could not write content to %s: %s" %
53
- [@parent.name, detail]
54
- end
55
-
56
- @parent.setchecksum
59
+ @parent.write { |f| f.print self.should }
57
60
 
58
61
  if @is == :absent
59
62
  return :file_created
@@ -64,4 +67,4 @@ module Puppet
64
67
  end
65
68
  end
66
69
 
67
- # $Id: content.rb 922 2006-02-16 19:10:34Z luke $
70
+ # $Id: content.rb 1125 2006-04-20 19:38:48Z luke $
@@ -3,11 +3,32 @@ module Puppet
3
3
  require 'etc'
4
4
  desc "Whether to create files that don't currently exist.
5
5
  Possible values are *absent*, *present* (equivalent to *file*),
6
- **file**/*directory*. Specifying 'absent' will delete the file,
6
+ *file*, and *directory*. Specifying 'absent' will delete the file,
7
7
  although currently this will not recursively delete directories.
8
+
9
+ Anything other than those values will be considered to be a symlink.
10
+ For instance, the following text creates a link::
11
+
12
+ # Useful on solaris
13
+ file { \"/etc/inetd.conf\":
14
+ ensure => \"/etc/inet/inetd.conf\"
15
+ }
8
16
 
9
- This is the only element with an *ensure* state that does not have
10
- a default value."
17
+ You can make relative links:
18
+
19
+ # Useful on solaris
20
+ file { \"/etc/inetd.conf\":
21
+ ensure => \"inet/inetd.conf\"
22
+ }
23
+
24
+ If you need to make a relative link to a file named the same
25
+ as one of the valid values, you must prefix it with ``./`` or
26
+ something similar.
27
+
28
+ You can also make recursive symlinks, which will create a
29
+ directory structure that maps to the target directory,
30
+ with directories corresponding to each directory
31
+ and links corresponding to each file."
11
32
 
12
33
  # Most 'ensure' states have a default, but with files we, um, don't.
13
34
  nodefault
@@ -23,21 +44,8 @@ module Puppet
23
44
  if state = @parent.state(:content) or state = @parent.state(:source)
24
45
  state.sync
25
46
  else
47
+ @parent.write(false) { |f| f.flush }
26
48
  mode = @parent.should(:mode)
27
- Puppet::Util.asuser(asuser(), @parent.should(:group)) {
28
- f = nil
29
- if mode
30
- Puppet::Util.withumask(000) do
31
- f = File.open(@parent[:path],"w", mode)
32
- end
33
- else
34
- f = File.open(@parent[:path],"w")
35
- end
36
-
37
- f.flush
38
- f.close
39
- @parent.setchecksum
40
- }
41
49
  end
42
50
  return :file_created
43
51
  end
@@ -52,7 +60,7 @@ module Puppet
52
60
  "Cannot create %s; parent directory %s does not exist" %
53
61
  [@parent[:path], parent]
54
62
  end
55
- Puppet::Util.asuser(asuser()) {
63
+ Puppet::Util.asuser(@parent.asuser()) {
56
64
  if mode
57
65
  Puppet::Util.withumask(000) do
58
66
  Dir.mkdir(@parent[:path],mode)
@@ -65,23 +73,39 @@ module Puppet
65
73
  return :directory_created
66
74
  end
67
75
 
68
- def asuser
69
- if @parent.should(:owner) and ! @parent.should(:owner).is_a?(Symbol)
70
- writeable = Puppet::Util.asuser(@parent.should(:owner)) {
71
- FileTest.writable?(File.dirname(@parent[:path]))
72
- }
73
76
 
74
- # If the parent directory is writeable, then we execute
75
- # as the user in question. Otherwise we'll rely on
76
- # the 'owner' state to do things.
77
- if writeable
78
- asuser = @parent.should(:owner)
77
+ newvalue(:link) do
78
+ if state = @parent.state(:target)
79
+ state.retrieve
80
+
81
+ if state.linkmaker
82
+ self.set_directory
83
+ return :directory_created
84
+ else
85
+ return state.sync
79
86
  end
87
+ else
88
+ self.fail "Cannot create a symlink without a target"
80
89
  end
90
+ end
91
+
92
+ # Symlinks.
93
+ newvalue(/./) do
94
+ # This code never gets executed. We need the regex to support
95
+ # specifying it, but the work is done in the 'symlink' code block.
96
+ end
81
97
 
82
- return asuser
98
+ munge do |value|
99
+ value = super(value)
100
+
101
+ return value if value.is_a? Symbol
102
+
103
+ @parent[:target] = value
104
+
105
+ return :link
83
106
  end
84
107
 
108
+ # Check that we can actually create anything
85
109
  def check
86
110
  basedir = File.dirname(@parent[:path])
87
111
 
@@ -106,112 +130,26 @@ module Puppet
106
130
  @is = :absent
107
131
  end
108
132
  end
109
-
110
- #self.debug "'exists' state is %s" % self.is
111
133
  end
112
134
 
135
+ def sync
136
+ event = super
113
137
 
114
- # We can mostly rely on the superclass method, but we want other states
115
- # to take precedence over 'ensure' if they are present.
116
- # def sync
117
- # # XXX This is a bad idea, because it almost guarantees bugs if we
118
- # # introduce more states to manage content, but anything else is just
119
- # # about as bad.
120
- # event = nil
121
- # #if state = @parent.state(:source) or state = @parent.state(:content)
122
- # # event = state.sync
123
- # #else
124
- # event = super
125
- # @parent.setchecksum
126
- # #end
127
- # return event
128
- # end
129
-
130
- def disabled_sync
131
- event = nil
132
- basedir = File.dirname(@parent[:path])
133
-
134
- if ! FileTest.exists?(basedir)
135
- raise Puppet::Error,
136
- "Can not create %s; parent directory does not exist" %
137
- @parent.name
138
- elsif ! FileTest.directory?(basedir)
139
- raise Puppet::Error,
140
- "Can not create %s; %s is not a directory" %
141
- [@parent.name, dirname]
142
- end
143
-
144
- self.retrieve
145
- if self.insync?
146
- self.info "already in sync"
147
- return nil
148
- end
149
-
150
- mode = @parent.should(:mode)
151
-
152
- # First, determine if a user has been specified and if so if
153
- # that user has write access to the parent dir
154
- asuser = nil
155
- if @parent.should(:owner) and ! @parent.should(:owner).is_a?(Symbol)
156
- writeable = Puppet::Util.asuser(@parent.should(:owner)) {
157
- FileTest.writable?(File.dirname(@parent[:path]))
158
- }
138
+ # There are some cases where all of the work does not get done on
139
+ # file creation, so we have to do some extra checking.
140
+ @parent.each do |thing|
141
+ next unless thing.is_a? Puppet::State
142
+ next if thing == self
159
143
 
160
- # If the parent directory is writeable, then we execute
161
- # as the user in question. Otherwise we'll rely on
162
- # the 'owner' state to do things.
163
- if writeable
164
- asuser = @parent.should(:owner)
144
+ thing.retrieve
145
+ unless thing.insync?
146
+ thing.sync
165
147
  end
166
148
  end
167
- begin
168
- case self.should
169
- when "file":
170
- # just create an empty file
171
- Puppet::Util.asuser(asuser, @parent.should(:group)) {
172
- if mode
173
- File.open(@parent[:path],"w", mode) {
174
- }
175
- else
176
- File.open(@parent[:path],"w") {
177
- }
178
- end
179
- }
180
- event = :file_created
181
- when "directory":
182
- Puppet::Util.asuser(asuser) {
183
- if mode
184
- Dir.mkdir(@parent[:path],mode)
185
- else
186
- Dir.mkdir(@parent[:path])
187
- end
188
- }
189
- event = :directory_created
190
- when :absent:
191
- # this is where the file should be deleted...
192
-
193
- # This value is only valid when we're rolling back a creation,
194
- # so we verify that the file has not been modified since then.
195
- unless FileTest.size(@parent[:path]) == 0
196
- raise Puppet::Error.new(
197
- "Created file %s has since been modified; cannot roll back."
198
- )
199
- end
200
149
 
201
- File.unlink(@parent[:path])
202
- else
203
- error = Puppet::Error.new(
204
- "Somehow got told to create a %s file" % self.should)
205
- raise error
206
- end
207
- rescue => detail
208
- raise Puppet::Error.new("Could not create %s: %s" %
209
- [self.should, detail]
210
- )
211
- end
212
150
  return event
213
151
  end
214
152
  end
215
153
  end
216
154
 
217
- # $Id: ensure.rb 966 2006-03-02 17:12:26Z luke $
155
+ # $Id: ensure.rb 1123 2006-04-20 05:14:13Z luke $