Skip to content

Commit

Permalink
cleanup createrepomddeps a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
mlschroe committed Dec 1, 2014
1 parent 52b6b04 commit f2c8f58
Showing 1 changed file with 26 additions and 38 deletions.
64 changes: 26 additions & 38 deletions createrepomddeps
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,9 @@ use Data::Dumper;
use Getopt::Long;
use Build::Rpm;
use Build::Rpmmd;
use Digest::MD5 qw(md5 md5_hex md5_base64);
use Digest::MD5 ();
use File::Path qw(mkpath rmtree);
use File::Basename;
use LWP::UserAgent;
use URI;

Getopt::Long::Configure("no_ignore_case");

Expand Down Expand Up @@ -85,62 +83,52 @@ sub package_parsed {
}
}

sub printasbuildcachefile(@) {
}

sub getmetadata {
my ($url, $dir) = @_;
my $dest = "${dir}repodata";
mkpath($dest);
system($INC[0].'/download', $dest, "${url}repodata/repomd.xml");
}

### main

GetOptions (
"nosrc" => \$opt_nosrc,
"dump" => \$opt_dump,
"old" => \$opt_old,
"zypp=s" => \$opt_zypp,
"cachedir=s" => \$cachedir,
) or exit(1);
"nosrc" => \$opt_nosrc,
"dump" => \$opt_dump,
"old" => \$opt_old,
"zypp=s" => \$opt_zypp,
"cachedir=s" => \$cachedir,
) or exit(1);

$opt_bc = 1 unless $opt_dump || $opt_old;

#my $url = '/mounts/mirror/SuSE/ftp.suse.com/pub/suse/update/10.1/';

for my $url (@ARGV) {
my $dir;
if ($opt_zypp) {
$dir = $opt_zypp;
$dir .= '/' unless $dir =~ /\/$/;
$baseurl = $url;
$baseurl .= '/' unless $baseurl =~ /\/$/;
} elsif ($url =~ /^(?:ftps?|https?):\/\/([^\/]*)\/?/) {
my $repoid = md5_hex($url);
my $repoid = Digest::MD5::md5_hex($url);
$dir = "$cachedir/$repoid/";
$baseurl = $url;
$baseurl .= '/' unless $baseurl =~ /\/$/;
getmetadata($baseurl, $dir);
mkpath("${dir}repodata");
system($INC[0].'/download', "${dir}repodata", "${baseurl}repodata/repomd.xml");
} else {
$dir = $url;
$dir .= '/' unless $dir =~ /\/$/;
$baseurl = $dir;
}

die("zypp repo $url is not up to date, please refresh first\n") unless -s "${dir}repodata/repomd.xml";
if (! -s "${dir}repodata/repomd.xml") {
die("zypp repo $url is not up to date, please refresh first\n") if $opt_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;

# print Dumper(\@primaryfiles);

for my $f (@primaryfiles) {
my $u = "$dir$f->{'location'}";
if ($] > 5.007) {
require Encode;
utf8::downgrade($u);
require Encode;
utf8::downgrade($u);
}
my $cached;
if (-e $u) {
Expand All @@ -149,27 +137,27 @@ for my $url (@ARGV) {
$cached = 0 if !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 $opt_zypp;
if ($url =~ /^(?:ftps?|https?):\/\/([^\/]*)\/?/) {
if (system($INC[0].'/download', $dir . "repodata/", $baseurl . "repodata/" . basename($u))) {
die("download failed\n");
}
} else {
die("inconsistent repodata in $url\n");
die("zypp repo $url is not up to date, please refresh first\n") if $opt_zypp;
if ($url =~ /^(?:ftps?|https?):\/\/([^\/]*)\/?/) {
if (system("$INC[0]/download", "${dir}repodata/", "${baseurl}repodata/" . basename($u))) {
die("download failed\n");
}
} else {
die("inconsistent repodata in $url\n");
}
}
my $fh;
open($fh, '<', $u) or die "Error opening $u: $!\n";
if ($u =~ /\.gz$/) {
use IO::Uncompress::Gunzip qw($GunzipError);
$fh = new IO::Uncompress::Gunzip $fh or die "Error opening $u: $GunzipError\n";
use IO::Uncompress::Gunzip qw($GunzipError);
$fh = new IO::Uncompress::Gunzip $fh or die "Error opening $u: $GunzipError\n";
}
Build::Rpmmd::parse_primary($fh, \&package_parsed);
close($fh);
}
}

if ($opt_dump) {
print Data::Dumper->Dump([\@packages], ['packages']); # caution: excessive memory consumption!
print Data::Dumper->Dump([\@packages], ['packages']); # caution: excessive memory consumption!
}

0 comments on commit f2c8f58

Please sign in to comment.