puppet 0.25.1 → 0.25.2

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 (198) hide show
  1. data/CHANGELOG +159 -135
  2. data/Rakefile +4 -1
  3. data/conf/gentoo/conf.d/puppetmaster +1 -1
  4. data/conf/osx/createpackage.sh +12 -0
  5. data/conf/osx/preflight +4 -0
  6. data/conf/redhat/puppet.spec +12 -2
  7. data/conf/redhat/server.init +1 -0
  8. data/conf/redhat/server.sysconfig +1 -1
  9. data/ext/ldap/puppet.schema +5 -9
  10. data/ext/puppetlast +2 -1
  11. data/ext/rack/README +2 -2
  12. data/ext/regexp_nodes/classes/databases +2 -0
  13. data/ext/regexp_nodes/classes/webservers +2 -0
  14. data/ext/regexp_nodes/parameters/environment/prod +1 -0
  15. data/ext/regexp_nodes/parameters/environment/qa +3 -0
  16. data/ext/regexp_nodes/regexp_nodes.rb +215 -0
  17. data/lib/puppet.rb +1 -1
  18. data/lib/puppet/agent.rb +2 -2
  19. data/lib/puppet/application/puppet.rb +1 -1
  20. data/lib/puppet/application/puppetd.rb +1 -1
  21. data/lib/puppet/application/puppetdoc.rb +4 -3
  22. data/lib/puppet/application/puppetrun.rb +5 -14
  23. data/lib/puppet/application/ralsh.rb +9 -25
  24. data/lib/puppet/configurer.rb +2 -1
  25. data/lib/puppet/configurer/fact_handler.rb +8 -6
  26. data/lib/puppet/daemon.rb +2 -2
  27. data/lib/puppet/defaults.rb +21 -2
  28. data/lib/puppet/external/pson/common.rb +1 -1
  29. data/lib/puppet/external/pson/pure.rb +3 -3
  30. data/lib/puppet/feature/base.rb +3 -0
  31. data/lib/puppet/feature/selinux.rb +3 -0
  32. data/lib/puppet/feature/zlib.rb +6 -0
  33. data/lib/puppet/file_serving/base.rb +16 -1
  34. data/lib/puppet/file_serving/metadata.rb +46 -9
  35. data/lib/puppet/file_serving/mount/file.rb +4 -1
  36. data/lib/puppet/indirector/catalog/active_record.rb +5 -0
  37. data/lib/puppet/indirector/envelope.rb +1 -3
  38. data/lib/puppet/indirector/indirection.rb +13 -16
  39. data/lib/puppet/indirector/node/ldap.rb +7 -4
  40. data/lib/puppet/indirector/ssl_file.rb +1 -1
  41. data/lib/puppet/network/authstore.rb +48 -118
  42. data/lib/puppet/network/client/resource.rb +2 -15
  43. data/lib/puppet/network/format.rb +2 -12
  44. data/lib/puppet/network/format_handler.rb +15 -1
  45. data/lib/puppet/network/formats.rb +19 -4
  46. data/lib/puppet/network/handler/fileserver.rb +1 -0
  47. data/lib/puppet/network/http/handler.rb +1 -0
  48. data/lib/puppet/network/http/rack/httphandler.rb +0 -18
  49. data/lib/puppet/network/http/rack/rest.rb +4 -4
  50. data/lib/puppet/network/http/rack/xmlrpc.rb +4 -4
  51. data/lib/puppet/network/http/webrick.rb +2 -1
  52. data/lib/puppet/network/server.rb +1 -1
  53. data/lib/puppet/node/environment.rb +20 -9
  54. data/lib/puppet/parameter.rb +17 -1
  55. data/lib/puppet/parser/ast/boolean_operator.rb +2 -2
  56. data/lib/puppet/parser/ast/leaf.rb +5 -1
  57. data/lib/puppet/parser/ast/resourceparam.rb +4 -0
  58. data/lib/puppet/parser/ast/selector.rb +4 -0
  59. data/lib/puppet/parser/functions/generate.rb +2 -2
  60. data/lib/puppet/parser/functions/shellquote.rb +1 -1
  61. data/lib/puppet/property.rb +3 -11
  62. data/lib/puppet/provider/cron/crontab.rb +2 -0
  63. data/lib/puppet/provider/host/parsed.rb +9 -9
  64. data/lib/puppet/provider/package/blastwave.rb +7 -6
  65. data/lib/puppet/provider/package/portage.rb +23 -27
  66. data/lib/puppet/provider/package/rug.rb +1 -1
  67. data/lib/puppet/provider/package/sun.rb +5 -3
  68. data/lib/puppet/provider/service/daemontools.rb +1 -1
  69. data/lib/puppet/provider/service/debian.rb +1 -1
  70. data/lib/puppet/provider/service/runit.rb +1 -1
  71. data/lib/puppet/provider/ssh_authorized_key/parsed.rb +2 -1
  72. data/lib/puppet/provider/sshkey/parsed.rb +3 -5
  73. data/lib/puppet/provider/zone/solaris.rb +1 -1
  74. data/lib/puppet/rails.rb +9 -2
  75. data/lib/puppet/rails/benchmark.rb +1 -1
  76. data/lib/puppet/rails/host.rb +2 -7
  77. data/lib/puppet/rails/resource.rb +20 -26
  78. data/lib/puppet/resource/catalog.rb +3 -3
  79. data/lib/puppet/resource/reference.rb +13 -25
  80. data/lib/puppet/ssl/certificate.rb +3 -2
  81. data/lib/puppet/ssl/host.rb +14 -33
  82. data/lib/puppet/sslcertificates.rb +1 -5
  83. data/lib/puppet/sslcertificates/ca.rb +8 -7
  84. data/lib/puppet/transaction.rb +15 -12
  85. data/lib/puppet/type.rb +12 -5
  86. data/lib/puppet/type/file.rb +26 -32
  87. data/lib/puppet/type/file/content.rb +5 -5
  88. data/lib/puppet/type/file/ensure.rb +6 -17
  89. data/lib/puppet/type/file/mode.rb +18 -1
  90. data/lib/puppet/type/file/source.rb +12 -12
  91. data/lib/puppet/type/host.rb +6 -9
  92. data/lib/puppet/type/k5login.rb +1 -1
  93. data/lib/puppet/type/maillist.rb +4 -7
  94. data/lib/puppet/type/port.rb +6 -5
  95. data/lib/puppet/type/resources.rb +12 -12
  96. data/lib/puppet/type/sshkey.rb +5 -5
  97. data/lib/puppet/type/tidy.rb +9 -2
  98. data/lib/puppet/type/yumrepo.rb +3 -1
  99. data/lib/puppet/util.rb +64 -56
  100. data/lib/puppet/util/backups.rb +2 -1
  101. data/lib/puppet/util/filetype.rb +46 -0
  102. data/lib/puppet/util/log.rb +10 -18
  103. data/lib/puppet/util/log_paths.rb +14 -0
  104. data/lib/puppet/util/methodhelper.rb +3 -4
  105. data/lib/puppet/util/monkey_patches.rb +8 -0
  106. data/lib/puppet/util/rdoc/generators/puppet_generator.rb +5 -3
  107. data/lib/puppet/util/rdoc/parser.rb +32 -16
  108. data/lib/puppet/util/reference.rb +6 -3
  109. data/lib/puppet/util/selinux.rb +21 -14
  110. data/lib/puppet/util/settings.rb +30 -25
  111. data/lib/puppet/util/settings/file_setting.rb +7 -4
  112. data/lib/puppet/util/subclass_loader.rb +1 -1
  113. data/lib/puppet/util/suidmanager.rb +11 -1
  114. data/lib/puppet/util/tagging.rb +22 -4
  115. data/man/man8/filebucket.8 +23 -18
  116. data/man/man8/pi.8 +42 -20
  117. data/man/man8/puppet.8 +47 -32
  118. data/man/man8/puppet.conf.8 +807 -764
  119. data/man/man8/puppetca.8 +24 -14
  120. data/man/man8/puppetd.8 +33 -16
  121. data/man/man8/puppetdoc.8 +71 -18
  122. data/man/man8/puppetmasterd.8 +18 -25
  123. data/man/man8/puppetqd.8 +60 -0
  124. data/man/man8/puppetrun.8 +27 -14
  125. data/man/man8/ralsh.8 +33 -40
  126. data/spec/integration/bin/puppetmasterd.rb +3 -2
  127. data/spec/integration/defaults.rb +11 -0
  128. data/spec/integration/file_serving/metadata.rb +1 -0
  129. data/spec/integration/indirector/file_content/file_server.rb +2 -1
  130. data/spec/integration/ssl/certificate_request.rb +2 -0
  131. data/spec/integration/type/file.rb +20 -1
  132. data/spec/shared_behaviours/file_serving.rb +1 -1
  133. data/spec/spec_helper.rb +1 -1
  134. data/spec/unit/application/puppet.rb +11 -30
  135. data/spec/unit/application/puppetd.rb +1 -0
  136. data/spec/unit/application/puppetdoc.rb +13 -4
  137. data/spec/unit/application/puppetmasterd.rb +1 -0
  138. data/spec/unit/application/puppetrun.rb +12 -2
  139. data/spec/unit/application/ralsh.rb +39 -22
  140. data/spec/unit/configurer.rb +6 -0
  141. data/spec/unit/configurer/fact_handler.rb +15 -1
  142. data/spec/unit/file_serving/metadata.rb +128 -16
  143. data/spec/unit/file_serving/mount/file.rb +8 -0
  144. data/spec/unit/indirector/catalog/active_record.rb +20 -1
  145. data/spec/unit/indirector/catalog/compiler.rb +2 -1
  146. data/spec/unit/indirector/indirection.rb +29 -18
  147. data/spec/unit/indirector/node/ldap.rb +20 -6
  148. data/spec/unit/network/authstore.rb +197 -0
  149. data/spec/unit/network/format_handler.rb +28 -8
  150. data/spec/unit/network/formats.rb +31 -0
  151. data/spec/unit/network/http/handler.rb +10 -0
  152. data/spec/unit/network/http/webrick.rb +2 -2
  153. data/spec/unit/network/rest_authconfig.rb +2 -2
  154. data/spec/unit/network/rights.rb +1 -1
  155. data/spec/unit/node/environment.rb +39 -23
  156. data/spec/unit/other/selinux.rb +2 -2
  157. data/spec/unit/parameter.rb +8 -0
  158. data/spec/unit/parser/ast/leaf.rb +9 -0
  159. data/spec/unit/parser/ast/selector.rb +8 -1
  160. data/spec/unit/parser/lexer.rb +1 -1
  161. data/spec/unit/parser/resource.rb +11 -0
  162. data/spec/unit/parser/resource/reference.rb +13 -1
  163. data/spec/unit/property.rb +6 -0
  164. data/spec/unit/provider/mount/parsed.rb +3 -1
  165. data/spec/unit/provider/service/debian.rb +1 -1
  166. data/spec/unit/provider/ssh_authorized_key/parsed.rb +9 -1
  167. data/spec/unit/provider/sshkey/parsed.rb +19 -0
  168. data/spec/unit/rails.rb +22 -9
  169. data/spec/unit/rails/resource.rb +20 -0
  170. data/spec/unit/ssl/host.rb +19 -57
  171. data/spec/unit/transaction.rb +39 -4
  172. data/spec/unit/type.rb +9 -0
  173. data/spec/unit/type/file/content.rb +29 -0
  174. data/spec/unit/type/maillist.rb +42 -0
  175. data/spec/unit/type/resources.rb +66 -1
  176. data/spec/unit/type/tidy.rb +14 -1
  177. data/spec/unit/util/autoload.rb +2 -0
  178. data/spec/unit/util/ldap/connection.rb +1 -1
  179. data/spec/unit/util/log.rb +14 -0
  180. data/spec/unit/util/monkey_patches.rb +103 -0
  181. data/spec/unit/util/queue.rb +10 -2
  182. data/spec/unit/util/selinux.rb +61 -2
  183. data/spec/unit/util/settings.rb +19 -0
  184. data/spec/unit/util/settings/file_setting.rb +25 -0
  185. data/spec/unit/util/tagging.rb +10 -0
  186. data/tasks/rake/changelog.rake +15 -0
  187. data/tasks/rake/ci.rake +22 -0
  188. data/tasks/rake/dailybuild.rake +9 -0
  189. data/tasks/rake/gem.rake +46 -0
  190. data/tasks/rake/git_workflow.rake +121 -0
  191. data/tasks/rake/metrics.rake +6 -0
  192. data/tasks/rake/sign.rake +14 -0
  193. data/tasks/rake/testbranch.rake +16 -0
  194. data/tasks/rake/tracdocs.rake +8 -0
  195. data/test/data/providers/ssh_authorized_key/parsed/authorized_keys +1 -0
  196. metadata +1042 -1288
  197. data/ext/bin/sleeper +0 -67
  198. data/ext/module_puppet +0 -209
