aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPascal Terjan <pterjan@mageia.org>2022-09-25 17:00:12 +0000
committerPascal Terjan <pterjan@mageia.org>2022-09-25 17:00:12 +0000
commit8bb79d1c33f40eb3e54a81655a2a296b2cd2d696 (patch)
tree54e72bdb66f208f9421a0f93b655efc283204369
parentd55d80136c3078919f64aec749bc32913e9d84ad (diff)
downloadpuppet-8bb79d1c33f40eb3e54a81655a2a296b2cd2d696.tar
puppet-8bb79d1c33f40eb3e54a81655a2a296b2cd2d696.tar.gz
puppet-8bb79d1c33f40eb3e54a81655a2a296b2cd2d696.tar.bz2
puppet-8bb79d1c33f40eb3e54a81655a2a296b2cd2d696.tar.xz
puppet-8bb79d1c33f40eb3e54a81655a2a296b2cd2d696.zip
Add an option to use upload lock
-rwxr-xr-xmodules/buildsystem/templates/cleaner.rb37
1 files 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?