summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2006-08-21 22:54:17 +0000
committerluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2006-08-21 22:54:17 +0000
commitbf43c76deddb8475fea43515ebd530b5d3f331a2 (patch)
tree96376c18daa8fd49a7776a2ca2f33f2d385ebd62
parentaee1c6a6ad10e3a42a8f4150b4838425e3580253 (diff)
downloadpuppet-bf43c76deddb8475fea43515ebd530b5d3f331a2.tar.gz
puppet-bf43c76deddb8475fea43515ebd530b5d3f331a2.tar.xz
puppet-bf43c76deddb8475fea43515ebd530b5d3f331a2.zip
Fixing #228. The real problem was that "present" should match any type of file existence, whereas it was just matching files. If the file was a directory, as in this case, Puppet considered it to be out of sync. Now, "present" matches files, links, or directories, but still creates an empty file if the path is missing.
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@1477 980ebf18-57e1-0310-9a29-db15c13687c0
-rwxr-xr-xlib/puppet/type/pfile/ensure.rb29
-rw-r--r--test/types/file.rb41
2 files changed, 66 insertions, 4 deletions
diff --git a/lib/puppet/type/pfile/ensure.rb b/lib/puppet/type/pfile/ensure.rb
index f22e43637..ac045dfd6 100755
--- a/lib/puppet/type/pfile/ensure.rb
+++ b/lib/puppet/type/pfile/ensure.rb
@@ -2,9 +2,11 @@ module Puppet
Puppet.type(:file).ensurable do
require 'etc'
desc "Whether to create files that don't currently exist.
- Possible values are *absent*, *present* (equivalent to *file*),
- *file*, and *directory*. Specifying 'absent' will delete the file,
- although currently this will not recursively delete directories.
+ Possible values are *absent*, *present* (equivalent to ``exists`` in
+ most file tests -- will match any form of file existence, and if the
+ file is missing will create an empty file), *file*, and
+ *directory*. Specifying ``absent`` will delete the file, although
+ currently this will not recursively delete directories.
Anything other than those values will be considered to be a symlink.
For instance, the following text creates a link:
@@ -50,7 +52,12 @@ module Puppet
return :file_created
end
- aliasvalue(:present, :file)
+ #aliasvalue(:present, :file)
+ newvalue(:present) do
+ # Make a file if they want something, but this will match almost
+ # anything.
+ set_file
+ end
newvalue(:directory) do
mode = @parent.should(:mode)
@@ -120,6 +127,20 @@ module Puppet
end
end
+ # We have to treat :present specially, because it works with any
+ # type of file.
+ def insync?
+ if self.should == :present
+ if @is.nil? or @is == :absent
+ return false
+ else
+ return true
+ end
+ else
+ return super
+ end
+ end
+
def retrieve
if stat = @parent.stat(false)
@is = stat.ftype.intern
diff --git a/test/types/file.rb b/test/types/file.rb
index eeb976370..551d96d89 100644
--- a/test/types/file.rb
+++ b/test/types/file.rb
@@ -1310,6 +1310,47 @@ class TestFile < Test::Unit::TestCase
assert(FileTest.exists?(dest), "File did not get created")
end
+
+ def test_present_matches_anything
+ path = tempfile()
+
+ file = Puppet::Type.newfile(:path => path, :ensure => :present)
+
+ file.retrieve
+ assert(! file.insync?, "File incorrectly in sync")
+
+ # Now make a file
+ File.open(path, "w") { |f| f.puts "yay" }
+
+ file.retrieve
+ assert(file.insync?, "File not in sync")
+
+ # Now make a directory
+ File.unlink(path)
+ Dir.mkdir(path)
+
+ file.retrieve
+ assert(file.insync?, "Directory not considered 'present'")
+
+ Dir.rmdir(path)
+
+ # Now make a link
+ file[:links] = :manage
+
+ otherfile = tempfile()
+ File.symlink(otherfile, path)
+
+ file.retrieve
+ assert(file.insync?, "Symlink not considered 'present'")
+ File.unlink(path)
+
+ # Now set some content, and make sure it works
+ file[:content] = "yayness"
+
+ assert_apply(file)
+
+ assert_equal("yayness", File.read(path), "Content did not get set correctly")
+ end
end
# $Id$