@@ -28,7 +28,8 @@ class Puppet::SSL::Certificate < Puppet::SSL::Base
28
28
  end
29
29
 
30
30
  def expiration
31
- return nil unless content
32
- return content.not_after
31
+ # Our expiration is either that of the cache or the content, whichever comes first
32
+ cache_expiration = @expiration
33
+ [(content and content.not_after), cache_expiration].compact.sort.first
33
34
  end
34
35
  end
@@ -94,12 +94,7 @@ class Puppet::SSL::Host
94
94
 
95
95
  # Remove all traces of a given host
96
96
  def self.destroy(name)
97
- [Key, Certificate, CertificateRequest].inject(false) do |result, klass|
98
- if klass.destroy(name)
99
- result = true
100
- end
101
- result
102
- end
97
+ [Key, Certificate, CertificateRequest].collect { |part| part.destroy(name) }.any? { |x| x }
103
98
  end
104
99
 
105
100
  # Search for more than one host, optionally only specifying
@@ -107,12 +102,7 @@ class Puppet::SSL::Host
107
102
  # This just allows our non-indirected class to have one of
108
103
  # indirection methods.
109
104
  def self.search(options = {})
110
- classes = [Key, CertificateRequest, Certificate]
111
- if klass = options[:for]
112
- classlist = [klass].flatten
113
- else
114
- classlist = [Key, CertificateRequest, Certificate]
115
- end
105
+ classlist = [options[:for] || [Key, CertificateRequest, Certificate]].flatten
116
106
 
