summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2006-07-21 20:11:13 +0000
committerluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2006-07-21 20:11:13 +0000
commit310b3a11eec563c4687041f9ae1a0b894571bc05 (patch)
treeebaf6941383ae7c2616f59258c0e95c83eb21044 /lib
parentc8537a51c61290c9ba32d57fed31b389dbbdeb29 (diff)
downloadpuppet-310b3a11eec563c4687041f9ae1a0b894571bc05.tar.gz
puppet-310b3a11eec563c4687041f9ae1a0b894571bc05.tar.xz
puppet-310b3a11eec563c4687041f9ae1a0b894571bc05.zip
Adding timeout functionality to the ParsedFile class, in preparation to adding config reloading to the Config class.
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@1419 980ebf18-57e1-0310-9a29-db15c13687c0
Diffstat (limited to 'lib')
-rw-r--r--lib/puppet/config.rb11
-rwxr-xr-xlib/puppet/parsedfile.rb44
2 files changed, 38 insertions, 17 deletions
diff --git a/lib/puppet/config.rb b/lib/puppet/config.rb
index 701ee5942..f70201cee 100644
--- a/lib/puppet/config.rb
+++ b/lib/puppet/config.rb
@@ -92,9 +92,11 @@ class Config
end
# Remove all set values.
- def clear
+ def clear(exceptcli = false)
@config.each { |name, obj|
- obj.clear
+ unless exceptcli and obj.setbycli
+ obj.clear
+ end
}
@used = []
end
@@ -216,7 +218,6 @@ class Config
# Parse a configuration file.
def parse(file)
text = nil
- @file = file
begin
text = File.read(file)
@@ -468,8 +469,8 @@ Generated on #{Time.now}.
}
topbucket = Puppet::TransBucket.new
- if defined? @file and @file
- topbucket.name = @file
+ if defined? @file.file and @file.file
+ topbucket.name = @file.file
else
topbucket.name = "configtop"
end
diff --git a/lib/puppet/parsedfile.rb b/lib/puppet/parsedfile.rb
index e32a2daef..c5168b2b1 100755
--- a/lib/puppet/parsedfile.rb
+++ b/lib/puppet/parsedfile.rb
@@ -4,35 +4,55 @@
require 'puppet'
module Puppet
+ class NoSuchFile < Puppet::Error; end
class ParsedFile
attr_reader :file
+ Puppet.config.setdefaults(:puppet,
+ :filetimeout => [ 15,
+ "The minimum time to wait between checking for updates in
+ configuration files."
+ ]
+ )
+
# Determine whether the file has changed and thus whether it should
# be reparsed
def changed?
- tmp = self.stamp
- retval = false
- if tmp != @stamp
- retval = true
- @stamp = tmp
- end
- @statted = Time.now
+ # Don't actually stat the file more often than filetimeout.
+ if Time.now - @statted > Puppet[:filetimeout]
+ tmp = stamp()
- return retval
+ if tmp == @tstamp
+ return false
+ else
+ @tstamp = tmp
+ return true
+ end
+ else
+ return false
+ end
end
# Create the file. Must be passed the file path.
def initialize(file)
@file = file
unless FileTest.exists?(@file)
- raise Puppet::DevError, "Can not use a non-existent file for parsing"
+ raise Puppet::NoSuchFile, "Can not use a non-existent file for parsing"
end
- @stamp = self.stamp
- @statted = Time.now
+ @tstamp = stamp()
end
+ private
+
+ # Provide a hook for setting the timestamp during testing, so we don't
+ # have to depend on the granularity of the filesystem.
+ attr_writer :tstamp
+
def stamp
- File.stat(@file).ctime
+ @statted = Time.now
+ return File.stat(@file).ctime
end
end
end
+
+# $Id$