summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2008-03-16 17:37:12 -0500
committerLuke Kanies <luke@madstop.com>2008-03-16 17:37:12 -0500
commitf3a304c557c096b5dbf319671cb84e5611eee30f (patch)
treeb6cf562bdd6ff369922f3498fc216a21e1d655c0
parent80f69ce86d245b45aeb93964aed9b3daca7d0d80 (diff)
Modifying the yaml terminus base class to use the timestamp
of the yaml file as the version of the object.
-rw-r--r--lib/puppet/indirector/yaml.rb5
-rwxr-xr-xspec/unit/indirector/yaml.rb12
2 files changed, 16 insertions, 1 deletions
diff --git a/lib/puppet/indirector/yaml.rb b/lib/puppet/indirector/yaml.rb
index 16816d941..4baeb38db 100644
--- a/lib/puppet/indirector/yaml.rb
+++ b/lib/puppet/indirector/yaml.rb
@@ -40,6 +40,11 @@ class Puppet::Indirector::Yaml < Puppet::Indirector::Terminus
end
end
+ def version(name)
+ return nil unless FileTest.exist?(path(name))
+ return File.stat(path(name)).mtime
+ end
+
private
def from_yaml(text)
diff --git a/spec/unit/indirector/yaml.rb b/spec/unit/indirector/yaml.rb
index 2e0b453d7..b61332485 100755
--- a/spec/unit/indirector/yaml.rb
+++ b/spec/unit/indirector/yaml.rb
@@ -24,6 +24,16 @@ describe Puppet::Indirector::Yaml, " when choosing file location" do
Puppet.settings.stubs(:value).with(:yamldir).returns(@dir)
end
+ it "should use the mtime of the written file as the version" do
+ stat = mock 'stat'
+ FileTest.stubs(:exist?).returns true
+ File.expects(:stat).returns stat
+ time = Time.now
+ stat.expects(:mtime).returns time
+
+ @store.version(:me).should equal(time)
+ end
+
describe Puppet::Indirector::Yaml, " when choosing file location" do
it "should store all files in a single file root set in the Puppet defaults" do
@@ -98,4 +108,4 @@ describe Puppet::Indirector::Yaml, " when choosing file location" do
proc { @store.find(@subject.name) }.should raise_error(Puppet::Error)
end
end
-end \ No newline at end of file
+end