From 8bb79d1c33f40eb3e54a81655a2a296b2cd2d696 Mon Sep 17 00:00:00 2001 From: Pascal Terjan Date: Sun, 25 Sep 2022 17:00:12 +0000 Subject: Add an option to use upload lock --- modules/buildsystem/templates/cleaner.rb | 37 +++++++++++++++++++++++++++++--- 1 file changed, 34 insertions(+), 3 deletions(-) diff --git a/modules/buildsystem/templates/cleaner.rb b/modules/buildsystem/templates/cleaner.rb index da13a8e8..40473170 100755 --- a/modules/buildsystem/templates/cleaner.rb +++ b/modules/buildsystem/templates/cleaner.rb @@ -25,7 +25,8 @@ def process [ '--base', '-p', GetoptLong::REQUIRED_ARGUMENT ], [ '--media', '-m', GetoptLong::REQUIRED_ARGUMENT ], [ '--destination', '-d', GetoptLong::REQUIRED_ARGUMENT ], - [ '--version', '-v', GetoptLong::REQUIRED_ARGUMENT ] + [ '--version', '-v', GetoptLong::REQUIRED_ARGUMENT ], + [ '--lockfile', '-l', GetoptLong::REQUIRED_ARGUMENT ], ) base_path = "<%= scope.lookupvar('buildsystem::var::repository::bootstrap_root') %>/distrib" @@ -34,6 +35,7 @@ def process old_path = "<%= scope.lookupvar('buildsystem::var::youri::packages_archivedir') %>" version = "cauldron" auto = false + lockfile = nil opts.each do |opt, arg| case opt @@ -52,9 +54,13 @@ def process base_path = arg when '--version' version = arg + when '--lockfile' + lockfile = arg end end + take_upload_lock(lockfile) if lockfile + medias.each{|media| src_path = "#{base_path}/#{version}/SRPMS/#{media}" @@ -64,7 +70,6 @@ def process $noarch = {} # Get a list of all src.rpm and their build time - `urpmf --synthesis "#{src_path}/media_info/synthesis.hdlist.cz" --qf '%filename:%buildtime:buildarchs' "."`.each_line{|l| l2 = l.split(':') filename = l2[0] @@ -75,7 +80,6 @@ def process $srcs[filename] = true $noarch[name] = true if buildarch == 'noarch' } - # TODO: Take an upload lock to avoid being confused by emi moving things archs.each{|arch| bin_path = "#{base_path}/#{version}/#{arch}/media/#{media}" debug_path = bin_path.sub("/media/", "/media/debug/") @@ -90,6 +94,33 @@ def process } end +def take_upload_lock(path) + start_time = Time.new + has_lock = false + at_exit { + if File.exists?(path) + if File.readlines(path)[0].to_i == Process.pid + File.delete(path) + end + end + } + until has_lock + while File.exists?(path) + puts "Upload in progress..." + if Time.new - start_time > 2*3600.0 + puts "Could not aquire upload lock for more than 2h, giving up" + end + sleep(5) + end + puts "Taking upload lock" + File.write(path, Process.pid) + if File.readlines(path)[0].to_i == Process.pid + puts "Succesfuly took upload lock" + has_lock = true + end + end +end + def move_packages(src, dst, list, auto) list.reject!{|f| !File.exist?(src + "/" + f)} return if list.empty? -- cgit v1.2.1