summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2008-12-10 23:29:39 -0600
committerJames Turnbull <james@lovedthanlost.net>2008-12-12 09:44:42 +1100
commit45144a1b9da2839fd9f8a182a8f82ecb06e17292 (patch)
tree545483efecf2ac4bfaf9e9a984ca651867043edc /lib
parent2385a78a7c455affed26955142a4d4d3ce53c37f (diff)
downloadpuppet-45144a1b9da2839fd9f8a182a8f82ecb06e17292.tar.gz
puppet-45144a1b9da2839fd9f8a182a8f82ecb06e17292.tar.xz
puppet-45144a1b9da2839fd9f8a182a8f82ecb06e17292.zip
Fixing #1812 (hopefully) - adding read and write locks to yaml.
It's obviously not really possible to test that this fixes it, but I'm confident that the locks work, and now we're using them, so it *should*. Signed-off-by: Luke Kanies <luke@madstop.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/puppet/indirector/yaml.rb15
1 files changed, 12 insertions, 3 deletions
diff --git a/lib/puppet/indirector/yaml.rb b/lib/puppet/indirector/yaml.rb
index 3f05ce618..5b53a7628 100644
--- a/lib/puppet/indirector/yaml.rb
+++ b/lib/puppet/indirector/yaml.rb
@@ -1,17 +1,26 @@
require 'puppet/indirector/terminus'
+require 'puppet/util/file_locking'
# The base class for YAML indirection termini.
class Puppet::Indirector::Yaml < Puppet::Indirector::Terminus
+ include Puppet::Util::FileLocking
+
# Read a given name's file in and convert it from YAML.
def find(request)
file = path(request.key)
return nil unless FileTest.exist?(file)
+ yaml = nil
begin
- return from_yaml(File.read(file))
+ readlock(file) { |fh| yaml = fh.read }
rescue => detail
raise Puppet::Error, "Could not read YAML data for %s %s: %s" % [indirection.name, request.key, detail]
end
+ begin
+ return from_yaml(yaml)
+ rescue => detail
+ raise Puppet::Error, "Could not parse YAML data for %s %s: %s" % [indirection.name, request.key, detail]
+ end
end
# Convert our object to YAML and store it to the disk.
@@ -28,7 +37,7 @@ class Puppet::Indirector::Yaml < Puppet::Indirector::Terminus
end
begin
- File.open(file, "w", 0660) { |f| f.print to_yaml(request.instance) }
+ writelock(file, 0660) { |f| f.print to_yaml(request.instance) }
rescue TypeError => detail
Puppet.err "Could not save %s %s: %s" % [self.name, request.key, detail]
end
@@ -36,7 +45,7 @@ class Puppet::Indirector::Yaml < Puppet::Indirector::Terminus
# Get the yaml directory
def base
- (Puppet[:name] == "puppetmasterd") ? Puppet[:yamldir] : Puppet[:clientyamldir]
+ (Puppet[:name] == "puppetmasterd") ? Puppet[:yamldir] : Puppet[:clientyamldir]
end
# Return the path to a given node's file.