From 28d4f278b9a4767ac7fcb0c062c975a6ad98b40f Mon Sep 17 00:00:00 2001 From: Vokhmin Alexey V Date: Thu, 14 Feb 2013 17:53:26 +0400 Subject: [PATCH] #907: add action for removing archive after destroy tag --- app/models/project.rb | 3 +-- app/models/project_tag.rb | 8 ++++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/app/models/project.rb b/app/models/project.rb index d9b476b8e..2be394c49 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -216,9 +216,8 @@ class Project < ActiveRecord::Base system "curl --user #{token}: -POST -F 'file_store[file]=@#{archive[:path]};filename=#{name}-#{tag.name}.#{tag_file_format(format)}' #{APP_CONFIG['file_store_url']}/api/v1/upload" end if project_tag - old_sha1 = project_tag.sha1 + project_tag.remove_archive_from_file_store(project_tag.sha1) project_tag.update_attributes(:sha1 => sha1) - system "curl --user #{token}: -X DELETE #{APP_CONFIG['file_store_url']}/api/v1/file_stores/#{old_sha1}.json" else project_tags.create( :tag_name => tag.name, diff --git a/app/models/project_tag.rb b/app/models/project_tag.rb index eeb8f1656..bfd6d47f2 100644 --- a/app/models/project_tag.rb +++ b/app/models/project_tag.rb @@ -16,4 +16,12 @@ class ProjectTag < ActiveRecord::Base :tag_name, :format_id + after_destroy :remove_archive_from_file_store + + def remove_archive_from_file_store(sha = sha1) + token = User.find_by_uname('rosa_system').authentication_token + system "curl --user #{token}: -X DELETE #{APP_CONFIG['file_store_url']}/api/v1/file_stores/#{sha}.json" + end + later :remove_archive_from_file_store, :queue => :clone_build + end