diff options
author | Chris Doherty <cdoherty@chef.io> | 2015-12-09 14:00:01 -0800 |
---|---|---|
committer | Chris Doherty <cdoherty@chef.io> | 2015-12-09 14:00:01 -0800 |
commit | a308dabedc060085239a2bb616bee250db7d2688 (patch) | |
tree | bba770e86da039f149afb5e0db36e3dfc5d0b9ee | |
parent | 45bebe485e22c05a6d4bda4d5a1289d2082cef5a (diff) | |
download | chef-zero-a308dabedc060085239a2bb616bee250db7d2688.tar.gz |
Delete files from /file_store when their artifact gets deleted.
-rw-r--r-- | lib/chef_zero/endpoints/cookbook_artifacts_cookbook_identifier.rb | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/lib/chef_zero/endpoints/cookbook_artifacts_cookbook_identifier.rb b/lib/chef_zero/endpoints/cookbook_artifacts_cookbook_identifier.rb index 01c481d..a1c5569 100644 --- a/lib/chef_zero/endpoints/cookbook_artifacts_cookbook_identifier.rb +++ b/lib/chef_zero/endpoints/cookbook_artifacts_cookbook_identifier.rb @@ -26,7 +26,7 @@ module ChefZero # # XXX rewrite to use /file_store URIs identified_cookbook_data["recipes"].each do |r| - r["url"] ||= build_uri(request.base_uri, request.rest_path + ["recipes", r["name"]]) + r["url"] ||= build_uri(request.base_uri, make_file_store_path(request.rest_path, r)) end identified_cookbook_json = to_json(identified_cookbook_data) @@ -36,12 +36,23 @@ module ChefZero return already_json_response(201, identified_cookbook_json) end + def make_file_store_path(rest_path, recipe) + rest_path.first(2) + ["file_store", "checksums", recipe["checksum"]] + end + # DELETE /organizations/ORG/cookbook_artifacts/COOKBOOK/IDENTIFIER def delete(request) begin identified_cookbook_json = get_data(request) delete_data(request) + # go through the recipes and delete stuff in the file store. + identified_cookbook_data = parse_json(identified_cookbook_json) + identified_cookbook_data["recipes"].each do |r| + file_path = make_file_store_path(request.rest_path, r) + delete_data(request, file_path) + end + # if this was the last revision, delete the directory so future requests will 404. artifact_path = request.rest_path[0..-2] if list_data(request, artifact_path).size == 0 |