summaryrefslogtreecommitdiffstats
path: root/lib/puppet
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2008-12-15 00:22:09 -0600
committerJames Turnbull <james@lovedthanlost.net>2008-12-15 19:27:45 +1100
commitcf19bd8dea141a59cdff5a7f1edc56d3620ab0e2 (patch)
treed921ad9b313ed11efbf6d301af478e61efccd155 /lib/puppet
parentb966ea02a9deeb947bd6153c4cd7c53b1ddff3d8 (diff)
downloadpuppet-cf19bd8dea141a59cdff5a7f1edc56d3620ab0e2.tar.gz
puppet-cf19bd8dea141a59cdff5a7f1edc56d3620ab0e2.tar.xz
puppet-cf19bd8dea141a59cdff5a7f1edc56d3620ab0e2.zip
Not using a temporary file when locking files for writing.
The temporary file was not actually useful, because we could never really get atomic renames, for annoying, complicated reasons. This hopefully finally fixes #1812. Signed-off-by: Luke Kanies <luke@madstop.com>
Diffstat (limited to 'lib/puppet')
-rw-r--r--lib/puppet/util/file_locking.rb15
1 files changed, 6 insertions, 9 deletions
diff --git a/lib/puppet/util/file_locking.rb b/lib/puppet/util/file_locking.rb
index 80a0b2b0c..101ece308 100644
--- a/lib/puppet/util/file_locking.rb
+++ b/lib/puppet/util/file_locking.rb
@@ -21,6 +21,11 @@ module Puppet::Util::FileLocking
tmpfile = file + ".tmp"
unless mode
+ # It's far more likely that the file will be there than not, so it's
+ # better to stat once to check for existence and mode.
+ # If we can't stat, it's most likely because the file's not there,
+ # but could also be because the directory isn't readable, in which case
+ # we won't be able to write anyway.
begin
mode = File.stat(file).mode
rescue
@@ -31,15 +36,7 @@ module Puppet::Util::FileLocking
Puppet::Util.sync(file).synchronize(Sync::EX) do
File.open(file, "w", mode) do |rf|
rf.lock_exclusive do |lrf|
- File.open(tmpfile, "w", mode) do |tf|
- yield tf
- end
- begin
- File.rename(tmpfile, file)
- rescue => detail
- File.unlink(tmpfile) if File.exist?(tmpfile)
- raise Puppet::Error, "Could not rename %s to %s: %s; file %s was unchanged" % [file, tmpfile, Thread.current.object_id, detail, file]
- end
+ yield lrf
end
end
end