From 9a537f2e09ad20abc8c954e7db5deec3bc3f05b4 Mon Sep 17 00:00:00 2001 From: Sara Meisburger Date: Mon, 12 Aug 2019 10:01:20 -0700 Subject: [PATCH 1/2] (RE-12499) add function to purge tarballs from artifactory if a compose fails --- lib/packaging/artifactory.rb | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/lib/packaging/artifactory.rb b/lib/packaging/artifactory.rb index 51852df5a..3301bfe07 100644 --- a/lib/packaging/artifactory.rb +++ b/lib/packaging/artifactory.rb @@ -359,6 +359,31 @@ def ship_pe_tarballs(tarball_path, target_repo, ship_paths) end end + # Remove shipped PE tarballs from artifactory + # Used when compose fails, we only want the tarball shipped to artifactory if all platforms succeed + # Identify which packages were created and shipped based on md5sum and remove them + # @param tarball_path [String] the local path to the tarballs that were shipped + # @param pe_repo [String] the artifactory repo the tarballs were shipped to + def purge_copied_pe_tarballs(tarball_path, pe_repo) + check_authorization + Dir.foreach("#{tarball_path}/") do |pe_tarball| + unless pe_tarball == '.' || pe_tarball == ".." + md5 = Digest::MD5.file("#{tarball_path}/#{pe_tarball}").hexdigest + artifacts_to_delete = Artifactory::Resource::Artifact.checksum_search(md5: md5, repos: pe_repo) + unless artifacts_to_delete.nil? + begin + artifacts_to_delete.each do |artifact| + puts "removing...#{pe_tarball} from #{pe_repo}" + artifact.delete + end + rescue Artifactory::Error::HTTPError + STDERR.puts "Error: cannot remove #{pe_tarball}, do you have the right permissions?" + end + end + end + end + end + private :check_authorization end end From 4715e48e41fbce3e1b6f8d61acb30db9a1632acf Mon Sep 17 00:00:00 2001 From: Sara Meisburger Date: Tue, 13 Aug 2019 13:23:39 -0700 Subject: [PATCH 2/2] (maint) rewrite purge_copied_pe_tarballs with `next` --- lib/packaging/artifactory.rb | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/lib/packaging/artifactory.rb b/lib/packaging/artifactory.rb index 3301bfe07..691a2ef92 100644 --- a/lib/packaging/artifactory.rb +++ b/lib/packaging/artifactory.rb @@ -367,19 +367,17 @@ def ship_pe_tarballs(tarball_path, target_repo, ship_paths) def purge_copied_pe_tarballs(tarball_path, pe_repo) check_authorization Dir.foreach("#{tarball_path}/") do |pe_tarball| - unless pe_tarball == '.' || pe_tarball == ".." - md5 = Digest::MD5.file("#{tarball_path}/#{pe_tarball}").hexdigest - artifacts_to_delete = Artifactory::Resource::Artifact.checksum_search(md5: md5, repos: pe_repo) - unless artifacts_to_delete.nil? - begin - artifacts_to_delete.each do |artifact| - puts "removing...#{pe_tarball} from #{pe_repo}" - artifact.delete - end - rescue Artifactory::Error::HTTPError - STDERR.puts "Error: cannot remove #{pe_tarball}, do you have the right permissions?" - end + next if pe_tarball == '.' || pe_tarball == ".." + md5 = Digest::MD5.file("#{tarball_path}/#{pe_tarball}").hexdigest + artifacts_to_delete = Artifactory::Resource::Artifact.checksum_search(md5: md5, repos: pe_repo) + next if artifacts_to_delete.nil? + begin + artifacts_to_delete.each do |artifact| + puts "Removing #{pe_tarball} from #{pe_repo}... " + artifact.delete end + rescue Artifactory::Error::HTTPError + STDERR.puts "Error: cannot remove #{pe_tarball}, do you have the right permissions?" end end end