summaryrefslogtreecommitdiffstats
path: root/lib/puppet/util.rb
diff options
context:
space:
mode:
authorluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2006-01-24 06:01:58 +0000
committerluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2006-01-24 06:01:58 +0000
commitae2575b45de1e8f4c0ec956cebe0eed2bafbcf57 (patch)
tree9c2b7c839087c285c228374f525315e55c392a34 /lib/puppet/util.rb
parent18e8e74a2e3b4c5d092fc0aae38bbc5455d4db48 (diff)
downloadpuppet-ae2575b45de1e8f4c0ec956cebe0eed2bafbcf57.tar.gz
puppet-ae2575b45de1e8f4c0ec956cebe0eed2bafbcf57.tar.xz
puppet-ae2575b45de1e8f4c0ec956cebe0eed2bafbcf57.zip
Adding the event-loop stuff to the repository and switching to using it. Also, breaking many classes out into their own class files.
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@848 980ebf18-57e1-0310-9a29-db15c13687c0
Diffstat (limited to 'lib/puppet/util.rb')
-rw-r--r--lib/puppet/util.rb18
1 files changed, 17 insertions, 1 deletions
diff --git a/lib/puppet/util.rb b/lib/puppet/util.rb
index 650eb484a..9974d55e3 100644
--- a/lib/puppet/util.rb
+++ b/lib/puppet/util.rb
@@ -89,13 +89,29 @@ module Util
def self.lock(*opts)
lock = opts[0] + ".lock"
while File.exists?(lock)
+ stamp = File.stat(lock).mtime.to_i
+ if Time.now.to_i - stamp > 5
+ Puppet.notice "Lock file %s is %s seconds old; removing"
+ File.delete(lock)
+ end
#Puppet.debug "%s is locked" % opts[0]
sleep 0.1
end
File.open(lock, "w") { |f| f.print " "; f.flush }
+ writing = false
+ if opts[1] == "w"
+ writing = true
+ tmp = opts[0] + ".tmp"
+ orig = opts[0]
+ opts[0] = tmp
+ end
begin
File.open(*opts) { |file| yield file }
- rescue
+ if writing
+ File.rename(tmp, orig)
+ end
+ rescue => detail
+ Puppet.err "Storage error: %s" % detail
raise
ensure
# I don't really understand how the lock file could disappear,