From 4f06d8f6ff862f9ef9ca37dab368fa243a183beb Mon Sep 17 00:00:00 2001 From: "yang.zhang" Date: Mon, 16 May 2016 10:50:56 +0800 Subject: [PATCH] add lock protection for download repodata using multi-threads Change-Id: Ica860fe3d7375ee496f25c4ff5b4b118500173ba --- createrepomddeps | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/createrepomddeps b/createrepomddeps index 6f96434..1fe6ea3 100755 --- a/createrepomddeps +++ b/createrepomddeps @@ -87,7 +87,16 @@ for my $url (@ARGV) { $dir = "$cachedir/$repoid/"; $baseurl .= '/' unless $baseurl =~ /\/$/; mkpath("${dir}repodata"); - system($INC[0].'/download', "${dir}repodata", "${baseurl}repodata/repomd.xml"); + my $lock_file = $dir . 'repodata/down_repomd.lock'; + open(my $lfh, '>>', $lock_file) or die "Could not open '$lock_file' - $!"; + flock($lfh, LOCK_EX); + if (!-f $dest . '/repomd.xml') { + if (system($INC[0].'/download', $dest, $url . "repodata/repomd.xml")) { + close($lfh) or die "Could not write '$lock_file' - $!"; + die("get metadata failed\n"); + } + } + close($lfh) or die "Could not write '$lock_file' - $!"; } else { $dir = $url; } @@ -111,6 +120,9 @@ for my $url (@ARGV) { utf8::downgrade($u); } my $cached; + my $lock_file = $dir . "repodata/down_primary.lock"; + open(my $lfh, '>>', $lock_file) or die "Could not open '$lock_file' - $!"; + flock($lfh, LOCK_EX); if (-e $u) { $cached = 1; $cached = 0 if exists($f->{'size'}) && $f->{'size'} != (-s _); @@ -126,6 +138,8 @@ for my $url (@ARGV) { die("inconsistent repodata in $url\n"); } } + close($lfh) or die "Could not write '$lock_file' - $!"; + my $fh; open($fh, '<', $u) or die "Error opening $u: $!\n"; if ($u =~ /\.gz$/) { -- 2.7.4