summaryrefslogtreecommitdiffstats
path: root/lib/puppet
diff options
context:
space:
mode:
authorMarkus Roberts <Markus@reality.com>2010-05-01 10:13:19 -0700
committerJames Turnbull <james@lovedthanlost.net>2010-05-02 17:58:04 +1000
commitbcde541e4433aa46c9f922b01e34368a09abb7e8 (patch)
treefe7acfb7067a5531b9bfb9bc2faa70d01ea80131 /lib/puppet
parent5abe571e167744ac198960c8e35c699375ec5cf7 (diff)
downloadpuppet-bcde541e4433aa46c9f922b01e34368a09abb7e8.tar.gz
puppet-bcde541e4433aa46c9f922b01e34368a09abb7e8.tar.xz
puppet-bcde541e4433aa46c9f922b01e34368a09abb7e8.zip
Fix for #2910 -- Tidy/matches is too tricky to use
The semantic interaction of tidy/matches and tidy/recurse is tricky to get right; it only makes sense to use matches with recursion (a fixed path will either statically match or it won't, no need for a run-time check) but there was nothing to warn users of this fact. To compound matters, the example in the matches parameter doc string even made this mistake. This patch: 1) fixes the doc string; 2) prohibits the use of match without a value of recurse capable of generating files to match, 3) fixes tests that were passing for the wrong reason and adds tests on the prohibition added in (2).
Diffstat (limited to 'lib/puppet')
-rwxr-xr-xlib/puppet/type/tidy.rb64
1 files changed, 35 insertions, 29 deletions
diff --git a/lib/puppet/type/tidy.rb b/lib/puppet/type/tidy.rb
index 3d7190c27..a4b87d5fa 100755
--- a/lib/puppet/type/tidy.rb
+++ b/lib/puppet/type/tidy.rb
@@ -19,6 +19,28 @@ Puppet::Type.newtype(:tidy) do
isnamevar
end
+ newparam(:recurse) do
+ desc "If target is a directory, recursively descend
+ into the directory looking for files to tidy."
+
+ newvalues(:true, :false, :inf, /^[0-9]+$/)
+
+ # Replace the validation so that we allow numbers in
+ # addition to string representations of them.
+ validate { |arg| }
+ munge do |value|
+ newval = super(value)
+ case newval
+ when :true, :inf; true
+ when :false; false
+ when Integer, Fixnum, Bignum; value
+ when /^\d+$/; Integer(value)
+ else
+ raise ArgumentError, "Invalid recurse value %s" % value.inspect
+ end
+ end
+ end
+
newparam(:matches) do
desc "One or more (shell type) file glob patterns, which restrict
the list of files to be tidied to those whose basenames match
@@ -29,22 +51,28 @@ Puppet::Type.newtype(:tidy) do
tidy { \"/tmp\":
age => \"1w\",
- recurse => false,
+ recurse => 1,
matches => [ \"[0-9]pub*.tmp\", \"*.temp\", \"tmpfile?\" ]
}
This removes files from \/tmp if they are one week old or older,
are not in a subdirectory and match one of the shell globs given.
- Note that the patterns are matched against the
- basename of each file -- that is, your glob patterns should not
- have any '/' characters in them, since you are only specifying
- against the last bit of the file."
+ Note that the patterns are matched against the basename of each
+ file -- that is, your glob patterns should not have any '/'
+ characters in them, since you are only specifying against the last
+ bit of the file.
+
+ Finally, note that you must now specify a non-zero/non-false value
+ for recurse if matches is used, as matches only apply to files found
+ by recursion (there's no reason to use static patterns match against
+ a statically determined path). Requiering explicit recursion clears
+ up a common source of confusion."
# Make sure we convert to an array.
munge do |value|
- value = [value] unless value.is_a?(Array)
- value
+ fail "Tidy can't use matches with recurse 0, false, or undef" if "#{@resource[:recurse]}" =~ /^(0|false|)$/
+ [value].flatten
end
# Does a given path match our glob patterns, if any? Return true
@@ -170,28 +198,6 @@ Puppet::Type.newtype(:tidy) do
defaultto :atime
end
- newparam(:recurse) do
- desc "If target is a directory, recursively descend
- into the directory looking for files to tidy."
-
- newvalues(:true, :false, :inf, /^[0-9]+$/)
-
- # Replace the validation so that we allow numbers in
- # addition to string representations of them.
- validate { |arg| }
- munge do |value|
- newval = super(value)
- case newval
- when :true, :inf; true
- when :false; false
- when Integer, Fixnum, Bignum; value
- when /^\d+$/; Integer(value)
- else
- raise ArgumentError, "Invalid recurse value %s" % value.inspect
- end
- end
- end
-
newparam(:rmdirs, :boolean => true) do
desc "Tidy directories in addition to files; that is, remove
directories whose age is older than the specified criteria.