14 package Repo::generic;
17 my ($class, $attr) = @_;
19 return bless $r, $class;
24 my $chksum = solv::Chksum->new($solv::REPOKEY_TYPE_SHA256);
26 return $chksum->raw();
29 sub calc_cookie_file {
30 my ($self, $filename) = @_;
31 my $chksum = solv::Chksum->new($solv::REPOKEY_TYPE_SHA256);
33 $chksum->add_stat($filename);
34 return $chksum->raw();
38 my ($self, $ext) = @_;
39 my $path = $self->{'alias'};
41 $path .= $ext ? "_$ext.solvx" : '.solv';
43 return "/var/cache/solv/$path";
47 my ($self, $pool) = @_;
48 $self->{'handle'} = $pool->add_repo($self->{'alias'});
49 $self->{'handle'}->{'appdata'} = $self;
50 $self->{'handle'}->{'priority'} = 99 - $self->{'priority'};
51 my $dorefresh = $self->{'autorefresh'};
53 my @s = stat($self->cachepath());
54 $dorefresh = 0 if @s && time() - $s[9] < $self->{'metadata_expire'};
56 $self->{'cookie'} = '';
57 if (!$dorefresh && $self->usecachedrepo()) {
58 print "repo: '$self->{'alias'}' cached\n";
61 return $self->load_if_changed();
69 my ($self, $file, $uncompress, $chksum, $markincomplete) = @_;
70 if (!$self->{'baseurl'}) {
71 print "$self->{'alias'}: no baseurl\n";
74 my $url = $self->{'baseurl'};
77 open(my $f, '+>', undef) || die;
78 fcntl($f, Fcntl::F_SETFD, 0);
79 my $st = system('curl', '-f', '-s', '-L', '-o', "/dev/fd/".fileno($f), '--', $url);
80 if (POSIX::lseek(fileno($f), 0, POSIX::SEEK_END) == 0 && ($st == 0 || !$chksum)) {
83 POSIX::lseek(fileno($f), 0, POSIX::SEEK_SET);
85 print "$file: download error #$st\n";
86 $self->{'incomplete'} = 1 if $markincomplete;
90 my $fchksum = solv::Chksum->new($chksum->{'type'});
91 $fchksum->add_fd(fileno($f));
92 if (!$fchksum->matches($chksum)) {
93 print "$file: checksum error\n";
94 $self->{'incomplete'} = 1 if $markincomplete;
99 return solv::xfopen_fd($file, POSIX::dup(fileno($f)));
101 return solv::xfopen_fd('', POSIX::dup(fileno($f)));
106 my ($self, $ext, $mark) = @_;
107 my $cookie = $ext ? $self->{'extcookie'} : $self->{'cookie'};
108 my $handle = $self->{'handle'};
109 my $cachepath = $self->cachepath($ext);
111 if (sysopen(my $f, $cachepath, POSIX::O_RDONLY)) {
112 sysseek($f, -32, Fcntl::SEEK_END);
114 return undef if sysread($f, $fcookie, 32) != 32;
115 return undef if $cookie && $fcookie ne $cookie;
116 if ($self->{'alias'} ne '@System' && !$ext) {
117 sysseek($f, -32 * 2, Fcntl::SEEK_END);
118 return undef if sysread($f, $fextcookie, 32) != 32;
120 sysseek($f, 0, Fcntl::SEEK_SET);
121 $f = solv::xfopen_fd('', POSIX::dup(fileno($f)));
122 my $flags = $ext ? $solv::Repo::REPO_USE_LOADING|$solv::Repo::REPO_EXTEND_SOLVABLES : 0;
123 $flags |= $solv::Repo::REPO_LOCALPOOL if $ext && $ext ne 'DL';
124 if (!$self->{'handle'}->add_solv($f, $flags)) {
129 $self->{'cookie'} = $fcookie unless $ext;
130 $self->{'extcookie'} = $fextcookie if $fextcookie;
131 utime undef, undef, $f if $mark;
139 my $chksum = solv::Chksum->new($solv::REPOKEY_TYPE_SHA256);
140 $chksum->add($self->{'cookie'});
145 my $extcookie = $chksum->raw();
146 substr($extcookie, 0, 1) = chr(1) if ord(substr($extcookie, 0, 1)) == 0;
147 $self->{'extcookie'} = $extcookie;
150 sub writecachedrepo {
151 my ($self, $ext, $info) = @_;
152 mkdir("/var/cache/solv", 0755) unless -d "/var/cache/solv";
155 ($f, $tmpname) = File::Temp::tempfile(".newsolv-XXXXXX", 'DIR' => '/var/cache/solv');
159 my $ff = solv::xfopen_fd('', POSIX::dup(fileno($f)));
161 $self->{'handle'}->write($ff);
165 $self->{'handle'}->write_first_repodata($ff);
168 if ($self->{'alias'} ne '@System' && !$ext) {
169 $self->genextcookie($f) unless $self->{'extcookie'};
170 syswrite($f, $self->{'extcookie'});
172 syswrite($f, $ext ? $self->{'extcookie'} : $self->{'cookie'});
174 if ($self->{'handle'}->iscontiguous()) {
175 $f = solv::xfopen($tmpname);
178 $self->{'handle'}->empty();
179 die("internal error, cannot reload solv file\n") unless $self->{'handle'}->add_solv($f, $solv::Repo::SOLV_ADD_NO_STUBS);
181 $info->extend_to_repo();
182 $info->read_solv_flags($f, $solv::Repo::REPO_EXTEND_SOLVABLES);
187 rename($tmpname, $self->cachepath($ext));
192 our @ISA = ('Repo::generic');
195 my ($self, $what) = @_;
196 my $di = $self->{'handle'}->Dataiterator($solv::SOLVID_META, $solv::REPOSITORY_REPOMD_TYPE, $what, $solv::Dataiterator::SEARCH_STRING);
197 $di->prepend_keyname($solv::REPOSITORY_REPOMD);
200 my $filename = $d->{'pool'}->lookup_str($solv::SOLVID_POS, $solv::REPOSITORY_REPOMD_LOCATION);
201 my $chksum = $d->{'pool'}->lookup_checksum($solv::SOLVID_POS, $solv::REPOSITORY_REPOMD_CHECKSUM);
202 if ($filename && !$chksum) {
203 print "no $filename file checksum!\n";
204 return (undef, undef);
206 return ($filename, $chksum) if $filename;
208 return (undef, undef);
212 my ($self, $repodata, $what, $ext) = @_;
213 my ($filename, $chksum) = $self->find($what);
214 ($filename, $chksum) = $self->find('prestodelta') if !$filename && $what eq 'deltainfo';
215 return unless $filename;
216 my $handle = $repodata->new_handle();
217 $repodata->set_poolstr($handle, $solv::REPOSITORY_REPOMD_TYPE, $what);
218 $repodata->set_str($handle, $solv::REPOSITORY_REPOMD_LOCATION, $filename);
219 $repodata->set_bin_checksum($handle, $solv::REPOSITORY_REPOMD_CHECKSUM, $chksum);
221 $repodata->add_idarray($handle, $solv::REPOSITORY_KEYS, $solv::REPOSITORY_DELTAINFO);
222 $repodata->add_idarray($handle, $solv::REPOSITORY_KEYS, $solv::REPOKEY_TYPE_FLEXARRAY);
223 } elsif ($ext eq 'FL') {
224 $repodata->add_idarray($handle, $solv::REPOSITORY_KEYS, $solv::SOLVABLE_FILELIST);
225 $repodata->add_idarray($handle, $solv::REPOSITORY_KEYS, $solv::REPOKEY_TYPE_DIRSTRARRAY);
227 $repodata->add_flexarray($solv::SOLVID_META, $solv::REPOSITORY_EXTERNAL, $handle);
232 my $repodata = $self->{'handle'}->add_repodata(0);
233 $self->add_ext($repodata, 'deltainfo', 'DL');
234 $self->add_ext($repodata, 'filelists', 'FL');
235 $repodata->internalize();
239 my ($self, $repodata) = @_;
240 my $repomdtype = $repodata->lookup_str($solv::SOLVID_META, $solv::REPOSITORY_REPOMD_TYPE);
242 if ($repomdtype eq 'filelists') {
244 } elsif ($repomdtype eq 'deltainfo') {
249 print("[$self->{'alias'}:$ext: ");
251 if ($self->usecachedrepo($ext)) {
256 my $filename = $repodata->lookup_str($solv::SOLVID_META, $solv::REPOSITORY_REPOMD_LOCATION);
257 my $filechksum = $repodata->lookup_checksum($solv::SOLVID_META, $solv::REPOSITORY_REPOMD_CHECKSUM);
258 my $f = $self->download($filename, 1, $filechksum);
261 $self->{'handle'}->add_rpmmd($f, 'FL', $solv::Repo::REPO_USE_LOADING|$solv::Repo::REPO_EXTEND_SOLVABLES);
262 } elsif ($ext eq 'FL') {
263 $self->{'handle'}->add_deltainfoxml($f, $solv::Repo::REPO_USE_LOADING);
266 $self->writecachedrepo($ext, $repodata);
270 sub load_if_changed {
272 print "rpmmd repo '$self->{'alias'}': ";
274 my $f = $self->download("repodata/repomd.xml");
276 print "no repomd.xml file, skipped\n";
277 $self->{'handle'}->free(1);
278 delete $self->{'handle'};
281 $self->{'cookie'} = $self->calc_cookie_fp($f);
282 if ($self->usecachedrepo(undef, 1)) {
287 $self->{'handle'}->add_repomdxml($f, 0);
290 my ($filename, $filechksum) = $self->find('primary');
292 $f = $self->download($filename, 1, $filechksum, 1);
294 $self->{'handle'}->add_rpmmd($f, undef, 0);
297 return undef if $self->{'incomplete'};
299 ($filename, $filechksum) = $self->find('updateinfo');
301 $f = $self->download($filename, 1, $filechksum, 1);
303 $self->{'handle'}->add_updateinfoxml($f, 0);
308 $self->writecachedrepo() unless $self->{'incomplete'};
309 $self->{'handle'}->create_stubs();
313 package Repo::susetags;
315 our @ISA = ('Repo::generic');
318 my ($self, $what) = @_;
320 my $di = $self->{'handle'}->Dataiterator($solv::SOLVID_META, $solv::SUSETAGS_FILE_NAME, $what, $solv::Dataiterator::SEARCH_STRING);
321 $di->prepend_keyname($solv::SUSETAGS_FILE);
324 my $chksum = $d->{'pool'}->lookup_checksum($solv::SOLVID_POS, $solv::SUSETAGS_FILE_CHECKSUM);
325 return ($what, $chksum);
327 return (undef, undef);
331 $solv::SOLVABLE_SUMMARY => $solv::REPOKEY_TYPE_STR,
332 $solv::SOLVABLE_DESCRIPTION => $solv::REPOKEY_TYPE_STR,
333 $solv::SOLVABLE_EULA => $solv::REPOKEY_TYPE_STR,
334 $solv::SOLVABLE_MESSAGEINS => $solv::REPOKEY_TYPE_STR,
335 $solv::SOLVABLE_MESSAGEDEL => $solv::REPOKEY_TYPE_STR,
336 $solv::SOLVABLE_CATEGORY => $solv::REPOKEY_TYPE_ID,
340 my ($self, $repodata, $what, $ext) = @_;
341 my ($filename, $chksum) = $self->find($what);
342 my $handle = $repodata->new_handle();
343 $repodata->set_str($handle, $solv::SUSETAGS_FILE_NAME, $filename);
344 $repodata->set_bin_checksum($handle, $solv::SUSETAGS_FILE_CHECKSUM, $chksum);
346 $repodata->add_idarray($handle, $solv::REPOSITORY_KEYS, $solv::REPOSITORY_DELTAINFO);
347 $repodata->add_idarray($handle, $solv::REPOSITORY_KEYS, $solv::REPOKEY_TYPE_FLEXARRAY);
348 } elsif ($ext eq 'DU') {
349 $repodata->add_idarray($handle, $solv::REPOSITORY_KEYS, $solv::SOLVABLE_DISKUSAGE);
350 $repodata->add_idarray($handle, $solv::REPOSITORY_KEYS, $solv::REPOKEY_TYPE_DIRNUMNUMARRAY);
351 } elsif ($ext eq 'FL') {
352 $repodata->add_idarray($handle, $solv::REPOSITORY_KEYS, $solv::SOLVABLE_FILELIST);
353 $repodata->add_idarray($handle, $solv::REPOSITORY_KEYS, $solv::REPOKEY_TYPE_DIRSTRARRAY);
355 for my $langid (sort {$a <=> $b} keys %langtags) {
356 $repodata->add_idarray($handle, $solv::REPOSITORY_KEYS, $self->{'handle'}->{'pool'}->id2langid($langid, $ext, 1));
357 $repodata->add_idarray($handle, $solv::REPOSITORY_KEYS, $langtags{$langid});
360 $repodata->add_flexarray($solv::SOLVID_META, $solv::REPOSITORY_EXTERNAL, $handle);
365 my $repodata = $self->{'handle'}->add_repodata(0);
366 my $di = $self->{'handle'}->Dataiterator($solv::SOLVID_META, $solv::SUSETAGS_FILE_NAME, undef, 0);
367 $di->prepend_keyname($solv::SUSETAGS_FILE);
369 my $filename = $d->match_str();
370 next unless $filename && $filename =~ /^packages\.(..)(?:\..*)$/;
371 next if $1 eq 'en' || $1 eq 'gz';
372 $self->add_ext($repodata, $filename, $1);
374 $repodata->internalize();
378 my ($self, $repodata) = @_;
379 my $filename = $repodata->lookup_str($solv::SOLVID_META, $solv::SUSETAGS_FILE_NAME);
380 my $ext = substr($filename, 9, 2);
381 print("[$self->{'alias'}:$ext: ");
383 if ($self->usecachedrepo($ext)) {
388 my $defvendorid = $self->{'handle'}->lookup_id($solv::SOLVID_META, $solv::SUSETAGS_DEFAULTVENDOR);
389 my $descrdir = $self->{'handle'}->lookup_str($solv::SOLVID_META, $solv::SUSETAGS_DESCRDIR) || 'suse/setup/descr';
390 my $filechksum = $repodata->lookup_checksum($solv::SOLVID_META, $solv::SUSETAGS_FILE_CHECKSUM);
391 my $f = $self->download("$descrdir/$filename", 1, $filechksum);
393 $self->{'handle'}->add_susetags($f, $defvendorid, $ext, $solv::Repo::REPO_USE_LOADING|$solv::Repo::REPO_EXTEND_SOLVABLES);
395 $self->writecachedrepo($ext, $repodata);
399 sub load_if_changed {
401 print "susetags repo '$self->{'alias'}': ";
403 my $f = $self->download("content");
405 print "no content file, skipped\n";
406 $self->{'handle'}->free(1);
407 delete $self->{'handle'};
410 $self->{'cookie'} = $self->calc_cookie_fp($f);
411 if ($self->usecachedrepo(undef, 1)) {
416 $self->{'handle'}->add_content($f, 0);
419 my $defvendorid = $self->{'handle'}->lookup_id($solv::SOLVID_META, $solv::SUSETAGS_DEFAULTVENDOR);
420 my $descrdir = $self->{'handle'}->lookup_str($solv::SOLVID_META, $solv::SUSETAGS_DESCRDIR) || 'suse/setup/descr';
421 my ($filename, $filechksum) = $self->find('packages.gz');
422 ($filename, $filechksum) = $self->find('packages') unless $filename;
424 $f = $self->download("$descrdir/$filename", 1, $filechksum, 1);
426 $self->{'handle'}->add_susetags($f, $defvendorid, undef, $solv::Repo::REPO_NO_INTERNALIZE|$solv::Repo::SUSETAGS_RECORD_SHARES);
428 ($filename, $filechksum) = $self->find('packages.en.gz');
429 ($filename, $filechksum) = $self->find('packages.en') unless $filename;
431 $f = $self->download("$descrdir/$filename", 1, $filechksum, 1);
433 $self->{'handle'}->add_susetags($f, $defvendorid, undef, $solv::Repo::REPO_NO_INTERNALIZE|$solv::Repo::REPO_REUSE_REPODATA|$solv::Repo::REPO_EXTEND_SOLVABLES);
437 $self->{'handle'}->internalize();
441 $self->writecachedrepo() unless $self->{'incomplete'};
442 $self->{'handle'}->create_stubs();
446 package Repo::unknown;
448 our @ISA = ('Repo::generic');
451 my ($self, $pool) = @_;
452 print "unsupported repo '$self->{'alias'}': skipped\n";
456 package Repo::system;
458 our @ISA = ('Repo::generic');
461 my ($self, $pool) = @_;
463 $self->{'handle'} = $pool->add_repo($self->{'alias'});
464 $self->{'handle'}->{'appdata'} = $self;
465 $pool->{'installed'} = $self->{'handle'};
466 print "rpm database: ";
467 $self->{'cookie'} = $self->calc_cookie_file('/var/lib/rpm/Packages');
468 if ($self->usecachedrepo()) {
473 $self->{'handle'}->add_products("/etc/products.d", $solv::Repo::REPO_NO_INTERNALIZE);
474 $self->{'handle'}->add_rpmdb(undef, 0);
481 my ($pool, $arch) = @_;
482 return undef unless $arch;
483 my $id = $pool->str2id($arch, 0);
484 return $id && $pool->isknownarch($id) ? 1 : undef;
488 my ($pool, $name, $globname, $globdep) = @_;
489 my $id = $pool->str2id($name, 0);
492 for my $s ($pool->providers($id)) {
493 return $pool->Job($solv::Job::SOLVER_SOLVABLE_NAME, $id) if $globname && $s->{'nameid'} == $id;
497 print "[using capability match for '$name']\n" if $globname && $globdep;
498 my @j = $pool->Job($solv::Job::SOLVER_SOLVABLE_PROVIDES, $id);
499 return $pool->Job($solv::Job::SOLVER_SOLVABLE_PROVIDES, $id);
502 return unless $name =~ /[[*?]/;
505 for my $d (@{$pool->Dataiterator(0, $solv::SOLVABLE_NAME, $name, $solv::Dataiterator::SEARCH_GLOB)}) {
506 my $s = $d->{'solvable'};
507 $idmatches{$s->{'nameid'}} = 1 if $s->installable();
510 return map {$pool->Job($solv::Job::SOLVER_SOLVABLE_NAME, $_)} sort(keys %idmatches);
514 my @idmatches = $pool->matchprovidingids($name, $solv::Dataiterator::SEARCH_GLOB);
516 print "[using capability match for '$name']\n";
517 return map {$pool->Job($solv::Job::SOLVER_SOLVABLE_PROVIDES, $_)} sort(@idmatches);
524 my ($pool, $jobs, $flags, $evr) = @_;
527 my $how = $j->{'how'};
528 my $sel = $how & $solv::Job::SOLVER_SELECTMASK;
529 my $what = $pool->rel2id($j->{'what'}, $evr, $flags);
530 if ($flags == $solv::REL_ARCH) {
531 $how |= $solv::Job::SOLVER_SETARCH;
532 } elsif ($flags == $solv::REL_EQ && $sel == $solv::Job::SOLVER_SOLVABLE_NAME) {
533 $how |= $pool->id2str($evr) =~ /-/ ? $solv::Job::SOLVER_SETEVR : $solv::Job::SOLVER_SETEV;
535 push @jobs, $pool->Job($how, $what);
541 my ($pool, $jobs, $flags, $evrstr) = @_;
542 if ($evrstr =~ /^(.+)\.(.+?)$/ && validarch($pool, $2)) {
543 my $evr = $pool->str2id($1);
544 my @jobs = limitjobs($pool, $jobs, $solv::REL_ARCH, $pool->str2id($2));
545 return limitjobs($pool, \@jobs, $flags, $evr);
547 return limitjobs($pool, $jobs, $flags, $pool->str2id($evrstr));
551 my ($pool, $cmd, $name, $rel, $evr) = @_;
553 $flags |= $solv::REL_LT if $rel =~ /</;
554 $flags |= $solv::REL_EQ if $rel =~ /=/;
555 $flags |= $solv::REL_GT if $rel =~ />/;
556 my @jobs = depglob($pool, $name, 1, 1);
557 return limitjobs($pool, \@jobs, $flags, $pool->str2id($evr)) if @jobs;
558 if (($name =~ /^(.+)\.(.+?)$/s) && validarch($pool, $2)) {
560 @jobs = depglob($pool, $1, 1, 1);
562 @jobs = limitjobs($pool, \@jobs, $solv::REL_ARCH, $pool->str2id($arch));
563 return limitjobs($pool, \@jobs, $flags, $pool->str2id($evr));
570 my ($pool, $cmd, $arg) = @_;
571 my @jobs = depglob($pool, $arg, 1, 1);
572 return @jobs if @jobs;
573 if (($arg =~ /^(.+)\.(.+?)$/s) && validarch($pool, $2)) {
575 @jobs = depglob($pool, $1, 1, 1);
576 return limitjobs($pool, \@jobs, $solv::REL_ARCH, $pool->str2id($arch)) if @jobs;
578 if ($arg =~ /^(.+)-(.+?)$/s) {
580 @jobs = depglob($pool, $1, 1, 0);
581 return limitjobs_arch($pool, \@jobs, $solv::REL_EQ, $evr) if @jobs;
583 if ($arg =~ /^(.+)-(.+?-.+?)$/s) {
585 @jobs = depglob($pool, $1, 1, 0);
586 return limitjobs_arch($pool, \@jobs, $solv::REL_EQ, $evr) if @jobs;
591 sub mkjobs_filelist {
592 my ($pool, $cmd, $arg) = @_;
593 my $type = ($arg =~ /[[*?]/) ? $solv::Dataiterator::SEARCH_GLOB : $solv::Dataiterator::SEARCH_STRING;
594 $type |= $solv::Dataiterator::SEARCH_FILES | $solv::Dataiterator::SEARCH_COMPLETE_FILELIST;
596 if ($cmd eq 'erase') {
597 $di = $pool->{'installed'}->Dataiterator(0, $solv::SOLVABLE_FILELIST, $arg, $type);
599 $di = $pool->Dataiterator(0, $solv::SOLVABLE_FILELIST, $arg, $type);
603 my $s = $d->{'solvable'};
604 next unless $s && $s->installable();
605 push @matches, $s->{'id'};
606 $di->skip_solvable();
608 return () unless @matches;
609 print "[using file list match for '$arg']\n";
611 return $pool->Job($solv::Job::SOLVER_SOLVABLE_ONE_OF, $pool->towhatprovides(\@matches));
613 return $pool->Job($solv::Job::SOLVER_SOLVABLE | $solv::Job::SOLVER_NOAUTOSET, $matches[0]);
618 my ($pool, $cmd, $arg) = @_;
619 if ($arg && $arg =~ /^\//) {
620 my @jobs = mkjobs_filelist($pool, $cmd, $arg);
621 return @jobs if @jobs;
623 if ($arg =~ /^(.+?)\s*([<=>]+)\s*(.+?)$/s) {
624 return mkjobs_rel($pool, $cmd, $1, $2, $3);
626 return mkjobs_nevra($pool, $cmd, $arg);
632 my $repo = $repodata->{'repo'}->{'appdata'};
633 return $repo ? $repo->load_ext($repodata) : 0;
636 die("Usage: p5solv COMMAND [ARGS]\n") unless @ARGV;
637 my $cmd = shift @ARGV;
638 $cmd = 'list' if $cmd eq 'li';
639 $cmd = 'install' if $cmd eq 'in';
640 $cmd = 'erase' if $cmd eq 'rm';
641 $cmd = 'verify' if $cmd eq 've';
642 $cmd = 'search' if $cmd eq 'se';
644 my $pool = solv::Pool->new();
645 $pool->setarch((POSIX::uname())[4]);
646 $pool->set_loadcallback(\&load_stub);
648 for my $reposdir ('/etc/zypp/repos.d') {
649 next unless -d $reposdir;
650 next unless opendir(DIR, $reposdir);
651 for my $reponame (sort(grep {/\.repo$/} readdir(DIR))) {
652 my $cfg = new Config::IniFiles('-file' => "$reposdir/$reponame");
653 for my $alias ($cfg->Sections()) {
654 my $repoattr = {'alias' => $alias, 'enabled' => 0, 'priority' => 99, 'autorefresh' => 1, 'type' => 'rpm-md', 'metadata_expire' => 900};
655 for my $p ($cfg->Parameters($alias)) {
656 $repoattr->{$p} = $cfg->val($alias, $p);
659 if ($repoattr->{'type'} eq 'rpm-md') {
660 $repo = Repo::rpmmd->new($repoattr);
661 } elsif ($repoattr->{'type'} eq 'yast2') {
662 $repo = Repo::susetags->new($repoattr);
664 $repo = Repo::unknown->new($repoattr);
671 my $sysrepo = Repo::system->new({'alias' => '@System', 'type' => 'system'});
672 $sysrepo->load($pool);
673 for my $repo (@repos) {
674 $repo->load($pool) if $repo->{'enabled'};
677 if ($cmd eq 'search') {
679 my $di = $pool->Dataiterator(0, $solv::SOLVABLE_NAME, $ARGV[0], $solv::Dataiterator::SEARCH_SUBSTRING | $solv::Dataiterator::SEARCH_NOCASE);
681 $matches{$d->{'solvid'}} = 1;
683 for my $solvid (sort keys %matches) {
684 my $s = $pool->{'solvables'}->[$solvid];
685 print "- ".$s->str()." [$s->{'repo'}->{'name'}] ".$s->lookup_str($solv::SOLVABLE_SUMMARY)."\n";
690 my @addedprovides = $pool->addfileprovides_ids();
691 $pool->createwhatprovides();
694 for my $arg (@ARGV) {
695 my @njobs = mkjobs($pool, $cmd, $arg);
696 die("nothing matches '$arg'\n") unless @njobs;
700 if ($cmd eq 'list' || $cmd eq 'info') {
701 die("no package matched.\n") unless @jobs;
702 for my $job (@jobs) {
703 for my $s ($pool->jobsolvables($job)) {
704 if ($cmd eq 'info') {
705 printf "Name: %s\n", $s->str();
706 printf "Repo: %s\n", $s->{'repo'}->{'name'};
707 printf "Summary: %s\n", $s->lookup_str($solv::SOLVABLE_SUMMARY);
708 my $str = $s->lookup_str($solv::SOLVABLE_URL);
709 printf "Url: %s\n", $str if $str;
710 $str = $s->lookup_str($solv::SOLVABLE_LICENSE);
711 printf "License: %s\n", $str if $str;
712 printf "Description:\n%s\n", $s->lookup_str($solv::SOLVABLE_DESCRIPTION);
714 printf " - %s [%s]\n", $s->str(), $s->{'repo'}->{'name'};
715 printf " %s\n", $s->lookup_str($solv::SOLVABLE_SUMMARY);
722 if ($cmd eq 'install' || $cmd eq 'erase' || $cmd eq 'up' || $cmd eq 'dup' || $cmd eq 'verify') {
724 if ($cmd eq 'up' || $cmd eq 'verify') {
725 push @jobs, $pool->Job($solv::Job::SOLVER_SOLVABLE_ALL, 0);
726 } elsif ($cmd ne 'dup') {
727 die("no package matched.\n");
730 for my $job (@jobs) {
732 if ($job->{'how'} == $solv::Job::SOLVER_SOLVABLE_ALL || grep {$_->isinstalled()} $pool->jobsolvables($job)) {
733 $job->{'how'} |= $solv::Job::SOLVER_UPDATE;
735 $job->{'how'} |= $solv::Job::SOLVER_INSTALL;
737 } elsif ($cmd eq 'install') {
738 $job->{'how'} |= $solv::Job::SOLVER_INSTALL;
739 } elsif ($cmd eq 'erase') {
740 $job->{'how'} |= $solv::Job::SOLVER_ERASE;
741 } elsif ($cmd eq 'dup') {
742 $job->{'how'} |= $solv::Job::SOLVER_DISTUPGRADE;
743 } elsif ($cmd eq 'verify') {
744 $job->{'how'} |= $solv::Job::SOLVER_VERIFY;
749 $solver = $pool->create_solver();
750 $solver->{'ignorealreadyrecommended'} = 1;
751 $solver->{'allowuninstall'} = 1 if $cmd eq 'erase';
752 if ($cmd eq 'dup' && !@jobs) {
753 $solver->{'distupgrade'} = 1;
754 $solver->{'updatesystem'} = 1;
755 $solver->{'allowdowngrade'} = 1;
756 $solver->{'allowvendorchange'} = 1;
757 $solver->{'allowarchchange'} = 1;
758 $solver->{'dosplitprovides'} = 1;
759 } elsif ($cmd eq 'up' and @jobs == 1 and $jobs[0]->{'how'} == ($solv::Job::SOLVER_UPDATE | $solv::Job::SOLVER_SOLVABLE_ALL)) {
760 $solver->{'dosplitprovides'} = 1;
762 my @problems = $solver->solve(\@jobs);
763 last unless @problems;
764 for my $problem (@problems) {
765 print "Problem $problem->{'id'}/".@problems.":\n";
766 my $r = $problem->findproblemrule();
768 print $ri->problemstr()."\n";
769 my @solutions = $problem->solutions();
770 for my $solution (@solutions) {
771 print " Solution $solution->{'id'}:\n";
772 for my $element ($solution->elements()) {
773 my $etype = $element->{'type'};
774 if ($etype == $solv::Solver::SOLVER_SOLUTION_JOB) {
775 print " - do not ask to ".$jobs[$element->{'jobidx'}]->str()."\n";
776 } elsif ($etype == $solv::Solver::SOLVER_SOLUTION_INFARCH) {
777 if ($element->{'solvable'}->isinstalled()) {
778 print " - keep ".$element->{'solvable'}->str()." despite the inferior architecture\n";
780 print " - install ".$element->{'solvable'}->str()." despite the inferior architecture\n";
782 } elsif ($etype == $solv::Solver::SOLVER_SOLUTION_DISTUPGRADE) {
783 if ($element->{'solvable'}->isinstalled()) {
784 print " - keep obsolete ".$element->{'solvable'}->str()."\n";
786 print " - install ".$element->{'solvable'}->str()." from excluded repository\n";
788 } elsif ($etype == $solv::Solver::SOLVER_SOLUTION_REPLACE) {
789 print " - allow replacement of ".$element->{'solvable'}->str()." with ".$element->{'replacement'}->str()."\n";
790 } elsif ($etype == $solv::Solver::SOLVER_SOLUTION_ERASE) {
791 print " - allow deinstallation of ".$element->{'solvable'}->str()."\n";
793 print " - allow something else\n";
799 print "Please choose a solution: ";
802 last if $sol eq 's' || $sol eq 'q' || ($sol =~ /^\d+$/ && $sol >= 1 && $sol <= @solutions);
805 exit(1) if $sol eq 'q';
806 my $solution = $solutions[$sol - 1];
807 for my $element ($solution->elements()) {
808 my $etype = $element->{'type'};
809 if ($etype == $solv::Solver::SOLVER_SOLUTION_JOB) {
810 $jobs[$element->{'jobidx'}] = $pool->Job($solv::Job::SOLVER_NOOP, 0);
812 my $newjob = $element->Job();
813 push @jobs, $newjob if $newjob && !grep {$_->{'how'} == $newjob->{'how'} && $_->{'what'} == $newjob->{'what'}} @jobs;
818 my $trans = $solver->transaction();
820 if ($trans->isempty()) {
821 print "Nothing to do.\n";
824 print "\nTransaction summary:\n\n";
825 for my $c ($trans->classify()) {
826 my ($ctype, $pkgs, $fromid, $toid) = @$c;
827 if ($ctype == $solv::Transaction::SOLVER_TRANSACTION_ERASE) {
828 printf "%d erased packages:\n", scalar(@$pkgs);
829 } elsif ($ctype == $solv::Transaction::SOLVER_TRANSACTION_INSTALL) {
830 printf "%d installed packages:\n", scalar(@$pkgs);
831 } elsif ($ctype == $solv::Transaction::SOLVER_TRANSACTION_REINSTALLED) {
832 printf "%d reinstalled packages:\n", scalar(@$pkgs);
833 } elsif ($ctype == $solv::Transaction::SOLVER_TRANSACTION_DOWNGRADED) {
834 printf "%d downgraded packages:\n", scalar(@$pkgs);
835 } elsif ($ctype == $solv::Transaction::SOLVER_TRANSACTION_CHANGED) {
836 printf "%d changed packages:\n", scalar(@$pkgs);
837 } elsif ($ctype == $solv::Transaction::SOLVER_TRANSACTION_UPGRADED) {
838 printf "%d upgraded packages:\n", scalar(@$pkgs);
839 } elsif ($ctype == $solv::Transaction::SOLVER_TRANSACTION_VENDORCHANGE) {
840 printf "%d vendor changes from '%s' to '%s':\n", scalar(@$pkgs), $pool->id2str($fromid), $pool->id2str($toid);
841 } elsif ($ctype == $solv::Transaction::SOLVER_TRANSACTION_ARCHCHANGE) {
842 printf "%d arch changes from '%s' to '%s':\n", scalar(@$pkgs), $pool->id2str($fromid), $pool->id2str($toid);
847 if ($ctype == $solv::Transaction::SOLVER_TRANSACTION_UPGRADED || $ctype == $solv::Transaction::SOLVER_TRANSACTION_DOWNGRADED) {
848 my $other = $trans->othersolvable($p);
849 printf " - %s -> %s\n", $p->str(), $other->str();
851 printf " - %s\n", $p->str();
856 printf "install size change: %d K\n\n", $trans->calc_installsizechange();
858 print("OK to continue (y/n)? ");
862 exit(1) if $yn eq 'n';
864 my @newpkgs = $trans->newpackages();
867 my $downloadsize = 0;
868 $downloadsize += $_->lookup_num($solv::SOLVABLE_DOWNLOADSIZE) for @newpkgs;
869 printf "Downloading %d packages, %d K\n", scalar(@newpkgs), $downloadsize;
870 for my $p (@newpkgs) {
871 my $repo = $p->{'repo'}->{'appdata'};
872 my ($location, $medianr) = $p->lookup_location();
873 next unless $location;
874 if ($repo->{'type'} eq 'yast2') {
875 $location = ($repo->{'handle'}->lookup_str($solv::SOLVID_META, $solv::SUSETAGS_DATADIR) || 'suse') ."/$location";
877 my $chksum = $p->lookup_checksum($solv::SOLVABLE_CHECKSUM);
878 my $f = $repo->download($location, 0, $chksum);
879 die("\n$repo->{'alias'}: $location not found in repository\n") unless $f;
880 $newpkgsfps{$p->{'id'}} = $f;
886 print "Committing transaction:\n\n";
888 for my $p ($trans->steps()) {
889 my $steptype = $trans->steptype($p, $solv::Transaction::SOLVER_TRANSACTION_RPM_ONLY);
890 if ($steptype == $solv::Transaction::SOLVER_TRANSACTION_ERASE) {
891 print "erase ".$p->str()."\n";
892 next unless $p->lookup_num($solv::RPM_RPMDBID);
893 my $evr = $p->{'evr'};
894 $evr =~ s/^[0-9]+://; # strip epoch
895 system('rpm', '-e', '--nodeps', '--nodigest', '--nosignature', "$p->{'name'}-$evr.$p->{'arch'}") && die("rpm failed: $?\n");
896 } elsif ($steptype == $solv::Transaction::SOLVER_TRANSACTION_INSTALL || $steptype == $solv::Transaction::SOLVER_TRANSACTION_MULTIINSTALL) {
897 print "install ".$p->str()."\n";
898 my $f = $newpkgsfps{$p->{'id'}};
899 my $mode = $steptype == $solv::Transaction::SOLVER_TRANSACTION_INSTALL ? '-U' : '-i';
900 system('rpm', $mode, '--force', '--nodeps', '--nodigest', '--nosignature', "/dev/fd/".solv::xfileno($f)) && die("rpm failed: $?\n");
902 delete $newpkgsfps{$p->{'id'}};