13 package Repo::generic;
16 my ($class, $alias, $type, $attr) = @_;
17 my $r = { %{$attr || {}} };
18 $r->{'alias'} = $alias;
20 return bless $r, $class;
25 my $chksum = solv::Chksum->new($solv::REPOKEY_TYPE_SHA256);
27 return $chksum->raw();
30 sub calc_cookie_file {
31 my ($self, $filename) = @_;
32 my $chksum = solv::Chksum->new($solv::REPOKEY_TYPE_SHA256);
34 $chksum->add_stat($filename);
35 return $chksum->raw();
39 my ($self, $ext) = @_;
40 my $path = $self->{'alias'};
42 $path .= $ext ? "_$ext.solvx" : '.solv';
44 return "/var/cache/solv/$path";
48 my ($self, $pool) = @_;
49 $self->{'handle'} = $pool->add_repo($self->{'alias'});
50 $self->{'handle'}->{'appdata'} = $self;
51 $self->{'handle'}->{'priority'} = 99 - $self->{'priority'};
52 my $dorefresh = $self->{'autorefresh'};
54 my @s = stat($self->cachepath());
55 $dorefresh = 0 if @s && time() - $s[9] < $self->{'metadata_expire'};
57 $self->{'cookie'} = '';
58 if (!$dorefresh && $self->usecachedrepo()) {
59 print "repo: '$self->{'alias'}' cached\n";
62 return $self->load_if_changed();
74 my ($self, $file, $uncompress, $chksum, $markincomplete) = @_;
75 if (!$self->{'baseurl'}) {
76 print "$self->{'alias'}: no baseurl\n";
79 my $url = $self->{'baseurl'};
82 open(my $f, '+>', undef) || die;
83 fcntl($f, Fcntl::F_SETFD, 0);
84 my $st = system('curl', '-f', '-s', '-L', '-o', "/dev/fd/".fileno($f), '--', $url);
85 if (POSIX::lseek(fileno($f), 0, POSIX::SEEK_END) == 0 && ($st == 0 || !$chksum)) {
88 POSIX::lseek(fileno($f), 0, POSIX::SEEK_SET);
90 print "$file: download error #$st\n";
91 $self->{'incomplete'} = 1 if $markincomplete;
95 my $fchksum = solv::Chksum->new($chksum->{'type'});
96 $fchksum->add_fd(fileno($f));
97 if ($fchksum != $chksum) {
98 print "$file: checksum error\n";
99 $self->{'incomplete'} = 1 if $markincomplete;
104 return solv::xfopen_dup($file, fileno($f));
106 return solv::xfopen_dup(undef, fileno($f));
111 my ($self, $ext, $mark) = @_;
112 my $cookie = $ext ? $self->{'extcookie'} : $self->{'cookie'};
113 my $handle = $self->{'handle'};
114 my $cachepath = $self->cachepath($ext);
116 if (sysopen(my $f, $cachepath, POSIX::O_RDONLY)) {
117 sysseek($f, -32, Fcntl::SEEK_END);
119 return undef if sysread($f, $fcookie, 32) != 32;
120 return undef if $cookie && $fcookie ne $cookie;
121 if ($self->{'type'} ne 'system' && !$ext) {
122 sysseek($f, -32 * 2, Fcntl::SEEK_END);
123 return undef if sysread($f, $fextcookie, 32) != 32;
125 sysseek($f, 0, Fcntl::SEEK_SET);
126 my $fd = solv::xfopen_dup(undef, fileno($f));
127 my $flags = $ext ? $solv::Repo::REPO_USE_LOADING|$solv::Repo::REPO_EXTEND_SOLVABLES : 0;
128 $flags |= $solv::Repo::REPO_LOCALPOOL if $ext && $ext ne 'DL';
129 if (!$self->{'handle'}->add_solv($fd, $flags)) {
134 $self->{'cookie'} = $fcookie unless $ext;
135 $self->{'extcookie'} = $fextcookie if $fextcookie;
136 utime undef, undef, $f if $mark;
144 my $chksum = solv::Chksum->new($solv::REPOKEY_TYPE_SHA256);
145 $chksum->add($self->{'cookie'});
150 my $extcookie = $chksum->raw();
151 substr($extcookie, 0, 1) = chr(1) if ord(substr($extcookie, 0, 1)) == 0;
152 $self->{'extcookie'} = $extcookie;
155 sub writecachedrepo {
156 my ($self, $ext, $info) = @_;
157 mkdir("/var/cache/solv", 0755) unless -d "/var/cache/solv";
160 ($f, $tmpname) = File::Temp::tempfile(".newsolv-XXXXXX", 'DIR' => '/var/cache/solv');
164 my $ff = solv::xfopen_dup(undef, fileno($f));
166 $self->{'handle'}->write($ff);
170 $self->{'handle'}->write_first_repodata($ff);
173 if ($self->{'type'} ne 'system' && !$ext) {
174 $self->genextcookie($f) unless $self->{'extcookie'};
175 syswrite($f, $self->{'extcookie'});
177 syswrite($f, $ext ? $self->{'extcookie'} : $self->{'cookie'});
179 if ($self->{'handle'}->iscontiguous()) {
180 $f = solv::xfopen($tmpname);
183 $self->{'handle'}->empty();
184 die("internal error, cannot reload solv file\n") unless $self->{'handle'}->add_solv($f, $solv::Repo::SOLV_ADD_NO_STUBS);
186 $info->extend_to_repo();
187 $info->add_solv($f, $solv::Repo::REPO_EXTEND_SOLVABLES);
192 rename($tmpname, $self->cachepath($ext));
197 our @ISA = ('Repo::generic');
200 my ($self, $what) = @_;
201 my $di = $self->{'handle'}->Dataiterator($solv::SOLVID_META, $solv::REPOSITORY_REPOMD_TYPE, $what, $solv::Dataiterator::SEARCH_STRING);
202 $di->prepend_keyname($solv::REPOSITORY_REPOMD);
204 my $dp = $d->parentpos();
205 my $filename = $dp->lookup_str($solv::REPOSITORY_REPOMD_LOCATION);
206 next unless $filename;
207 my $chksum = $dp->lookup_checksum($solv::REPOSITORY_REPOMD_CHECKSUM);
209 print "no $filename file checksum!\n";
210 return (undef, undef);
212 return ($filename, $chksum);
214 return (undef, undef);
218 my ($self, $repodata, $what, $ext) = @_;
219 my ($filename, $chksum) = $self->find($what);
220 ($filename, $chksum) = $self->find('prestodelta') if !$filename && $what eq 'deltainfo';
221 return unless $filename;
222 my $handle = $repodata->new_handle();
223 $repodata->set_poolstr($handle, $solv::REPOSITORY_REPOMD_TYPE, $what);
224 $repodata->set_str($handle, $solv::REPOSITORY_REPOMD_LOCATION, $filename);
225 $repodata->set_checksum($handle, $solv::REPOSITORY_REPOMD_CHECKSUM, $chksum);
227 $repodata->add_idarray($handle, $solv::REPOSITORY_KEYS, $solv::REPOSITORY_DELTAINFO);
228 $repodata->add_idarray($handle, $solv::REPOSITORY_KEYS, $solv::REPOKEY_TYPE_FLEXARRAY);
229 } elsif ($ext eq 'FL') {
230 $repodata->add_idarray($handle, $solv::REPOSITORY_KEYS, $solv::SOLVABLE_FILELIST);
231 $repodata->add_idarray($handle, $solv::REPOSITORY_KEYS, $solv::REPOKEY_TYPE_DIRSTRARRAY);
233 $repodata->add_flexarray($solv::SOLVID_META, $solv::REPOSITORY_EXTERNAL, $handle);
238 my $repodata = $self->{'handle'}->add_repodata(0);
239 $self->add_ext($repodata, 'deltainfo', 'DL');
240 $self->add_ext($repodata, 'filelists', 'FL');
241 $repodata->internalize();
245 my ($self, $repodata) = @_;
246 my $repomdtype = $repodata->lookup_str($solv::SOLVID_META, $solv::REPOSITORY_REPOMD_TYPE);
248 if ($repomdtype eq 'filelists') {
250 } elsif ($repomdtype eq 'deltainfo') {
255 print("[$self->{'alias'}:$ext: ");
257 if ($self->usecachedrepo($ext)) {
262 my $filename = $repodata->lookup_str($solv::SOLVID_META, $solv::REPOSITORY_REPOMD_LOCATION);
263 my $filechksum = $repodata->lookup_checksum($solv::SOLVID_META, $solv::REPOSITORY_REPOMD_CHECKSUM);
264 my $f = $self->download($filename, 1, $filechksum);
267 $self->{'handle'}->add_rpmmd($f, 'FL', $solv::Repo::REPO_USE_LOADING|$solv::Repo::REPO_EXTEND_SOLVABLES);
268 } elsif ($ext eq 'FL') {
269 $self->{'handle'}->add_deltainfoxml($f, $solv::Repo::REPO_USE_LOADING);
272 $self->writecachedrepo($ext, $repodata);
276 sub load_if_changed {
278 print "rpmmd repo '$self->{'alias'}': ";
280 my $f = $self->download("repodata/repomd.xml");
282 print "no repomd.xml file, skipped\n";
283 $self->{'handle'}->free(1);
284 delete $self->{'handle'};
287 $self->{'cookie'} = $self->calc_cookie_fp($f);
288 if ($self->usecachedrepo(undef, 1)) {
293 $self->{'handle'}->add_repomdxml($f, 0);
296 my ($filename, $filechksum) = $self->find('primary');
298 $f = $self->download($filename, 1, $filechksum, 1);
300 $self->{'handle'}->add_rpmmd($f, undef, 0);
303 return undef if $self->{'incomplete'};
305 ($filename, $filechksum) = $self->find('updateinfo');
307 $f = $self->download($filename, 1, $filechksum, 1);
309 $self->{'handle'}->add_updateinfoxml($f, 0);
314 $self->writecachedrepo() unless $self->{'incomplete'};
315 $self->{'handle'}->create_stubs();
319 package Repo::susetags;
321 our @ISA = ('Repo::generic');
324 my ($self, $what) = @_;
326 my $di = $self->{'handle'}->Dataiterator($solv::SOLVID_META, $solv::SUSETAGS_FILE_NAME, $what, $solv::Dataiterator::SEARCH_STRING);
327 $di->prepend_keyname($solv::SUSETAGS_FILE);
329 my $dp = $d->parentpos();
330 my $chksum = $dp->lookup_checksum($solv::SUSETAGS_FILE_CHECKSUM);
331 return ($what, $chksum);
333 return (undef, undef);
337 $solv::SOLVABLE_SUMMARY => $solv::REPOKEY_TYPE_STR,
338 $solv::SOLVABLE_DESCRIPTION => $solv::REPOKEY_TYPE_STR,
339 $solv::SOLVABLE_EULA => $solv::REPOKEY_TYPE_STR,
340 $solv::SOLVABLE_MESSAGEINS => $solv::REPOKEY_TYPE_STR,
341 $solv::SOLVABLE_MESSAGEDEL => $solv::REPOKEY_TYPE_STR,
342 $solv::SOLVABLE_CATEGORY => $solv::REPOKEY_TYPE_ID,
346 my ($self, $repodata, $what, $ext) = @_;
347 my ($filename, $chksum) = $self->find($what);
348 my $handle = $repodata->new_handle();
349 $repodata->set_str($handle, $solv::SUSETAGS_FILE_NAME, $filename);
350 $repodata->set_checksum($handle, $solv::SUSETAGS_FILE_CHECKSUM, $chksum);
352 $repodata->add_idarray($handle, $solv::REPOSITORY_KEYS, $solv::REPOSITORY_DELTAINFO);
353 $repodata->add_idarray($handle, $solv::REPOSITORY_KEYS, $solv::REPOKEY_TYPE_FLEXARRAY);
354 } elsif ($ext eq 'DU') {
355 $repodata->add_idarray($handle, $solv::REPOSITORY_KEYS, $solv::SOLVABLE_DISKUSAGE);
356 $repodata->add_idarray($handle, $solv::REPOSITORY_KEYS, $solv::REPOKEY_TYPE_DIRNUMNUMARRAY);
357 } elsif ($ext eq 'FL') {
358 $repodata->add_idarray($handle, $solv::REPOSITORY_KEYS, $solv::SOLVABLE_FILELIST);
359 $repodata->add_idarray($handle, $solv::REPOSITORY_KEYS, $solv::REPOKEY_TYPE_DIRSTRARRAY);
361 for my $langid (sort {$a <=> $b} keys %langtags) {
362 $repodata->add_idarray($handle, $solv::REPOSITORY_KEYS, $self->{'handle'}->{'pool'}->id2langid($langid, $ext, 1));
363 $repodata->add_idarray($handle, $solv::REPOSITORY_KEYS, $langtags{$langid});
366 $repodata->add_flexarray($solv::SOLVID_META, $solv::REPOSITORY_EXTERNAL, $handle);
371 my $repodata = $self->{'handle'}->add_repodata(0);
372 my $di = $self->{'handle'}->Dataiterator($solv::SOLVID_META, $solv::SUSETAGS_FILE_NAME, undef, 0);
373 $di->prepend_keyname($solv::SUSETAGS_FILE);
375 my $filename = $d->str();
376 next unless $filename && $filename =~ /^packages\.(..)(?:\..*)$/;
377 next if $1 eq 'en' || $1 eq 'gz';
378 $self->add_ext($repodata, $filename, $1);
380 $repodata->internalize();
384 my ($self, $repodata) = @_;
385 my $filename = $repodata->lookup_str($solv::SOLVID_META, $solv::SUSETAGS_FILE_NAME);
386 my $ext = substr($filename, 9, 2);
387 print("[$self->{'alias'}:$ext: ");
389 if ($self->usecachedrepo($ext)) {
394 my $defvendorid = $self->{'handle'}->lookup_id($solv::SOLVID_META, $solv::SUSETAGS_DEFAULTVENDOR);
395 my $descrdir = $self->{'handle'}->lookup_str($solv::SOLVID_META, $solv::SUSETAGS_DESCRDIR) || 'suse/setup/descr';
396 my $filechksum = $repodata->lookup_checksum($solv::SOLVID_META, $solv::SUSETAGS_FILE_CHECKSUM);
397 my $f = $self->download("$descrdir/$filename", 1, $filechksum);
399 $self->{'handle'}->add_susetags($f, $defvendorid, $ext, $solv::Repo::REPO_USE_LOADING|$solv::Repo::REPO_EXTEND_SOLVABLES);
401 $self->writecachedrepo($ext, $repodata);
405 sub load_if_changed {
407 print "susetags repo '$self->{'alias'}': ";
409 my $f = $self->download("content");
411 print "no content file, skipped\n";
412 $self->{'handle'}->free(1);
413 delete $self->{'handle'};
416 $self->{'cookie'} = $self->calc_cookie_fp($f);
417 if ($self->usecachedrepo(undef, 1)) {
422 $self->{'handle'}->add_content($f, 0);
425 my $defvendorid = $self->{'handle'}->lookup_id($solv::SOLVID_META, $solv::SUSETAGS_DEFAULTVENDOR);
426 my $descrdir = $self->{'handle'}->lookup_str($solv::SOLVID_META, $solv::SUSETAGS_DESCRDIR) || 'suse/setup/descr';
427 my ($filename, $filechksum) = $self->find('packages.gz');
428 ($filename, $filechksum) = $self->find('packages') unless $filename;
430 $f = $self->download("$descrdir/$filename", 1, $filechksum, 1);
432 $self->{'handle'}->add_susetags($f, $defvendorid, undef, $solv::Repo::REPO_NO_INTERNALIZE|$solv::Repo::SUSETAGS_RECORD_SHARES);
434 ($filename, $filechksum) = $self->find('packages.en.gz');
435 ($filename, $filechksum) = $self->find('packages.en') unless $filename;
437 $f = $self->download("$descrdir/$filename", 1, $filechksum, 1);
439 $self->{'handle'}->add_susetags($f, $defvendorid, undef, $solv::Repo::REPO_NO_INTERNALIZE|$solv::Repo::REPO_REUSE_REPODATA|$solv::Repo::REPO_EXTEND_SOLVABLES);
443 $self->{'handle'}->internalize();
447 $self->writecachedrepo() unless $self->{'incomplete'};
448 $self->{'handle'}->create_stubs();
452 package Repo::unknown;
454 our @ISA = ('Repo::generic');
457 my ($self, $pool) = @_;
458 print "unsupported repo '$self->{'alias'}': skipped\n";
462 package Repo::system;
464 our @ISA = ('Repo::generic');
467 my ($self, $pool) = @_;
469 $self->{'handle'} = $pool->add_repo($self->{'alias'});
470 $self->{'handle'}->{'appdata'} = $self;
471 $pool->{'installed'} = $self->{'handle'};
472 print "rpm database: ";
473 $self->{'cookie'} = $self->calc_cookie_file('/var/lib/rpm/Packages');
474 if ($self->usecachedrepo()) {
479 $self->{'handle'}->add_products("/etc/products.d", $solv::Repo::REPO_NO_INTERNALIZE);
480 $self->{'handle'}->add_rpmdb(undef, $solv::Repo::REPO_REUSE_REPODATA);
481 $self->writecachedrepo();
488 my ($pool, $arch) = @_;
489 return undef unless $arch;
490 my $id = $pool->str2id($arch, 0);
491 return $id && $pool->isknownarch($id) ? 1 : undef;
495 my ($pool, $name, $globname, $globdep) = @_;
496 my $id = $pool->str2id($name, 0);
499 for my $s ($pool->whatprovides($id)) {
500 return $pool->Job($solv::Job::SOLVER_SOLVABLE_NAME, $id) if $globname && $s->{'nameid'} == $id;
504 print "[using capability match for '$name']\n" if $globname && $globdep;
505 return $pool->Job($solv::Job::SOLVER_SOLVABLE_PROVIDES, $id);
508 return unless $name =~ /[[*?]/;
511 for my $d (@{$pool->Dataiterator(0, $solv::SOLVABLE_NAME, $name, $solv::Dataiterator::SEARCH_GLOB)}) {
512 my $s = $d->{'solvable'};
513 $idmatches{$s->{'nameid'}} = 1 if $s->installable();
516 return map {$pool->Job($solv::Job::SOLVER_SOLVABLE_NAME, $_)} sort(keys %idmatches);
520 my @idmatches = $pool->matchprovidingids($name, $solv::Dataiterator::SEARCH_GLOB);
522 print "[using capability match for '$name']\n";
523 return map {$pool->Job($solv::Job::SOLVER_SOLVABLE_PROVIDES, $_)} sort(@idmatches);
530 my ($pool, $jobs, $flags, $evrstr) = @_;
532 my $evr = $pool->str2id($evrstr);
534 my $how = $j->{'how'};
535 my $sel = $how & $solv::Job::SOLVER_SELECTMASK;
536 my $what = $pool->rel2id($j->{'what'}, $evr, $flags);
537 if ($flags == $solv::REL_ARCH) {
538 $how |= $solv::Job::SOLVER_SETARCH;
539 } elsif ($flags == $solv::REL_EQ && $sel == $solv::Job::SOLVER_SOLVABLE_NAME) {
540 $how |= $evrstr =~ /-/ ? $solv::Job::SOLVER_SETEVR : $solv::Job::SOLVER_SETEV;
542 push @jobs, $pool->Job($how, $what);
547 sub limitjobs_evrarch {
548 my ($pool, $jobs, $flags, $evrstr) = @_;
549 if ($evrstr =~ /^(.+)\.(.+?)$/ && validarch($pool, $2)) {
551 $jobs = [ limitjobs($pool, $jobs, $solv::REL_ARCH, $2) ];
553 return limitjobs($pool, $jobs, $flags, $evrstr);
557 my ($pool, $cmd, $name, $rel, $evr) = @_;
559 $flags |= $solv::REL_LT if $rel =~ /</;
560 $flags |= $solv::REL_EQ if $rel =~ /=/;
561 $flags |= $solv::REL_GT if $rel =~ />/;
562 my @jobs = depglob($pool, $name, 1, 1);
563 return limitjobs($pool, \@jobs, $flags, $evr) if @jobs;
564 if (($name =~ /^(.+)\.(.+?)$/s) && validarch($pool, $2)) {
566 @jobs = depglob($pool, $1, 1, 1);
568 @jobs = limitjobs($pool, \@jobs, $solv::REL_ARCH, $arch);
569 return limitjobs($pool, \@jobs, $flags, $evr);
576 my ($pool, $cmd, $arg) = @_;
577 my @jobs = depglob($pool, $arg, 1, 1);
578 return @jobs if @jobs;
579 if (($arg =~ /^(.+)\.(.+?)$/s) && validarch($pool, $2)) {
581 @jobs = depglob($pool, $1, 1, 1);
582 return limitjobs($pool, \@jobs, $solv::REL_ARCH, $arch) if @jobs;
584 if ($arg =~ /^(.+)-(.+?)$/s) {
586 @jobs = depglob($pool, $1, 1, 0);
587 return limitjobs_evrarch($pool, \@jobs, $solv::REL_EQ, $evr) if @jobs;
589 if ($arg =~ /^(.+)-(.+?-.+?)$/s) {
591 @jobs = depglob($pool, $1, 1, 0);
592 return limitjobs_evrarch($pool, \@jobs, $solv::REL_EQ, $evr) if @jobs;
597 sub mkjobs_filelist {
598 my ($pool, $cmd, $arg) = @_;
599 my $type = ($arg =~ /[[*?]/) ? $solv::Dataiterator::SEARCH_GLOB : $solv::Dataiterator::SEARCH_STRING;
600 $type |= $solv::Dataiterator::SEARCH_FILES | $solv::Dataiterator::SEARCH_COMPLETE_FILELIST;
602 if ($cmd eq 'erase') {
603 $di = $pool->{'installed'}->Dataiterator(0, $solv::SOLVABLE_FILELIST, $arg, $type);
605 $di = $pool->Dataiterator(0, $solv::SOLVABLE_FILELIST, $arg, $type);
609 my $s = $d->{'solvable'};
610 next unless $s && $s->installable();
611 push @matches, $s->{'id'};
612 $di->skip_solvable();
614 return () unless @matches;
615 print "[using file list match for '$arg']\n";
617 return $pool->Job($solv::Job::SOLVER_SOLVABLE_ONE_OF, $pool->towhatprovides(\@matches));
619 return $pool->Job($solv::Job::SOLVER_SOLVABLE | $solv::Job::SOLVER_NOAUTOSET, $matches[0]);
624 my ($pool, $cmd, $arg) = @_;
625 if ($arg && $arg =~ /^\//) {
626 my @jobs = mkjobs_filelist($pool, $cmd, $arg);
627 return @jobs if @jobs;
629 if ($arg =~ /^(.+?)\s*([<=>]+)\s*(.+?)$/s) {
630 return mkjobs_rel($pool, $cmd, $1, $2, $3);
632 return mkjobs_nevra($pool, $cmd, $arg);
638 my $repo = $repodata->{'repo'}->{'appdata'};
639 return $repo ? $repo->load_ext($repodata) : 0;
642 die("Usage: p5solv COMMAND [ARGS]\n") unless @ARGV;
643 my $cmd = shift @ARGV;
644 $cmd = 'list' if $cmd eq 'li';
645 $cmd = 'install' if $cmd eq 'in';
646 $cmd = 'erase' if $cmd eq 'rm';
647 $cmd = 'verify' if $cmd eq 've';
648 $cmd = 'search' if $cmd eq 'se';
651 for my $reposdir ('/etc/zypp/repos.d') {
652 next unless -d $reposdir;
653 next unless opendir(DIR, $reposdir);
654 for my $reponame (sort(grep {/\.repo$/} readdir(DIR))) {
655 my $cfg = new Config::IniFiles('-file' => "$reposdir/$reponame");
656 for my $alias ($cfg->Sections()) {
657 my $repoattr = {'alias' => $alias, 'enabled' => 0, 'priority' => 99, 'autorefresh' => 1, 'type' => 'rpm-md', 'metadata_expire' => 900};
658 for my $p ($cfg->Parameters($alias)) {
659 $repoattr->{$p} = $cfg->val($alias, $p);
662 if ($repoattr->{'type'} eq 'rpm-md') {
663 $repo = Repo::rpmmd->new($alias, 'repomd', $repoattr);
664 } elsif ($repoattr->{'type'} eq 'yast2') {
665 $repo = Repo::susetags->new($alias, 'susetags', $repoattr);
667 $repo = Repo::unknown->new($alias, 'unknown', $repoattr);
674 my $pool = solv::Pool->new();
675 $pool->setarch((POSIX::uname())[4]);
676 $pool->set_loadcallback(\&load_stub);
678 my $sysrepo = Repo::system->new('@System', 'system');
679 $sysrepo->load($pool);
680 for my $repo (@repos) {
681 $repo->load($pool) if $repo->{'enabled'};
684 if ($cmd eq 'search') {
686 my $di = $pool->Dataiterator(0, $solv::SOLVABLE_NAME, $ARGV[0], $solv::Dataiterator::SEARCH_SUBSTRING | $solv::Dataiterator::SEARCH_NOCASE);
688 $matches{$d->{'solvid'}} = 1;
690 for my $solvid (sort keys %matches) {
691 my $s = $pool->{'solvables'}->[$solvid];
692 print "- ".$s->str()." [$s->{'repo'}->{'name'}] ".$s->lookup_str($solv::SOLVABLE_SUMMARY)."\n";
697 my @addedprovides = $pool->addfileprovides_ids();
698 $pool->createwhatprovides();
701 for my $arg (@ARGV) {
702 my @njobs = mkjobs($pool, $cmd, $arg);
703 die("nothing matches '$arg'\n") unless @njobs;
707 if ($cmd eq 'list' || $cmd eq 'info') {
708 die("no package matched.\n") unless @jobs;
709 for my $job (@jobs) {
710 for my $s ($job->solvables()) {
711 if ($cmd eq 'info') {
712 printf "Name: %s\n", $s->str();
713 printf "Repo: %s\n", $s->{'repo'}->{'name'};
714 printf "Summary: %s\n", $s->lookup_str($solv::SOLVABLE_SUMMARY);
715 my $str = $s->lookup_str($solv::SOLVABLE_URL);
716 printf "Url: %s\n", $str if $str;
717 $str = $s->lookup_str($solv::SOLVABLE_LICENSE);
718 printf "License: %s\n", $str if $str;
719 printf "Description:\n%s\n", $s->lookup_str($solv::SOLVABLE_DESCRIPTION);
721 printf " - %s [%s]\n", $s->str(), $s->{'repo'}->{'name'};
722 printf " %s\n", $s->lookup_str($solv::SOLVABLE_SUMMARY);
729 if ($cmd eq 'install' || $cmd eq 'erase' || $cmd eq 'up' || $cmd eq 'dup' || $cmd eq 'verify') {
731 if ($cmd eq 'up' || $cmd eq 'verify' || $cmd eq 'dup') {
732 push @jobs, $pool->Job($solv::Job::SOLVER_SOLVABLE_ALL, 0);
734 die("no package matched.\n");
737 for my $job (@jobs) {
739 if ($job->{'how'} == $solv::Job::SOLVER_SOLVABLE_ALL || grep {$_->isinstalled()} $job->solvables()) {
740 $job->{'how'} |= $solv::Job::SOLVER_UPDATE;
742 $job->{'how'} |= $solv::Job::SOLVER_INSTALL;
744 } elsif ($cmd eq 'install') {
745 $job->{'how'} |= $solv::Job::SOLVER_INSTALL;
746 } elsif ($cmd eq 'erase') {
747 $job->{'how'} |= $solv::Job::SOLVER_ERASE;
748 } elsif ($cmd eq 'dup') {
749 $job->{'how'} |= $solv::Job::SOLVER_DISTUPGRADE;
750 } elsif ($cmd eq 'verify') {
751 $job->{'how'} |= $solv::Job::SOLVER_VERIFY;
756 $solver = $pool->Solver();
757 $solver->set_flag($solv::Solver::SOLVER_FLAG_IGNORE_ALREADY_RECOMMENDED, 1);
758 $solver->set_flag($solv::Solver::SOLVER_FLAG_SPLITPROVIDES, 1);
759 $solver->set_flag($solv::Solver::SOLVER_FLAG_ALLOW_UNINSTALL, 1) if $cmd eq 'erase';
760 my @problems = $solver->solve(\@jobs);
761 last unless @problems;
762 for my $problem (@problems) {
763 print "Problem $problem->{'id'}/".@problems.":\n";
764 my $r = $problem->findproblemrule();
766 print $ri->problemstr()."\n";
767 my @solutions = $problem->solutions();
768 for my $solution (@solutions) {
769 print " Solution $solution->{'id'}:\n";
770 for my $element ($solution->elements(1)) {
771 print " - ".$element->str()."\n";
777 print "Please choose a solution: ";
780 last if $sol eq 's' || $sol eq 'q' || ($sol =~ /^\d+$/ && $sol >= 1 && $sol <= @solutions);
783 exit(1) if $sol eq 'q';
784 my $solution = $solutions[$sol - 1];
785 for my $element ($solution->elements()) {
786 my $newjob = $element->Job();
787 if ($element->{'type'} == $solv::Solver::SOLVER_SOLUTION_JOB) {
788 $jobs[$element->{'jobidx'}] = $newjob;
790 push @jobs, $newjob if $newjob && !grep {$_ == $newjob} @jobs;
795 my $trans = $solver->transaction();
797 if ($trans->isempty()) {
798 print "Nothing to do.\n";
801 print "\nTransaction summary:\n\n";
802 for my $c ($trans->classify()) {
803 if ($c->{'type'} == $solv::Transaction::SOLVER_TRANSACTION_ERASE) {
804 print "$c->{'count'} erased packages:\n";
805 } elsif ($c->{'type'} == $solv::Transaction::SOLVER_TRANSACTION_INSTALL) {
806 print "$c->{'count'} installed packages:\n";
807 } elsif ($c->{'type'} == $solv::Transaction::SOLVER_TRANSACTION_REINSTALLED) {
808 print "$c->{'count'} reinstalled packages:\n";
809 } elsif ($c->{'type'} == $solv::Transaction::SOLVER_TRANSACTION_DOWNGRADED) {
810 print "$c->{'count'} downgraded packages:\n";
811 } elsif ($c->{'type'} == $solv::Transaction::SOLVER_TRANSACTION_CHANGED) {
812 print "$c->{'count'} changed packages:\n";
813 } elsif ($c->{'type'} == $solv::Transaction::SOLVER_TRANSACTION_UPGRADED) {
814 print "$c->{'count'} upgraded packages:\n";
815 } elsif ($c->{'type'} == $solv::Transaction::SOLVER_TRANSACTION_VENDORCHANGE) {
816 printf "$c->{'count'} vendor changes from '%s' to '%s':\n", $pool->id2str($c->{'fromid'}), $pool->id2str($c->{'toid'});
817 } elsif ($c->{'type'} == $solv::Transaction::SOLVER_TRANSACTION_ARCHCHANGE) {
818 printf "$c->{'count'} arch changes from '%s' to '%s':\n", $pool->id2str($c->{'fromid'}), $pool->id2str($c->{'toid'});
822 for my $p ($c->solvables()) {
823 if ($c->{'type'} == $solv::Transaction::SOLVER_TRANSACTION_UPGRADED || $c->{'type'} == $solv::Transaction::SOLVER_TRANSACTION_DOWNGRADED) {
824 my $other = $trans->othersolvable($p);
825 printf " - %s -> %s\n", $p->str(), $other->str();
827 printf " - %s\n", $p->str();
832 printf "install size change: %d K\n\n", $trans->calc_installsizechange();
834 print("OK to continue (y/n)? ");
838 exit(1) if $yn eq 'n';
840 my @newpkgs = $trans->newpackages();
843 my $downloadsize = 0;
844 $downloadsize += $_->lookup_num($solv::SOLVABLE_DOWNLOADSIZE) for @newpkgs;
845 printf "Downloading %d packages, %d K\n", scalar(@newpkgs), $downloadsize;
846 for my $p (@newpkgs) {
847 my $repo = $p->{'repo'}->{'appdata'};
848 my ($location, $medianr) = $p->lookup_location();
849 next unless $location;
850 if ($repo->{'type'} eq 'susetags') {
851 $location = ($repo->{'handle'}->lookup_str($solv::SOLVID_META, $solv::SUSETAGS_DATADIR) || 'suse') ."/$location";
853 my $chksum = $p->lookup_checksum($solv::SOLVABLE_CHECKSUM);
854 my $f = $repo->download($location, 0, $chksum);
855 die("\n$repo->{'alias'}: $location not found in repository\n") unless $f;
856 $newpkgsfps{$p->{'id'}} = $f;
862 print "Committing transaction:\n\n";
864 for my $p ($trans->steps()) {
865 my $steptype = $trans->steptype($p, $solv::Transaction::SOLVER_TRANSACTION_RPM_ONLY);
866 if ($steptype == $solv::Transaction::SOLVER_TRANSACTION_ERASE) {
867 print "erase ".$p->str()."\n";
868 next unless $p->lookup_num($solv::RPM_RPMDBID);
869 my $evr = $p->{'evr'};
870 $evr =~ s/^[0-9]+://; # strip epoch
871 system('rpm', '-e', '--nodeps', '--nodigest', '--nosignature', "$p->{'name'}-$evr.$p->{'arch'}") && die("rpm failed: $?\n");
872 } elsif ($steptype == $solv::Transaction::SOLVER_TRANSACTION_INSTALL || $steptype == $solv::Transaction::SOLVER_TRANSACTION_MULTIINSTALL) {
873 print "install ".$p->str()."\n";
874 my $f = $newpkgsfps{$p->{'id'}};
875 my $mode = $steptype == $solv::Transaction::SOLVER_TRANSACTION_INSTALL ? '-U' : '-i';
876 system('rpm', $mode, '--force', '--nodeps', '--nodigest', '--nosignature', "/dev/fd/".solv::xfileno($f)) && die("rpm failed: $?\n");
878 delete $newpkgsfps{$p->{'id'}};