diff options
author | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2007-07-11 20:23:49 +0000 |
---|---|---|
committer | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2007-07-11 20:23:49 +0000 |
commit | d104d4b32b34434e42a83078bccaa68890c1b373 (patch) | |
tree | e11ab0b246ed044c3fd61491e4b3501c9341366e /lib/puppet | |
parent | 17a830d5421a0ae9d84914a4215010bf4b16253f (diff) | |
download | puppet-d104d4b32b34434e42a83078bccaa68890c1b373.tar.gz puppet-d104d4b32b34434e42a83078bccaa68890c1b373.tar.xz puppet-d104d4b32b34434e42a83078bccaa68890c1b373.zip |
Having FileType instances automatically back their contents up to a filebucket, so it is much harder to lose content. This does not yet back up crontab contents, though.
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@2679 980ebf18-57e1-0310-9a29-db15c13687c0
Diffstat (limited to 'lib/puppet')
-rw-r--r-- | lib/puppet/network/client/dipper.rb | 2 | ||||
-rwxr-xr-x | lib/puppet/provider/parsedfile.rb | 1 | ||||
-rwxr-xr-x | lib/puppet/type/pfilebucket.rb | 5 | ||||
-rwxr-xr-x | lib/puppet/util/filetype.rb | 11 |
4 files changed, 15 insertions, 4 deletions
diff --git a/lib/puppet/network/client/dipper.rb b/lib/puppet/network/client/dipper.rb index 5ddb67db1..c16e37725 100644 --- a/lib/puppet/network/client/dipper.rb +++ b/lib/puppet/network/client/dipper.rb @@ -19,7 +19,7 @@ class Puppet::Network::Client::Dipper < Puppet::Network::Client # Back up a file to our bucket def backup(file) unless FileTest.exists?(file) - raise(BucketError, "File %s does not exist" % file) + raise(ArgumentError, "File %s does not exist" % file) end contents = ::File.read(file) unless local? diff --git a/lib/puppet/provider/parsedfile.rb b/lib/puppet/provider/parsedfile.rb index 4e3dac8f8..cdb770b8b 100755 --- a/lib/puppet/provider/parsedfile.rb +++ b/lib/puppet/provider/parsedfile.rb @@ -316,7 +316,6 @@ class Puppet::Provider::ParsedFile < Puppet::Provider end @property_hash[:name] ||= @resource.name - warning "Flushing" self.class.flush(@property_hash) end diff --git a/lib/puppet/type/pfilebucket.rb b/lib/puppet/type/pfilebucket.rb index fd0f131a1..df30c1872 100755 --- a/lib/puppet/type/pfilebucket.rb +++ b/lib/puppet/type/pfilebucket.rb @@ -65,9 +65,10 @@ module Puppet # Create a default filebucket. def self.mkdefaultbucket - unless self["puppet"] - self.create :name => "puppet", :path => Puppet[:clientbucketdir] + unless default = self["puppet"] + default = self.create :name => "puppet", :path => Puppet[:clientbucketdir] end + default end def self.instances diff --git a/lib/puppet/util/filetype.rb b/lib/puppet/util/filetype.rb index 8abe0cc00..7ce732b63 100755 --- a/lib/puppet/util/filetype.rb +++ b/lib/puppet/util/filetype.rb @@ -67,6 +67,16 @@ class Puppet::Util::FileType @filetypes[type] end + # Back the file up before replacing it. + def backup + bucket.backup(@path) if FileTest.exists?(@path) + end + + # Pick or create a filebucket to use. + def bucket + Puppet::Type.type(:filebucket).mkdefaultbucket.bucket + end + def initialize(path) @path = path end @@ -91,6 +101,7 @@ class Puppet::Util::FileType # Overwrite the file. def write(text) + backup() File.open(@path, "w") { |f| f.print text; f.flush } end end |