summaryrefslogtreecommitdiffstats
path: root/lib/puppet
diff options
context:
space:
mode:
authorluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2006-01-12 16:57:34 +0000
committerluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2006-01-12 16:57:34 +0000
commitc5782dfb9aa6ecfab045d348a7d07e38bcb4a8e2 (patch)
tree94c0639ec0abf347a5891ea177319f7e6fc5348f /lib/puppet
parentb0ea70db255f36977593a6373a189f63dc9a268f (diff)
downloadpuppet-c5782dfb9aa6ecfab045d348a7d07e38bcb4a8e2.tar.gz
puppet-c5782dfb9aa6ecfab045d348a7d07e38bcb4a8e2.tar.xz
puppet-c5782dfb9aa6ecfab045d348a7d07e38bcb4a8e2.zip
Adding "content" state to files, and string interpolation handles escaped whitespace characters.
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@813 980ebf18-57e1-0310-9a29-db15c13687c0
Diffstat (limited to 'lib/puppet')
-rw-r--r--lib/puppet/parser/scope.rb2
-rw-r--r--lib/puppet/type/pfile.rb7
-rwxr-xr-xlib/puppet/type/pfile/content.rb46
3 files changed, 54 insertions, 1 deletions
diff --git a/lib/puppet/parser/scope.rb b/lib/puppet/parser/scope.rb
index c5ee0226a..a2d05e7d4 100644
--- a/lib/puppet/parser/scope.rb
+++ b/lib/puppet/parser/scope.rb
@@ -534,7 +534,7 @@ module Puppet
end
end
#Puppet.debug("result is '%s'" % newstring)
- return newstring
+ return newstring.gsub(/\\t/, "\t").gsub(/\\n/, "\n").gsub(/\\s/, "\s")
end
# This method will fail if the named object is already defined anywhere
diff --git a/lib/puppet/type/pfile.rb b/lib/puppet/type/pfile.rb
index c13e7038d..6a52d31e9 100644
--- a/lib/puppet/type/pfile.rb
+++ b/lib/puppet/type/pfile.rb
@@ -85,6 +85,12 @@ module Puppet
}
end
+ validate do
+ if self[:content] and self[:source]
+ raise Puppet::Error, "You cannot specify both content and a source"
+ end
+ end
+
@depthfirst = false
@@ -540,6 +546,7 @@ end
# the order they are in the state list.
require 'puppet/type/pfile/create'
require 'puppet/type/pfile/checksum'
+require 'puppet/type/pfile/content'
require 'puppet/type/pfile/source'
require 'puppet/type/pfile/uid'
require 'puppet/type/pfile/group'
diff --git a/lib/puppet/type/pfile/content.rb b/lib/puppet/type/pfile/content.rb
new file mode 100755
index 000000000..45aebdbda
--- /dev/null
+++ b/lib/puppet/type/pfile/content.rb
@@ -0,0 +1,46 @@
+module Puppet
+ Puppet.type(:file).newstate(:content) do
+ desc "Specify the contents of a file as a string. Newlines, tabs, and spaces
+ can be specified using the escaped syntax (e.g., \\n for a newline). The
+ primary purpose of this parameter is to provide a kind of limited
+ templating."
+
+ # We should probably take advantage of existing md5 sums if they're there,
+ # but I really don't feel like dealing with the complexity right now.
+ def retrieve
+ unless FileTest.exists?(@parent.name)
+ @is = :notfound
+ return
+ end
+ begin
+ @is = File.read(@parent.name)
+ rescue => detail
+ @is = nil
+ raise Puppet::Error, "Could not read %s: %s" %
+ [@parent.name, detail]
+ end
+ end
+
+
+ # Just write our content out to disk.
+ def sync
+ begin
+ File.open(@parent.name, "w") { |f|
+ f.print self.should
+ f.flush
+ }
+ rescue => detail
+ raise Puppet::Error, "Could not write content to %s: %s" %
+ [@parent.name, detail]
+ end
+
+ if @is == :notfound
+ return :file_created
+ else
+ return :file_changed
+ end
+ end
+ end
+end
+
+# $Id$