summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2009-01-15 15:44:09 -0600
committerJames Turnbull <james@lovedthanlost.net>2009-02-13 14:16:36 +1100
commitd5a193a594bbc2194dbf1e5264369ebea0e55880 (patch)
tree8078cfd0c8c180ded487aa1427354025742014d8 /lib
parent53f15b9208a3271e944c687b8d0e670d422fb832 (diff)
downloadpuppet-d5a193a594bbc2194dbf1e5264369ebea0e55880.tar.gz
puppet-d5a193a594bbc2194dbf1e5264369ebea0e55880.tar.xz
puppet-d5a193a594bbc2194dbf1e5264369ebea0e55880.zip
Fixing #1541 - ParsedFile only backs up files once per transaction
This moves responsibility for backups from the filetype to the consumer of the filetype, but only ParsedFile actually uses filetypes. Signed-off-by: Luke Kanies <luke@madstop.com>
Diffstat (limited to 'lib')
-rwxr-xr-xlib/puppet/provider/parsedfile.rb14
-rwxr-xr-xlib/puppet/util/filetype.rb1
2 files changed, 14 insertions, 1 deletions
diff --git a/lib/puppet/provider/parsedfile.rb b/lib/puppet/provider/parsedfile.rb
index a4c4bc87c..45eae57ff 100755
--- a/lib/puppet/provider/parsedfile.rb
+++ b/lib/puppet/provider/parsedfile.rb
@@ -78,8 +78,22 @@ class Puppet::Provider::ParsedFile < Puppet::Provider
@modified.reject! { |t| flushed.include?(t) }
end
+ # Make sure our file is backed up, but only back it up once per transaction.
+ # We cheat and rely on the fact that @records is created on each prefetch.
+ def self.backup_target(target)
+ unless defined?(@backup_stats)
+ @backup_stats = {}
+ end
+ return nil if @backup_stats[target] == @records.object_id
+
+ target_object(target).backup
+ @backup_stats[target] = @records.object_id
+ end
+
# Flush all of the records relating to a specific target.
def self.flush_target(target)
+ backup_target(target)
+
records = target_records(target).reject { |r|
r[:ensure] == :absent
}
diff --git a/lib/puppet/util/filetype.rb b/lib/puppet/util/filetype.rb
index 137ef0c67..5d4ba1440 100755
--- a/lib/puppet/util/filetype.rb
+++ b/lib/puppet/util/filetype.rb
@@ -108,7 +108,6 @@ class Puppet::Util::FileType
# Overwrite the file.
def write(text)
- backup()
require "tempfile"
tf = Tempfile.new("puppet")
tf.print text; tf.flush