117
107
  # Collect the results from each class, flatten them, collect all of the names, make the name list unique,
118
108
  # then create a Host instance for each one.
@@ -127,8 +117,7 @@ class Puppet::SSL::Host
127
117
  end
128
118
 
129
119
  def key
130
- return nil unless @key ||= Key.find(name)
131
- @key
120
+ @key ||= Key.find(name)
132
121
  end
133
122
 
134
123
  # This is the private key; we can create it from scratch
@@ -146,8 +135,7 @@ class Puppet::SSL::Host
146
135
  end
147
136
 
148
137
  def certificate_request
149
- return nil unless @certificate_request ||= CertificateRequest.find(name)
150
- @certificate_request
138
+ @certificate_request ||= CertificateRequest.find(name)
151
139
  end
152
140
 
153
141
  # Our certificate request requires the key but that's all.
@@ -166,26 +154,19 @@ class Puppet::SSL::Host
166
154
  end
167
155
 
168
156
  def certificate
169
- unless @certificate
170
- generate_key unless key
171
-
157
+ @certificate ||= (
172
158
  # get the CA cert first, since it's required for the normal cert
173
159
  # to be of any use.
174
- return nil unless Certificate.find("ca") unless ca?
175
- return nil unless @certificate = Certificate.find(name)
176
-
177
- unless certificate_matches_key?
178
- raise Puppet::Error, "Retrieved certificate does not match private key; please remove certificate from server and regenerate it with the current key"
160
+ if not (key or generate_key) or not (ca? or Certificate.find("ca")) or not (cert = Certificate.find(name)) or cert.expired?
161
+ nil
162
+ elsif not cert.content.check_private_key(key.content)
163
+ Certificate.expire(name)
164
+ Puppet.warning "Retrieved certificate does not match private key"
165
+ nil
166
+ else
167
+ cert
179
168
  end
180
- end
181
- @certificate
182
- end
183
-
184
- def certificate_matches_key?
185
- return false unless key
186
- return false unless certificate
187
-
188
- return certificate.content.check_private_key(key.content)
169
+ )
189
170
  end
