-
Notifications
You must be signed in to change notification settings - Fork 186
/
createrepomddeps
executable file
·156 lines (137 loc) · 4.84 KB
/
createrepomddeps
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#!/usr/bin/perl -w
################################################################
#
# Copyright (c) 1995-2014 SUSE Linux Products GmbH
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 or 3 as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program (see the file COPYING); if not, write to the
# Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
#
################################################################
BEGIN {
unshift @INC, ($::ENV{'BUILD_DIR'} || '/usr/lib/build');
}
use strict;
use Digest::MD5 ();
use File::Path ();
use Data::Dumper;
use Build ':rpm';
use Build::Rpm;
use Build::Rpmmd;
use Build::Options;
use Build::Download;
my $cachedir = "/var/cache/build";
my $options = {
'nosrc' => '',
'dump' => '',
'old' => '',
'zypp' => ':',
'cachedir' => ':',
};
sub printold {
my ($pkg, $baseurl, $old_seen) = @_;
my $evr = $pkg->{'version'}.'-'.$pkg->{'release'};
$evr = "$pkg->{'epoch'}:$evr" if $pkg->{'epoch'};
my $loc = $baseurl . $pkg->{'location'};
my $k = "$pkg->{'name'}.$pkg->{'arch'}";
if ($old_seen->{$k}) {
my $vv = Build::Rpm::verscmp($old_seen->{$k}->[0], $evr, 0);
if ($vv >= 0) {
print "$loc\n";
return;
}
print $old_seen->{$k}->[1]."\n";
}
$old_seen->{$k} = [ $evr, $loc ];
}
my ($opts, @args) = Build::Options::parse_options($options, @ARGV);
$cachedir = $opts->{'cachedir'} if $opts->{'cachedir'};
my $old_seen = {}; # for --old
my @packages; # for --dump
my $ua = Build::Download::create_ua();
for my $url (@args) {
my $dir;
my $baseurl = $url;
if ($opts->{'zypp'}) {
$dir = $opts->{'zypp'};
} elsif ($url =~ /^(?:ftps?|https?):\/\/([^\/]*)\/?/) {
my $repoid = Digest::MD5::md5_hex($url);
$dir = "$cachedir/$repoid/";
$baseurl .= '/' unless $baseurl =~ /\/$/;
File::Path::mkpath("${dir}repodata");
Build::Download::download("${baseurl}repodata/repomd.xml", "${dir}repodata/.repomd.xml.$$", "${dir}repodata/repomd.xml", 'ua' => $ua, 'retry' => 3);
} else {
$dir = $url;
}
$dir .= '/' unless $dir =~ /\/$/;
$baseurl .= '/' unless $baseurl =~ /\/$/;
if (! -s "${dir}repodata/repomd.xml") {
die("zypp repo $url is not up to date, please refresh first\n") if $opts->{'zypp'};
die("repo $url does not contain a repomd.xml file\n");
}
my @primaryfiles;
Build::Rpmmd::parse_repomd("${dir}repodata/repomd.xml", \@primaryfiles);
@primaryfiles = grep {$_->{'type'} eq 'primary' && defined($_->{'location'})} @primaryfiles;
for my $f (@primaryfiles) {
my $u = $f->{'location'};
if ($] > 5.007) {
require Encode;
utf8::downgrade($u);
}
$u =~ s/.*\///; # strip "repodata" part
my $cached;
if (-e "${dir}repodata/$u") {
$cached = 1;
$cached = 0 if exists($f->{'size'}) && $f->{'size'} != (-s _);
$cached = 0 if !$opts->{'zypp'} && !exists($f->{'size'}) && $u !~ /[0-9a-f]{32}-primary/;
}
if (!$cached) {
die("zypp repo $url is not up to date, please refresh first\n") if $opts->{'zypp'};
die("inconsistent repodata in $url\n") unless $url =~ /^(?:ftps?|https?):\/\/([^\/]*)\/?/;
Build::Download::download("${baseurl}repodata/$u", "${dir}repodata/.$u.$$", "${dir}repodata/$u", 'ua' => $ua, 'retry' => 3, 'digest' => $f->{'checksum'});
}
my $fh;
open($fh, '<', "${dir}repodata/$u") or die "Error opening ${dir}repodata/$u: $!\n";
if ($u =~ /\.gz$/) {
use IO::Uncompress::Gunzip qw($GunzipError);
$fh = new IO::Uncompress::Gunzip $fh or die "Error opening $u: $GunzipError\n";
}
if ($u =~ /\.zst$/) {
open ($fh, "-|", "zstd", "-dc", "$dir/repodata/$u");
}
my $parsefn;
if ($opts->{'dump'}) {
$parsefn = sub {
return if $opts->{'nosrc'} && ($_[0]->{'arch'} eq 'src' || $_[0]->{'arch'} eq 'nosrc');
$_[0]->{'baseurl'} = $baseurl;
push @packages, $_[0];
};
} elsif ($opts->{'old'}) {
$parsefn = sub {
return if $opts->{'nosrc'} && ($_[0]->{'arch'} eq 'src' || $_[0]->{'arch'} eq 'nosrc');
printold($_[0], $baseurl, $old_seen);
};
} else {
$parsefn = sub {
return if $opts->{'nosrc'} && ($_[0]->{'arch'} eq 'src' || $_[0]->{'arch'} eq 'nosrc');
binmode STDOUT, ":utf8";
Build::writedeps(\*STDOUT, $_[0], $baseurl)
};
}
Build::Rpmmd::parse($fh, $parsefn, 'addselfprovides' => 1);
close($fh);
}
}
if ($opts->{'dump'}) {
print Data::Dumper->Dump([\@packages], ['packages']); # caution: excessive memory consumption!
}