use POSIX;
use Fcntl;
use Config::IniFiles;
-use File::FnMatch;
use Data::Dumper;
use solv;
use Devel::Peek;
use FileHandle;
+use File::Temp ();
use strict;
package Repo::generic;
sub new {
- my ($class, $attr) = @_;
- my $r = { %$attr };
+ my ($class, $alias, $type, $attr) = @_;
+ my $r = { %{$attr || {}} };
+ $r->{'alias'} = $alias;
+ $r->{'type'} = $type;
return bless $r, $class;
}
+sub calc_cookie_fp {
+ my ($self, $fp) = @_;
+ my $chksum = solv::Chksum->new($solv::REPOKEY_TYPE_SHA256);
+ $chksum->add_fp($fp);
+ return $chksum->raw();
+}
+
+sub calc_cookie_file {
+ my ($self, $filename) = @_;
+ my $chksum = solv::Chksum->new($solv::REPOKEY_TYPE_SHA256);
+ $chksum->add("1.1");
+ $chksum->add_stat($filename);
+ return $chksum->raw();
+}
+
sub cachepath {
my ($self, $ext) = @_;
my $path = $self->{'alias'};
$self->{'handle'} = $pool->add_repo($self->{'alias'});
$self->{'handle'}->{'appdata'} = $self;
$self->{'handle'}->{'priority'} = 99 - $self->{'priority'};
+ my $dorefresh = $self->{'autorefresh'};
+ if ($dorefresh) {
+ my @s = stat($self->cachepath());
+ $dorefresh = 0 if @s && time() - $s[9] < $self->{'metadata_expire'};
+ }
$self->{'cookie'} = '';
- $self->usecachedrepo();
+ if (!$dorefresh && $self->usecachedrepo()) {
+ print "repo: '$self->{'alias'}' cached\n";
+ return 1;
+ }
+ return $self->load_if_changed();
+}
+
+sub load_if_changed {
+ return 0;
+}
+
+sub load_ext {
+ return 0;
}
sub download {
if ($chksum) {
my $fchksum = solv::Chksum->new($chksum->{'type'});
$fchksum->add_fd(fileno($f));
- if (!$fchksum->matches($chksum)) {
+ if ($fchksum != $chksum) {
print "$file: checksum error\n";
$self->{'incomplete'} = 1 if $markincomplete;
return undef;
}
}
if ($uncompress) {
- return solv::xfopen_fd($file, POSIX::dup(fileno($f)));
+ return solv::xfopen_dup($file, fileno($f));
} else {
- return solv::xfopen_fd('', POSIX::dup(fileno($f)));
+ return solv::xfopen_dup(undef, fileno($f));
}
}
my ($self, $ext, $mark) = @_;
my $cookie = $ext ? $self->{'extcookie'} : $self->{'cookie'};
my $handle = $self->{'handle'};
- my $cachepath = $self->cachepath();
+ my $cachepath = $self->cachepath($ext);
+ my $fextcookie;
if (sysopen(my $f, $cachepath, POSIX::O_RDONLY)) {
- $f = solv::xfopen_fd('', POSIX::dup(fileno($f)));
+ sysseek($f, -32, Fcntl::SEEK_END);
+ my $fcookie = '';
+ return undef if sysread($f, $fcookie, 32) != 32;
+ return undef if $cookie && $fcookie ne $cookie;
+ if ($self->{'type'} ne 'system' && !$ext) {
+ sysseek($f, -32 * 2, Fcntl::SEEK_END);
+ return undef if sysread($f, $fextcookie, 32) != 32;
+ }
+ sysseek($f, 0, Fcntl::SEEK_SET);
+ my $fd = solv::xfopen_dup(undef, fileno($f));
my $flags = $ext ? $solv::Repo::REPO_USE_LOADING|$solv::Repo::REPO_EXTEND_SOLVABLES : 0;
$flags |= $solv::Repo::REPO_LOCALPOOL if $ext && $ext ne 'DL';
- if (!$self->{'handle'}->add_solv($f, $flags)) {
- solv::xfclose($f);
+ if (!$self->{'handle'}->add_solv($fd, $flags)) {
+ solv::xfclose($fd);
return undef;
}
- solv::xfclose($f);
+ solv::xfclose($fd);
+ $self->{'cookie'} = $fcookie unless $ext;
+ $self->{'extcookie'} = $fextcookie if $fextcookie;
+ utime undef, undef, $f if $mark;
return 1;
}
return undef;
}
+sub genextcookie {
+ my ($self, $f) = @_;
+ my $chksum = solv::Chksum->new($solv::REPOKEY_TYPE_SHA256);
+ $chksum->add($self->{'cookie'});
+ if ($f) {
+ my @s = stat($f);
+ $chksum->add("@s");
+ }
+ my $extcookie = $chksum->raw();
+ substr($extcookie, 0, 1) = chr(1) if ord(substr($extcookie, 0, 1)) == 0;
+ $self->{'extcookie'} = $extcookie;
+}
+
+sub writecachedrepo {
+ my ($self, $ext, $info) = @_;
+ mkdir("/var/cache/solv", 0755) unless -d "/var/cache/solv";
+ my ($f, $tmpname);
+ eval {
+ ($f, $tmpname) = File::Temp::tempfile(".newsolv-XXXXXX", 'DIR' => '/var/cache/solv');
+ };
+ return unless $f;
+ chmod 0444, $f;
+ my $ff = solv::xfopen_dup(undef, fileno($f));
+ if (!$info) {
+ $self->{'handle'}->write($ff);
+ } elsif ($ext) {
+ $info->write($ff);
+ } else {
+ $self->{'handle'}->write_first_repodata($ff);
+ }
+ solv::xfclose($ff);
+ if ($self->{'type'} ne 'system' && !$ext) {
+ $self->genextcookie($f) unless $self->{'extcookie'};
+ syswrite($f, $self->{'extcookie'});
+ }
+ syswrite($f, $ext ? $self->{'extcookie'} : $self->{'cookie'});
+ close($f);
+ if ($self->{'handle'}->iscontiguous()) {
+ $f = solv::xfopen($tmpname);
+ if ($f) {
+ if (!$ext) {
+ $self->{'handle'}->empty();
+ die("internal error, cannot reload solv file\n") unless $self->{'handle'}->add_solv($f, $solv::Repo::SOLV_ADD_NO_STUBS);
+ } else {
+ $info->extend_to_repo();
+ $info->add_solv($f, $solv::Repo::REPO_EXTEND_SOLVABLES);
+ }
+ solv::xfclose($f);
+ }
+ }
+ rename($tmpname, $self->cachepath($ext));
+}
+
package Repo::rpmmd;
our @ISA = ('Repo::generic');
+sub find {
+ my ($self, $what) = @_;
+ my $di = $self->{'handle'}->Dataiterator($solv::SOLVID_META, $solv::REPOSITORY_REPOMD_TYPE, $what, $solv::Dataiterator::SEARCH_STRING);
+ $di->prepend_keyname($solv::REPOSITORY_REPOMD);
+ for my $d (@$di) {
+ $d->setpos_parent();
+ my $filename = $d->{'pool'}->lookup_str($solv::SOLVID_POS, $solv::REPOSITORY_REPOMD_LOCATION);
+ next unless $filename;
+ my $chksum = $d->{'pool'}->lookup_checksum($solv::SOLVID_POS, $solv::REPOSITORY_REPOMD_CHECKSUM);
+ if (!$chksum) {
+ print "no $filename file checksum!\n";
+ return (undef, undef);
+ }
+ return ($filename, $chksum);
+ }
+ return (undef, undef);
+}
+
+sub add_ext {
+ my ($self, $repodata, $what, $ext) = @_;
+ my ($filename, $chksum) = $self->find($what);
+ ($filename, $chksum) = $self->find('prestodelta') if !$filename && $what eq 'deltainfo';
+ return unless $filename;
+ my $handle = $repodata->new_handle();
+ $repodata->set_poolstr($handle, $solv::REPOSITORY_REPOMD_TYPE, $what);
+ $repodata->set_str($handle, $solv::REPOSITORY_REPOMD_LOCATION, $filename);
+ $repodata->set_checksum($handle, $solv::REPOSITORY_REPOMD_CHECKSUM, $chksum);
+ if ($ext eq 'DL') {
+ $repodata->add_idarray($handle, $solv::REPOSITORY_KEYS, $solv::REPOSITORY_DELTAINFO);
+ $repodata->add_idarray($handle, $solv::REPOSITORY_KEYS, $solv::REPOKEY_TYPE_FLEXARRAY);
+ } elsif ($ext eq 'FL') {
+ $repodata->add_idarray($handle, $solv::REPOSITORY_KEYS, $solv::SOLVABLE_FILELIST);
+ $repodata->add_idarray($handle, $solv::REPOSITORY_KEYS, $solv::REPOKEY_TYPE_DIRSTRARRAY);
+ }
+ $repodata->add_flexarray($solv::SOLVID_META, $solv::REPOSITORY_EXTERNAL, $handle);
+}
+
+sub add_exts {
+ my ($self) = @_;
+ my $repodata = $self->{'handle'}->add_repodata(0);
+ $self->add_ext($repodata, 'deltainfo', 'DL');
+ $self->add_ext($repodata, 'filelists', 'FL');
+ $repodata->internalize();
+}
+
+sub load_ext {
+ my ($self, $repodata) = @_;
+ my $repomdtype = $repodata->lookup_str($solv::SOLVID_META, $solv::REPOSITORY_REPOMD_TYPE);
+ my $ext;
+ if ($repomdtype eq 'filelists') {
+ $ext = 'FL';
+ } elsif ($repomdtype eq 'deltainfo') {
+ $ext = 'DL';
+ } else {
+ return 0;
+ }
+ print("[$self->{'alias'}:$ext: ");
+ STDOUT->flush();
+ if ($self->usecachedrepo($ext)) {
+ print "cached]\n";
+ return 1;
+ }
+ print "fetching]\n";
+ my $filename = $repodata->lookup_str($solv::SOLVID_META, $solv::REPOSITORY_REPOMD_LOCATION);
+ my $filechksum = $repodata->lookup_checksum($solv::SOLVID_META, $solv::REPOSITORY_REPOMD_CHECKSUM);
+ my $f = $self->download($filename, 1, $filechksum);
+ return 0 unless $f;
+ if ($ext eq 'FL') {
+ $self->{'handle'}->add_rpmmd($f, 'FL', $solv::Repo::REPO_USE_LOADING|$solv::Repo::REPO_EXTEND_SOLVABLES);
+ } elsif ($ext eq 'FL') {
+ $self->{'handle'}->add_deltainfoxml($f, $solv::Repo::REPO_USE_LOADING);
+ }
+ solv::xfclose($f);
+ $self->writecachedrepo($ext, $repodata);
+ return 1;
+}
+
+sub load_if_changed {
+ my ($self) = @_;
+ print "rpmmd repo '$self->{'alias'}': ";
+ STDOUT->flush();
+ my $f = $self->download("repodata/repomd.xml");
+ if (!$f) {
+ print "no repomd.xml file, skipped\n";
+ $self->{'handle'}->free(1);
+ delete $self->{'handle'};
+ return undef;
+ }
+ $self->{'cookie'} = $self->calc_cookie_fp($f);
+ if ($self->usecachedrepo(undef, 1)) {
+ print "cached\n";
+ solv::xfclose($f);
+ return 1;
+ }
+ $self->{'handle'}->add_repomdxml($f, 0);
+ solv::xfclose($f);
+ print "fetching\n";
+ my ($filename, $filechksum) = $self->find('primary');
+ if ($filename) {
+ $f = $self->download($filename, 1, $filechksum, 1);
+ if ($f) {
+ $self->{'handle'}->add_rpmmd($f, undef, 0);
+ solv::xfclose($f);
+ }
+ return undef if $self->{'incomplete'};
+ }
+ ($filename, $filechksum) = $self->find('updateinfo');
+ if ($filename) {
+ $f = $self->download($filename, 1, $filechksum, 1);
+ if ($f) {
+ $self->{'handle'}->add_updateinfoxml($f, 0);
+ solv::xfclose($f);
+ }
+ }
+ $self->add_exts();
+ $self->writecachedrepo() unless $self->{'incomplete'};
+ $self->{'handle'}->create_stubs();
+ return 1;
+}
+
package Repo::susetags;
our @ISA = ('Repo::generic');
+sub find {
+ my ($self, $what) = @_;
+
+ my $di = $self->{'handle'}->Dataiterator($solv::SOLVID_META, $solv::SUSETAGS_FILE_NAME, $what, $solv::Dataiterator::SEARCH_STRING);
+ $di->prepend_keyname($solv::SUSETAGS_FILE);
+ for my $d (@$di) {
+ $d->setpos_parent();
+ my $chksum = $d->{'pool'}->lookup_checksum($solv::SOLVID_POS, $solv::SUSETAGS_FILE_CHECKSUM);
+ return ($what, $chksum);
+ }
+ return (undef, undef);
+}
+
+my %langtags = (
+ $solv::SOLVABLE_SUMMARY => $solv::REPOKEY_TYPE_STR,
+ $solv::SOLVABLE_DESCRIPTION => $solv::REPOKEY_TYPE_STR,
+ $solv::SOLVABLE_EULA => $solv::REPOKEY_TYPE_STR,
+ $solv::SOLVABLE_MESSAGEINS => $solv::REPOKEY_TYPE_STR,
+ $solv::SOLVABLE_MESSAGEDEL => $solv::REPOKEY_TYPE_STR,
+ $solv::SOLVABLE_CATEGORY => $solv::REPOKEY_TYPE_ID,
+);
+
+sub add_ext {
+ my ($self, $repodata, $what, $ext) = @_;
+ my ($filename, $chksum) = $self->find($what);
+ my $handle = $repodata->new_handle();
+ $repodata->set_str($handle, $solv::SUSETAGS_FILE_NAME, $filename);
+ $repodata->set_checksum($handle, $solv::SUSETAGS_FILE_CHECKSUM, $chksum);
+ if ($ext eq 'DL') {
+ $repodata->add_idarray($handle, $solv::REPOSITORY_KEYS, $solv::REPOSITORY_DELTAINFO);
+ $repodata->add_idarray($handle, $solv::REPOSITORY_KEYS, $solv::REPOKEY_TYPE_FLEXARRAY);
+ } elsif ($ext eq 'DU') {
+ $repodata->add_idarray($handle, $solv::REPOSITORY_KEYS, $solv::SOLVABLE_DISKUSAGE);
+ $repodata->add_idarray($handle, $solv::REPOSITORY_KEYS, $solv::REPOKEY_TYPE_DIRNUMNUMARRAY);
+ } elsif ($ext eq 'FL') {
+ $repodata->add_idarray($handle, $solv::REPOSITORY_KEYS, $solv::SOLVABLE_FILELIST);
+ $repodata->add_idarray($handle, $solv::REPOSITORY_KEYS, $solv::REPOKEY_TYPE_DIRSTRARRAY);
+ } else {
+ for my $langid (sort {$a <=> $b} keys %langtags) {
+ $repodata->add_idarray($handle, $solv::REPOSITORY_KEYS, $self->{'handle'}->{'pool'}->id2langid($langid, $ext, 1));
+ $repodata->add_idarray($handle, $solv::REPOSITORY_KEYS, $langtags{$langid});
+ }
+ }
+ $repodata->add_flexarray($solv::SOLVID_META, $solv::REPOSITORY_EXTERNAL, $handle);
+}
+
+sub add_exts {
+ my ($self) = @_;
+ my $repodata = $self->{'handle'}->add_repodata(0);
+ my $di = $self->{'handle'}->Dataiterator($solv::SOLVID_META, $solv::SUSETAGS_FILE_NAME, undef, 0);
+ $di->prepend_keyname($solv::SUSETAGS_FILE);
+ for my $d (@$di) {
+ my $filename = $d->str();
+ next unless $filename && $filename =~ /^packages\.(..)(?:\..*)$/;
+ next if $1 eq 'en' || $1 eq 'gz';
+ $self->add_ext($repodata, $filename, $1);
+ }
+ $repodata->internalize();
+}
+
+sub load_ext {
+ my ($self, $repodata) = @_;
+ my $filename = $repodata->lookup_str($solv::SOLVID_META, $solv::SUSETAGS_FILE_NAME);
+ my $ext = substr($filename, 9, 2);
+ print("[$self->{'alias'}:$ext: ");
+ STDOUT->flush();
+ if ($self->usecachedrepo($ext)) {
+ print "cached]\n";
+ return 1;
+ }
+ print "fetching]\n";
+ my $defvendorid = $self->{'handle'}->lookup_id($solv::SOLVID_META, $solv::SUSETAGS_DEFAULTVENDOR);
+ my $descrdir = $self->{'handle'}->lookup_str($solv::SOLVID_META, $solv::SUSETAGS_DESCRDIR) || 'suse/setup/descr';
+ my $filechksum = $repodata->lookup_checksum($solv::SOLVID_META, $solv::SUSETAGS_FILE_CHECKSUM);
+ my $f = $self->download("$descrdir/$filename", 1, $filechksum);
+ return 0 unless $f;
+ $self->{'handle'}->add_susetags($f, $defvendorid, $ext, $solv::Repo::REPO_USE_LOADING|$solv::Repo::REPO_EXTEND_SOLVABLES);
+ solv::xfclose($f);
+ $self->writecachedrepo($ext, $repodata);
+ return 1;
+}
+
+sub load_if_changed {
+ my ($self) = @_;
+ print "susetags repo '$self->{'alias'}': ";
+ STDOUT->flush();
+ my $f = $self->download("content");
+ if (!$f) {
+ print "no content file, skipped\n";
+ $self->{'handle'}->free(1);
+ delete $self->{'handle'};
+ return undef;
+ }
+ $self->{'cookie'} = $self->calc_cookie_fp($f);
+ if ($self->usecachedrepo(undef, 1)) {
+ print "cached\n";
+ solv::xfclose($f);
+ return 1;
+ }
+ $self->{'handle'}->add_content($f, 0);
+ solv::xfclose($f);
+ print "fetching\n";
+ my $defvendorid = $self->{'handle'}->lookup_id($solv::SOLVID_META, $solv::SUSETAGS_DEFAULTVENDOR);
+ my $descrdir = $self->{'handle'}->lookup_str($solv::SOLVID_META, $solv::SUSETAGS_DESCRDIR) || 'suse/setup/descr';
+ my ($filename, $filechksum) = $self->find('packages.gz');
+ ($filename, $filechksum) = $self->find('packages') unless $filename;
+ if ($filename) {
+ $f = $self->download("$descrdir/$filename", 1, $filechksum, 1);
+ if ($f) {
+ $self->{'handle'}->add_susetags($f, $defvendorid, undef, $solv::Repo::REPO_NO_INTERNALIZE|$solv::Repo::SUSETAGS_RECORD_SHARES);
+ solv::xfclose($f);
+ ($filename, $filechksum) = $self->find('packages.en.gz');
+ ($filename, $filechksum) = $self->find('packages.en') unless $filename;
+ if ($filename) {
+ $f = $self->download("$descrdir/$filename", 1, $filechksum, 1);
+ if ($f) {
+ $self->{'handle'}->add_susetags($f, $defvendorid, undef, $solv::Repo::REPO_NO_INTERNALIZE|$solv::Repo::REPO_REUSE_REPODATA|$solv::Repo::REPO_EXTEND_SOLVABLES);
+ solv::xfclose($f);
+ }
+ }
+ $self->{'handle'}->internalize();
+ }
+ }
+ $self->add_exts();
+ $self->writecachedrepo() unless $self->{'incomplete'};
+ $self->{'handle'}->create_stubs();
+ return undef;
+}
+
package Repo::unknown;
our @ISA = ('Repo::generic');
our @ISA = ('Repo::generic');
-sub calc_cookie_file {
- my ($self, $filename) = @_;
- my $chksum = solv::Chksum->new($solv::REPOKEY_TYPE_SHA256);
- $chksum->add("1.1");
- $chksum->add_stat($filename);
- return $chksum->raw();
-}
-
sub load {
my ($self, $pool) = @_;
print "cached\n";
return 1;
}
- return undef;
+ print "reading\n";
+ $self->{'handle'}->add_products("/etc/products.d", $solv::Repo::REPO_NO_INTERNALIZE);
+ $self->{'handle'}->add_rpmdb(undef, $solv::Repo::REPO_REUSE_REPODATA);
+ $self->writecachedrepo();
+ return 1;
}
package main;
my $id = $pool->str2id($name, 0);
if ($id) {
my $match;
- for my $s ($pool->providers($id)) {
+ for my $s ($pool->whatprovides($id)) {
return $pool->Job($solv::Job::SOLVER_SOLVABLE_NAME, $id) if $globname && $s->{'nameid'} == $id;
$match = 1;
}
if ($match) {
print "[using capability match for '$name']\n" if $globname && $globdep;
- my @j = $pool->Job($solv::Job::SOLVER_SOLVABLE_PROVIDES, $id);
return $pool->Job($solv::Job::SOLVER_SOLVABLE_PROVIDES, $id);
}
}
return unless $name =~ /[[*?]/;
if ($globname) {
my %idmatches;
- for my $d (@{$pool->dataiterator_new(0, $solv::SOLVABLE_NAME, $name, $solv::Dataiterator::SEARCH_GLOB)}) {
+ for my $d (@{$pool->Dataiterator(0, $solv::SOLVABLE_NAME, $name, $solv::Dataiterator::SEARCH_GLOB)}) {
my $s = $d->{'solvable'};
$idmatches{$s->{'nameid'}} = 1 if $s->installable();
}
}
sub limitjobs {
- my ($pool, $jobs, $flags, $evr) = @_;
+ my ($pool, $jobs, $flags, $evrstr) = @_;
my @jobs;
+ my $evr = $pool->str2id($evrstr);
for my $j (@$jobs) {
my $how = $j->{'how'};
my $sel = $how & $solv::Job::SOLVER_SELECTMASK;
if ($flags == $solv::REL_ARCH) {
$how |= $solv::Job::SOLVER_SETARCH;
} elsif ($flags == $solv::REL_EQ && $sel == $solv::Job::SOLVER_SOLVABLE_NAME) {
- $how |= $pool->id2str($evr) =~ /-/ ? $solv::Job::SOLVER_SETEVR : $solv::Job::SOLVER_SETEV;
+ $how |= $evrstr =~ /-/ ? $solv::Job::SOLVER_SETEVR : $solv::Job::SOLVER_SETEV;
}
push @jobs, $pool->Job($how, $what);
}
return @jobs;
}
-sub limitjobs_arch {
+sub limitjobs_evrarch {
my ($pool, $jobs, $flags, $evrstr) = @_;
if ($evrstr =~ /^(.+)\.(.+?)$/ && validarch($pool, $2)) {
- my $evr = $pool->str2id($1);
- my @jobs = limitjobs($pool, $jobs, $solv::REL_ARCH, $pool->str2id($2));
- return limitjobs($pool, \@jobs, $flags, $evr);
+ $evrstr = $1;
+ $jobs = [ limitjobs($pool, $jobs, $solv::REL_ARCH, $2) ];
}
- return limitjobs($pool, $jobs, $flags, $pool->str2id($evrstr));
+ return limitjobs($pool, $jobs, $flags, $evrstr);
}
sub mkjobs_rel {
$flags |= $solv::REL_EQ if $rel =~ /=/;
$flags |= $solv::REL_GT if $rel =~ />/;
my @jobs = depglob($pool, $name, 1, 1);
- return limitjobs($pool, \@jobs, $flags, $pool->str2id($evr)) if @jobs;
+ return limitjobs($pool, \@jobs, $flags, $evr) if @jobs;
if (($name =~ /^(.+)\.(.+?)$/s) && validarch($pool, $2)) {
my $arch = $2;
@jobs = depglob($pool, $1, 1, 1);
if (@jobs) {
- @jobs = limitjobs($pool, \@jobs, $solv::REL_ARCH, $pool->str2id($arch));
- return limitjobs($pool, \@jobs, $flags, $pool->str2id($evr));
+ @jobs = limitjobs($pool, \@jobs, $solv::REL_ARCH, $arch);
+ return limitjobs($pool, \@jobs, $flags, $evr);
}
}
return ();
if (($arg =~ /^(.+)\.(.+?)$/s) && validarch($pool, $2)) {
my $arch = $2;
@jobs = depglob($pool, $1, 1, 1);
- return limitjobs($pool, \@jobs, $solv::REL_ARCH, $pool->str2id($arch)) if @jobs;
+ return limitjobs($pool, \@jobs, $solv::REL_ARCH, $arch) if @jobs;
}
if ($arg =~ /^(.+)-(.+?)$/s) {
my $evr = $2;
@jobs = depglob($pool, $1, 1, 0);
- return limitjobs_arch($pool, \@jobs, $solv::REL_EQ, $evr) if @jobs;
+ return limitjobs_evrarch($pool, \@jobs, $solv::REL_EQ, $evr) if @jobs;
}
if ($arg =~ /^(.+)-(.+?-.+?)$/s) {
my $evr = $2;
@jobs = depglob($pool, $1, 1, 0);
- return limitjobs_arch($pool, \@jobs, $solv::REL_EQ, $evr) if @jobs;
+ return limitjobs_evrarch($pool, \@jobs, $solv::REL_EQ, $evr) if @jobs;
}
return ();
}
$type |= $solv::Dataiterator::SEARCH_FILES | $solv::Dataiterator::SEARCH_COMPLETE_FILELIST;
my $di;
if ($cmd eq 'erase') {
- $di = $pool->{'installed'}->dataiterator_new(0, $solv::SOLVABLE_FILELIST, $arg, $type);
+ $di = $pool->{'installed'}->Dataiterator(0, $solv::SOLVABLE_FILELIST, $arg, $type);
} else {
- $di = $pool->dataiterator_new(0, $solv::SOLVABLE_FILELIST, $arg, $type);
+ $di = $pool->Dataiterator(0, $solv::SOLVABLE_FILELIST, $arg, $type);
}
my @matches;
for my $d (@$di) {
my $s = $d->{'solvable'};
next unless $s && $s->installable();
push @matches, $s->{'id'};
- tied(@$di)->iter()->skip_solvable();
+ $di->skip_solvable();
}
return () unless @matches;
print "[using file list match for '$arg']\n";
}
}
+sub load_stub {
+ my ($repodata) = @_;
+ my $repo = $repodata->{'repo'}->{'appdata'};
+ return $repo ? $repo->load_ext($repodata) : 0;
+}
+
die("Usage: p5solv COMMAND [ARGS]\n") unless @ARGV;
my $cmd = shift @ARGV;
$cmd = 'list' if $cmd eq 'li';
$cmd = 'verify' if $cmd eq 've';
$cmd = 'search' if $cmd eq 'se';
-my $pool = solv::Pool->new();
-$pool->setarch((POSIX::uname())[4]);
my @repos;
for my $reposdir ('/etc/zypp/repos.d') {
next unless -d $reposdir;
}
my $repo;
if ($repoattr->{'type'} eq 'rpm-md') {
- $repo = Repo::rpmmd->new($repoattr);
+ $repo = Repo::rpmmd->new($alias, 'repomd', $repoattr);
} elsif ($repoattr->{'type'} eq 'yast2') {
- $repo = Repo::susetags->new($repoattr);
+ $repo = Repo::susetags->new($alias, 'susetags', $repoattr);
} else {
- $repo = Repo::unknown->new($repoattr);
+ $repo = Repo::unknown->new($alias, 'unknown', $repoattr);
}
push @repos, $repo;
}
}
}
-my $sysrepo = Repo::system->new({'alias' => '@System', 'type' => 'system'});
+my $pool = solv::Pool->new();
+$pool->setarch((POSIX::uname())[4]);
+$pool->set_loadcallback(\&load_stub);
+
+my $sysrepo = Repo::system->new('@System', 'system');
$sysrepo->load($pool);
for my $repo (@repos) {
$repo->load($pool) if $repo->{'enabled'};
if ($cmd eq 'search') {
my %matches;
- my $di = $pool->dataiterator_new(0, $solv::SOLVABLE_NAME, $ARGV[0], $solv::Dataiterator::SEARCH_SUBSTRING | $solv::Dataiterator::SEARCH_NOCASE);
+ my $di = $pool->Dataiterator(0, $solv::SOLVABLE_NAME, $ARGV[0], $solv::Dataiterator::SEARCH_SUBSTRING | $solv::Dataiterator::SEARCH_NOCASE);
for my $d (@$di) {
$matches{$d->{'solvid'}} = 1;
}
if ($cmd eq 'list' || $cmd eq 'info') {
die("no package matched.\n") unless @jobs;
for my $job (@jobs) {
- for my $s ($pool->jobsolvables($job)) {
+ for my $s ($job->solvables()) {
if ($cmd eq 'info') {
printf "Name: %s\n", $s->str();
printf "Repo: %s\n", $s->{'repo'}->{'name'};
if ($cmd eq 'install' || $cmd eq 'erase' || $cmd eq 'up' || $cmd eq 'dup' || $cmd eq 'verify') {
if (!@jobs) {
- if ($cmd eq 'up' || $cmd eq 'verify') {
+ if ($cmd eq 'up' || $cmd eq 'verify' || $cmd eq 'dup') {
push @jobs, $pool->Job($solv::Job::SOLVER_SOLVABLE_ALL, 0);
- } elsif ($cmd ne 'dup') {
+ } else {
die("no package matched.\n");
}
}
for my $job (@jobs) {
if ($cmd eq 'up') {
- if ($job->{'how'} == $solv::Job::SOLVER_SOLVABLE_ALL || grep {$_->isinstalled()} $pool->jobsolvables($job)) {
+ if ($job->{'how'} == $solv::Job::SOLVER_SOLVABLE_ALL || grep {$_->isinstalled()} $job->solvables()) {
$job->{'how'} |= $solv::Job::SOLVER_UPDATE;
} else {
$job->{'how'} |= $solv::Job::SOLVER_INSTALL;
}
my $solver;
while (1) {
- $solver = $pool->create_solver();
- $solver->{'ignorealreadyrecommended'} = 1;
- $solver->{'allowuninstall'} = 1 if $cmd eq 'erase';
- if ($cmd eq 'dup' && !@jobs) {
- $solver->{'distupgrade'} = 1;
- $solver->{'updatesystem'} = 1;
- $solver->{'allowdowngrade'} = 1;
- $solver->{'allowvendorchange'} = 1;
- $solver->{'allowarchchange'} = 1;
- $solver->{'dosplitprovides'} = 1;
- } elsif ($cmd eq 'up' and @jobs == 1 and $jobs[0]->{'how'} == ($solv::Job::SOLVER_UPDATE | $solv::Job::SOLVER_SOLVABLE_ALL)) {
- $solver->{'dosplitprovides'} = 1;
+ $solver = $pool->Solver();
+ $solver->set_flag($solv::Solver::SOLVER_FLAG_IGNORE_ALREADY_RECOMMENDED, 1);
+ $solver->set_flag($solv::Solver::SOLVER_FLAG_ALLOW_UNINSTALL, 1) if $cmd eq 'erase';
+ if ($cmd eq 'dup' && @jobs == 1 $jobs[0]->{'how'} == ($solv::Job::SOLVER_DISTUPGRADE | $solv::Job::SOLVER_SOLVABLE_ALL)) {
+ $solver->set_flag($solv::Solver::SOLVER_FLAG_ALLOW_DOWNGRADE, 1);
+ $solver->set_flag($solv::Solver::SOLVER_FLAG_ALLOW_VENDERCHANGE, 1);
+ $solver->set_flag($solv::Solver::SOLVER_FLAG_ALLOW_ARCHCHANGE, 1);
+ $solver->set_flag($solv::Solver::SOLVER_FLAG_SPLITPROVIDES, 1);
+ } elsif ($cmd eq 'up' && @jobs == 1 && $jobs[0]->{'how'} == ($solv::Job::SOLVER_UPDATE | $solv::Job::SOLVER_SOLVABLE_ALL)) {
+ $solver->set_flag($solv::Solver::SOLVER_FLAG_SPLITPROVIDES, 1);
}
my @problems = $solver->solve(\@jobs);
last unless @problems;
print " - allow something else\n";
}
}
+ print "\n";
}
my $sol;
while (1) {
$jobs[$element->{'jobidx'}] = $pool->Job($solv::Job::SOLVER_NOOP, 0);
} else {
my $newjob = $element->Job();
- push @jobs, $newjob if $newjob && !grep {$_->{'how'} == $newjob->{'how'} && $_->{'what'} == $newjob->{'what'}} @jobs;
+ push @jobs, $newjob if $newjob && !grep {$_ == $newjob} @jobs;
}
}
}
}
print "\nTransaction summary:\n\n";
for my $c ($trans->classify()) {
- my ($ctype, $pkgs, $fromid, $toid) = @$c;
- if ($ctype == $solv::Transaction::SOLVER_TRANSACTION_ERASE) {
- printf "%d erased packages:\n", scalar(@$pkgs);
- } elsif ($ctype == $solv::Transaction::SOLVER_TRANSACTION_INSTALL) {
- printf "%d installed packages:\n", scalar(@$pkgs);
- } elsif ($ctype == $solv::Transaction::SOLVER_TRANSACTION_REINSTALLED) {
- printf "%d reinstalled packages:\n", scalar(@$pkgs);
- } elsif ($ctype == $solv::Transaction::SOLVER_TRANSACTION_DOWNGRADED) {
- printf "%d downgraded packages:\n", scalar(@$pkgs);
- } elsif ($ctype == $solv::Transaction::SOLVER_TRANSACTION_CHANGED) {
- printf "%d changed packages:\n", scalar(@$pkgs);
- } elsif ($ctype == $solv::Transaction::SOLVER_TRANSACTION_UPGRADED) {
- printf "%d upgraded packages:\n", scalar(@$pkgs);
- } elsif ($ctype == $solv::Transaction::SOLVER_TRANSACTION_VENDORCHANGE) {
- printf "%d vendor changes from '%s' to '%s':\n", scalar(@$pkgs), $pool->id2str($fromid), $pool->id2str($toid);
- } elsif ($ctype == $solv::Transaction::SOLVER_TRANSACTION_ARCHCHANGE) {
- printf "%d arch changes from '%s' to '%s':\n", scalar(@$pkgs), $pool->id2str($fromid), $pool->id2str($toid);
+ if ($c->{'type'} == $solv::Transaction::SOLVER_TRANSACTION_ERASE) {
+ print "$c->{'count'} erased packages:\n";
+ } elsif ($c->{'type'} == $solv::Transaction::SOLVER_TRANSACTION_INSTALL) {
+ print "$c->{'count'} installed packages:\n";
+ } elsif ($c->{'type'} == $solv::Transaction::SOLVER_TRANSACTION_REINSTALLED) {
+ print "$c->{'count'} reinstalled packages:\n";
+ } elsif ($c->{'type'} == $solv::Transaction::SOLVER_TRANSACTION_DOWNGRADED) {
+ print "$c->{'count'} downgraded packages:\n";
+ } elsif ($c->{'type'} == $solv::Transaction::SOLVER_TRANSACTION_CHANGED) {
+ print "$c->{'count'} changed packages:\n";
+ } elsif ($c->{'type'} == $solv::Transaction::SOLVER_TRANSACTION_UPGRADED) {
+ print "$c->{'count'} upgraded packages:\n";
+ } elsif ($c->{'type'} == $solv::Transaction::SOLVER_TRANSACTION_VENDORCHANGE) {
+ printf "$c->{'count'} vendor changes from '%s' to '%s':\n", $pool->id2str($c->{'fromid'}), $pool->id2str($c->{'toid'});
+ } elsif ($c->{'type'} == $solv::Transaction::SOLVER_TRANSACTION_ARCHCHANGE) {
+ printf "$c->{'count'} arch changes from '%s' to '%s':\n", $pool->id2str($c->{'fromid'}), $pool->id2str($c->{'toid'});
} else {
next;
}
- for my $p (@$pkgs) {
- if ($ctype == $solv::Transaction::SOLVER_TRANSACTION_UPGRADED || $ctype == $solv::Transaction::SOLVER_TRANSACTION_DOWNGRADED) {
+ for my $p ($c->solvables()) {
+ if ($c->{'type'} == $solv::Transaction::SOLVER_TRANSACTION_UPGRADED || $c->{'type'} == $solv::Transaction::SOLVER_TRANSACTION_DOWNGRADED) {
my $other = $trans->othersolvable($p);
printf " - %s -> %s\n", $p->str(), $other->str();
} else {
my $repo = $p->{'repo'}->{'appdata'};
my ($location, $medianr) = $p->lookup_location();
next unless $location;
- if ($repo->{'type'} eq 'yast2') {
+ if ($repo->{'type'} eq 'susetags') {
$location = ($repo->{'handle'}->lookup_str($solv::SOLVID_META, $solv::SUSETAGS_DATADIR) || 'suse') ."/$location";
}
my $chksum = $p->lookup_checksum($solv::SOLVABLE_CHECKSUM);