From: yang.zhang Date: Mon, 16 May 2016 02:50:56 +0000 (+0800) Subject: add lock protection for download repodata using multi-threads X-Git-Tag: upstream/20160629~11^2~6 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=4f06d8f6ff862f9ef9ca37dab368fa243a183beb;p=tools%2Fbuild.git add lock protection for download repodata using multi-threads Change-Id: Ica860fe3d7375ee496f25c4ff5b4b118500173ba --- 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$/) {