summaryrefslogtreecommitdiffstats
path: root/lib/puppet
diff options
context:
space:
mode:
authorluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2005-09-21 21:14:12 +0000
committerluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2005-09-21 21:14:12 +0000
commit03f57330ef06d6afd6b5f011f1764c4420f7d3dd (patch)
treee915c74c5cca2887fd8f7e896f96fd01d5f1881b /lib/puppet
parentf7575561b52ad89b97bbf97b5487144339031099 (diff)
downloadpuppet-03f57330ef06d6afd6b5f011f1764c4420f7d3dd.tar.gz
puppet-03f57330ef06d6afd6b5f011f1764c4420f7d3dd.tar.xz
puppet-03f57330ef06d6afd6b5f011f1764c4420f7d3dd.zip
adding a ParsedFile class to handle figuring out whether a file has changed
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@696 980ebf18-57e1-0310-9a29-db15c13687c0
Diffstat (limited to 'lib/puppet')
-rwxr-xr-xlib/puppet/parsedfile.rb36
1 files changed, 36 insertions, 0 deletions
diff --git a/lib/puppet/parsedfile.rb b/lib/puppet/parsedfile.rb
new file mode 100755
index 000000000..337932309
--- /dev/null
+++ b/lib/puppet/parsedfile.rb
@@ -0,0 +1,36 @@
+# A simple class that tells us when a file has changed and thus whether we
+# should reload it
+
+require 'puppet'
+
+module Puppet
+ class ParsedFile
+ # 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
+
+ return retval
+ 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"
+ end
+ @stamp = self.stamp
+ @statted = Time.now
+ end
+
+ def stamp
+ File.stat(@file).ctime
+ end
+ end
+end