190
171
 
191
172
  # Generate all necessary parts of our ssl host.
@@ -2,11 +2,7 @@
2
2
 
3
3
  require 'puppet'
4
4
 
5
- begin
6
- require 'openssl'
7
- rescue LoadError
8
- raise Puppet::Error, "You must have the Ruby openssl library installed"
9
- end
5
+ raise Puppet::Error, "You must have the Ruby openssl library installed" unless Puppet.features.openssl?
10
6
 
11
7
  module Puppet::SSLCertificates
12
8
  #def self.mkcert(type, name, dnsnames, ttl, issuercert, issuername, serial, publickey)
@@ -134,7 +134,7 @@ class Puppet::SSLCertificates::CA
134
134
 
135
135
  # List certificates waiting to be signed. This returns a list of hostnames, not actual
136
136
  # files -- the names can be converted to full paths with host2csrfile.
137
- def list
137
+ def list(dummy_argument=:work_arround_for_ruby_GC_bug)
138
138
  return Dir.entries(Puppet[:csrdir]).find_all { |file|
139
139
  file =~ /\.pem$/
140
140
  }.collect { |file|
@@ -144,7 +144,7 @@ class Puppet::SSLCertificates::CA
144
144
 
145
145
  # List signed certificates. This returns a list of hostnames, not actual
146
146
  # files -- the names can be converted to full paths with host2csrfile.
147
- def list_signed
147
+ def list_signed(dummy_argument=:work_arround_for_ruby_GC_bug)
148
148
  return Dir.entries(Puppet[:signeddir]).find_all { |file|
149
149
  file =~ /\.pem$/
150
150
  }.collect { |file|
@@ -278,12 +278,13 @@ class Puppet::SSLCertificates::CA
278
278
  host = thing2name(csr)
279
279
 
280
280
  csrfile = host2csrfile(host)
281
- if File.exists?(csrfile)
282
- raise Puppet::Error, "Certificate request for %s already exists" % host
283
- end
281
+ raise Puppet::Error, "Certificate request for #{host} already exists" if File.exists?(csrfile)
282
+ Puppet.settings.writesub(:csrdir, csrfile) { |f| f.print csr.to_pem }
284
283
 
285
- Puppet.settings.writesub(:csrdir, csrfile) do |f|
286
- f.print csr.to_pem
284
+ certfile = host2certfile(host)
285
+ if File.exists?(certfile)
286
+ Puppet.notice "Removing previously signed certificate #{certfile} for #{host}"
287
+ Puppet::SSLCertificates::Inventory::rebuild
287
288
  end
288
289
  end
289
290
 
@@ -2,6 +2,7 @@
2
2
  # and performs them
3
3
 
4
4
  require 'puppet'
5
+ require 'puppet/util/tagging'
5
6
 
6
7
  module Puppet
7
8
  class Transaction
@@ -18,6 +19,7 @@ class Transaction
18
19
  attr_reader :events
19
20
 
20
21
  include Puppet::Util
22
+ include Puppet::Util::Tagging
21
23
 
22
24
  # Add some additional times for reporting
23
25
  def addtimes(hash)
@@ -353,6 +355,7 @@ class Transaction
353
355
  made = [made] unless made.is_a?(Array)
354
356
  made.uniq.find_all do |res|
355
357
  begin
358
+ res.tag(*resource.tags)
356
359
  @catalog.add_resource(res) do |r|
357
360
  r.finish
358
361
  make_parent_child_relationship(resource, [r])
@@ -601,26 +604,26 @@ class Transaction
601
604
  # The tags we should be checking.
602
605
  def tags
603
606
  unless defined? @tags
604
- tags = Puppet[:tags]
605
- if tags.nil? or tags == ""
606
- @tags = []
607
- else
608
- @tags = tags.split(/\s*,\s*/)
609
- end
607
+ self.tags = Puppet[:tags]
610
608
  end
611
609
 
612
- @tags
610
+ super
613
611
  end
614
612
 
615
- def tags=(tags)
616
- tags = [tags] unless tags.is_a?(Array)
617
- @tags = tags
613
+ def handle_qualified_tags( qualified )
614
+ # The default behavior of Puppet::Util::Tagging is
615
+ # to split qualified tags into parts. That would cause
616
+ # qualified tags to match too broadly here.
617
+ return
618
618
  end
619
619
 
620
620
  # Is this resource tagged appropriately?
621
621
  def missing_tags?(resource)
622
- return false if self.ignore_tags? or tags.empty?
623
- return true unless resource.tagged?(tags)
622
+ not appropriately_tagged?(resource)
623
+ end
624
+
625
+ def appropriately_tagged?(resource)
626
+ self.ignore_tags? or tags.empty? or resource.tagged?(*tags)
624
627
  end
625
628
 
626
629
  # Are there any edges that target this resource?
@@ -210,8 +210,8 @@ class Type
210
210
  end
211
211
 
212
212
  # Find the namevar
213
- def self.namevar
214
- unless defined? @namevar
213
+ def self.namevar_parameter
214
+ @namevar_parameter ||= (
215
215
  params = @parameters.find_all { |param|
216
216
  param.isnamevar? or param.name == :name
217
217
  }
@@ -219,12 +219,19 @@ class Type
219
219
  if params.length > 1
220
220
  raise Puppet::DevError, "Found multiple namevars for %s" % self.name
221
221
  elsif params.length == 1
222
- @namevar = params[0].name
222
+ params.first
223
223
  else
224
224
  raise Puppet::DevError, "No namevar for %s" % self.name
225
225
  end
226
- end
227
- @namevar
226
+ )
227
+ end
228
+
229
+ def self.namevar
230
+ @namevar ||= namevar_parameter.name
231
+ end
232
+
233
+ def self.canonicalize_ref(s)
234
+ namevar_parameter.canonicalize(s)
228
235
  end
229
236
 
230
237
  # Create a new parameter. Requires a block and a name, stores it in the
@@ -31,7 +31,7 @@ module Puppet
31
31
 
32
32
  validate do |value|
33
33
  unless value =~ /^#{File::SEPARATOR}/
34
- raise Puppet::Error, "File paths must be fully qualified, not '%s'" % value
34
+ fail Puppet::Error,"File paths must be fully qualified, not '#{value}'"
35
35
  end
36
36
  end
37
37
 
@@ -46,6 +46,12 @@ module Puppet
46
46
  unmunge do |value|
47
47
  File.join( Puppet::FileCollection.collection.path(value[:index]), value[:name] )
48
48
  end
49
+
50
+ to_canonicalize do |s|
51
+ # Get rid of any duplicate slashes, and remove any trailing slashes unless
52
+ # the title is just a slash, in which case leave it.
53
+ s.gsub(/\/+/, "/").sub(/(.)\/$/,'\1')
54
+ end
49
55
  end
50
56
 
51
57
  newparam(:backup) do
@@ -120,10 +126,10 @@ module Puppet
120
126
  munge do |value|
121
127
  newval = super(value)
122
128
  case newval
123
- when :true, :inf: true
124
- when :false: false
125
- when :remote: :remote
126
- when Integer, Fixnum, Bignum:
129
+ when :true, :inf; true
130
+ when :false; false
131
+ when :remote; :remote
132
+ when Integer, Fixnum, Bignum
127
133
  self.warning "Setting recursion depth with the recurse parameter is now deprecated, please use recurselimit"
128
134
 
129
135
  # recurse == 0 means no recursion
@@ -131,7 +137,7 @@ module Puppet
131
137
 
132
138
  resource[:recurselimit] = value
133
139
  true
134
- when /^\d+$/:
140
+ when /^\d+$/
135
141
  self.warning "Setting recursion depth with the recurse parameter is now deprecated, please use recurselimit"
136
142
  value = Integer(value)
137
143
 
@@ -141,7 +147,7 @@ module Puppet
141
147
  resource[:recurselimit] = value
142
148
  true
143
149
  else
144
- raise ArgumentError, "Invalid recurse value %s" % value.inspect
150
+ self.fail "Invalid recurse value #{value.inspect}"
145
151
  end
146
152
  end
147
153
  end
@@ -154,10 +160,10 @@ module Puppet
154
160
  munge do |value|
155
161
  newval = super(value)
156
162
  case newval
157
- when Integer, Fixnum, Bignum: value
158
- when /^\d+$/: Integer(value)
163
+ when Integer, Fixnum, Bignum; value
164
+ when /^\d+$/; Integer(value)
159
165
  else
160
- raise ArgumentError, "Invalid recurselimit value %s" % value.inspect
166
+ self.fail "Invalid recurselimit value #{value.inspect}"
161
167
  end
162
168
  end
163
169
  end
@@ -399,11 +405,7 @@ module Puppet
399
405
 
400
406
  super
401
407
 
402
- # Get rid of any duplicate slashes, and remove any trailing slashes.
403
- @title = @title.gsub(/\/+/, "/")
404
-
405
- @title.sub!(/\/$/, "") unless @title == "/"
406
-
408
+ @title = self.class.canonicalize_ref(@title)
407
409
  @stat = nil
408
410
  end
409
411
 
@@ -494,26 +496,18 @@ module Puppet
494
496
  # not likely to have many actual conflicts, which is good, because
495
497
  # this is a pretty inefficient implementation.
496
498
  def remove_less_specific_files(files)
497
- # We sort the paths so we can short-circuit some tests.
498
- mypath = self[:path]
499
- other_paths = catalog.vertices.find_all do |r|
500
- r.is_a?(self.class) and r[:path][0..(mypath.length - 1)] == mypath
501
- end.collect { |r| r[:path] }.sort { |a, b| a.length <=> b.length } - [self[:path]]
499
+ mypath = self[:path].split(File::Separator)
500
+ other_paths = catalog.vertices.
501
+ select { |r| r.is_a?(self.class) and r[:path] != self[:path] }.
502
+ collect { |r| r[:path].split(File::Separator) }.
503
+ select { |p| p[0,mypath.length] == mypath }
502
504
 
503
505
  return files if other_paths.empty?
504
506
 
505
- remove = []
506
- files.each do |file|
507
- path = file[:path]
508
- other_paths.each do |p|
509
- if path[0..(p.length - 1)] == p
510
- remove << file
511
- break
512
- end
513
- end
514
- end
515
-
516
- files - remove
507
+ files.reject { |file|
508
+ path = file[:path].split(File::Separator)
509
+ other_paths.any? { |p| path[0,p.length] == p }
510
+ }
517
511
  end
518
512
 
519
513
  # A simple method for determining whether we should be recursing.
@@ -96,7 +96,7 @@ module Puppet
96
96
  return true if ! @resource.replace?
97
97
 
98
98
  if self.should
99
- return super
99
+ result = super
100
100
  elsif source = resource.parameter(:source)
101
101
  fail "Got a remote source with no checksum" unless source.checksum
102
102
  result = (is == source.checksum)
@@ -114,14 +114,14 @@ module Puppet
114
114
 
115
115
  def retrieve
116
116
  return :absent unless stat = @resource.stat
117
-
117
+ ftype = stat.ftype
118
118
  # Don't even try to manage the content on directories or links
119
- return nil if stat.ftype == "directory"
119
+ return nil if ["directory","link"].include? ftype or checksum_type.nil?
120
120
 
121
121
  begin
122
- return "{#{checksum_type}}" + send(checksum_type.to_s + "_file", resource[:path]).to_s
122
+ "{#{checksum_type}}" + send(checksum_type.to_s + "_file", resource[:path]).to_s
123
123
  rescue => detail
124
- raise Puppet::Error, "Could not read %s: %s" % [@resource.title, detail]
124
+ raise Puppet::Error, "Could not read #{ftype} #{@resource.title}: #{detail}"
125
125
  end
126
126
  end
127
127
 
@@ -80,13 +80,9 @@ module Puppet
80
80
 
81
81
 
82
82
  newvalue(:link) do
83
- if property = @resource.property(:target)
84
- property.retrieve
85
-
86
- return property.mklink
87
- else
88
- self.fail "Cannot create a symlink without a target"
89
- end
83
+ fail "Cannot create a symlink without a target" unless property = resource.property(:target)
84
+ property.retrieve
85
+ property.mklink
90
86
  end
91
87
 
92
88
  # Symlinks.
@@ -97,16 +93,9 @@ module Puppet
97
93
 
98
94
  munge do |value|
99
95
  value = super(value)
100
-
101
- # It doesn't make sense to try to manage links unless, well,
102
- # we're managing links.
103
- resource[:links] = :manage if value == :link
104
- return value if value.is_a? Symbol
105
-
106
- @resource[:target] = value
107
- resource[:links] = :manage
108
-
109
- return :link
96
+ value,resource[:target] = :link,value unless value.is_a? Symbol
97
+ resource[:links] = :manage if value == :link and resource[:links] != :follow
98
+ value
110
99
  end
111
100
 
112
101
  def change_to_s(currentvalue, newvalue)
@@ -5,7 +5,24 @@ module Puppet
5
5
  Puppet::Type.type(:file).newproperty(:mode) do
6
6
  require 'etc'
7
7
  desc "Mode the file should be. Currently relatively limited:
8
- you must specify the exact mode the file should be."
8
+ you must specify the exact mode the file should be.
9
+
10
+ Note that when you set the mode of a directory, Puppet always
11
+ sets the search/traverse (1) bit anywhere the read (4) bit is set.
12
+ This is almost always what you want: read allows you to list the
13
+ entries in a directory, and search/traverse allows you to access
14
+ (read/write/execute) those entries.) Because of this feature, you
15
+ can recursively make a directory and all of the files in it
16
+ world-readable by setting e.g.::
17
+
18
+ file { '/some/dir':
19
+ mode => 644,
20
+ recurse => true,
21
+ }
22
+
23
+ In this case all of the files underneath ``/some/dir`` will have
24
+ mode 644, and all of the directories will have mode 755."
25
+
9
26
  @event = :file_changed
10
27
 
11
28
  # Our modes are octal, so make sure they print correctly. Other
@@ -93,11 +93,7 @@ module Puppet
93
93
  end
94
94
 
95
95
  def checksum
96
- if metadata
97
- metadata.checksum
98
- else
99
- nil
100
- end
96
+ metadata && metadata.checksum
101
97
  end
102
98
 
103
99
  # Look up (if necessary) and return remote content.
@@ -119,16 +115,20 @@ module Puppet
119
115
  [:owner, :mode, :group, :checksum].each do |param|
120
116
  next if param == :owner and Puppet::Util::SUIDManager.uid != 0
121
117
  next if param == :checksum and metadata.ftype == "directory"
122
- unless value = @resource[param] and value != :absent
123
- @resource[param] = metadata.send(param)
118
+ unless value = resource[param] and value != :absent
119
+ resource[param] = metadata.send(param)
124
120
  end
125
121
  end
126
122
 
127
- # Set the 'ensure' value, unless we're trying to delete the file.
128
- @resource[:ensure] = metadata.ftype unless @resource[:ensure] == :absent
129
-
130
- if metadata.ftype == "link"
131
- @resource[:target] = metadata.destination
123
+ if resource[:ensure] == :absent
124
+ # We know all we need to
125
+ elsif metadata.ftype != "link"
126
+ resource[:ensure] = metadata.ftype
127
+ elsif @resource[:links] == :follow
128
+ resource[:ensure] = :present
129
+ else
130
+ resource[:ensure] = "link"
131
+ resource[:target] = metadata.destination
132
132
  end
133
133
  end
134
134