Skip to content

Commit 9af6955

Browse files
timcharperdanielsdeleo
authored andcommitted
revision provider for deploy resource learns to reconstruct deploy history from F.S.
If the cache file gets wiped out that contains this information, chef would try to redeploy a revision that has already been deployed, causing things to fail. This need not be, since we can regenerate this list by looking at the deployed folders on the filesystem and order them by ctime. resolves CHEF-1107
1 parent 1392dd3 commit 9af6955

2 files changed

Lines changed: 14 additions & 1 deletion

File tree

‎chef/lib/chef/provider/deploy/revision.rb‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,15 @@ def sorted_releases
5050
cache
5151
end
5252

53+
def sorted_releases_from_filesystem
54+
Dir.glob(new_resource.deploy_to + "/releases/*").sort_by { |d| ::File.ctime(d) }
55+
end
56+
5357
def load_cache
5458
begin
5559
JSON.parse(Chef::FileCache.load("revision-deploys/#{new_resource.name}"))
5660
rescue Chef::Exceptions::FileNotFound
57-
save_cache([])
61+
sorted_releases_from_filesystem
5862
end
5963
end
6064

‎chef/spec/unit/provider/deploy/revision_spec.rb‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,4 +87,13 @@
8787
@provider.all_releases.should == %w{second third fourth fifth latest}
8888
end
8989

90+
it "regenerates the file cache if it's not available" do
91+
oldest = "/my/deploy/dir/releases/oldest"
92+
latest = "/my/deploy/dir/releases/latest"
93+
Dir.should_receive(:glob).with("/my/deploy/dir/releases/*").and_return([latest, oldest])
94+
::File.should_receive(:ctime).with(oldest).and_return(Time.now - 10)
95+
::File.should_receive(:ctime).with(latest).and_return(Time.now - 1)
96+
@provider.all_releases.should == [oldest, latest]
97+
end
98+
9099
end

0 commit comments

Comments
 (0)