14 package Repo::generic;
17 my ($class, $alias, $type, $attr) = @_;
18 my $r = { %{$attr || {}} };
19 $r->{'alias'} = $alias;
21 return bless $r, $class;
26 my $chksum = solv::Chksum->new($solv::REPOKEY_TYPE_SHA256);
28 return $chksum->raw();
31 sub calc_cookie_file {
32 my ($self, $filename) = @_;
33 my $chksum = solv::Chksum->new($solv::REPOKEY_TYPE_SHA256);
35 $chksum->add_stat($filename);
36 return $chksum->raw();
40 my ($self, $ext) = @_;
41 my $path = $self->{'alias'};
43 $path .= $ext ? "_$ext.solvx" : '.solv';
45 return "/var/cache/solv/$path";
49 my ($self, $pool) = @_;
50 $self->{'handle'} = $pool->add_repo($self->{'alias'});
51 $self->{'handle'}->{'appdata'} = $self;
52 $self->{'handle'}->{'priority'} = 99 - $self->{'priority'};
53 my $dorefresh = $self->{'autorefresh'};
55 my @s = stat($self->cachepath());
56 $dorefresh = 0 if @s && time() - $s[9] < $self->{'metadata_expire'};
58 $self->{'cookie'} = '';
59 if (!$dorefresh && $self->usecachedrepo()) {
60 print "repo: '$self->{'alias'}' cached\n";
63 return $self->load_if_changed();
75 my ($self, $file, $uncompress, $chksum, $markincomplete) = @_;
76 if (!$self->{'baseurl'}) {
77 print "$self->{'alias'}: no baseurl\n";
80 my $url = $self->{'baseurl'};
83 open(my $f, '+>', undef) || die;
84 fcntl($f, Fcntl::F_SETFD, 0);
85 my $st = system('curl', '-f', '-s', '-L', '-o', "/dev/fd/".fileno($f), '--', $url);
86 if (POSIX::lseek(fileno($f), 0, POSIX::SEEK_END) == 0 && ($st == 0 || !$chksum)) {
89 POSIX::lseek(fileno($f), 0, POSIX::SEEK_SET);
91 print "$file: download error #$st\n";
92 $self->{'incomplete'} = 1 if $markincomplete;
96 my $fchksum = solv::Chksum->new($chksum->{'type'});
97 $fchksum->add_fd(fileno($f));
98 if ($fchksum != $chksum) {
99 print "$file: checksum error\n";
100 $self->{'incomplete'} = 1 if $markincomplete;
105 return solv::xfopen_dup($file, fileno($f));
107 return solv::xfopen_dup(undef, fileno($f));
112 my ($self, $ext, $mark) = @_;
113 my $cookie = $ext ? $self->{'extcookie'} : $self->{'cookie'};
114 my $handle = $self->{'handle'};
115 my $cachepath = $self->cachepath($ext);
117 if (sysopen(my $f, $cachepath, POSIX::O_RDONLY)) {
118 sysseek($f, -32, Fcntl::SEEK_END);
120 return undef if sysread($f, $fcookie, 32) != 32;
121 return undef if $cookie && $fcookie ne $cookie;
122 if ($self->{'type'} ne 'system' && !$ext) {
123 sysseek($f, -32 * 2, Fcntl::SEEK_END);
124 return undef if sysread($f, $fextcookie, 32) != 32;
126 sysseek($f, 0, Fcntl::SEEK_SET);
127 $f = solv::xfopen_dup(undef, fileno($f));
128 my $flags = $ext ? $solv::Repo::REPO_USE_LOADING|$solv::Repo::REPO_EXTEND_SOLVABLES : 0;
129 $flags |= $solv::Repo::REPO_LOCALPOOL if $ext && $ext ne 'DL';
130 if (!$self->{'handle'}->add_solv($f, $flags)) {
135 $self->{'cookie'} = $fcookie unless $ext;
136 $self->{'extcookie'} = $fextcookie if $fextcookie;
137 utime undef, undef, $f if $mark;
145 my $chksum = solv::Chksum->new($solv::REPOKEY_TYPE_SHA256);
146 $chksum->add($self->{'cookie'});
151 my $extcookie = $chksum->raw();
152 substr($extcookie, 0, 1) = chr(1) if ord(substr($extcookie, 0, 1)) == 0;
153 $self->{'extcookie'} = $extcookie;
156 sub writecachedrepo {
157 my ($self, $ext, $info) = @_;
158 mkdir("/var/cache/solv", 0755) unless -d "/var/cache/solv";
161 ($f, $tmpname) = File::Temp::tempfile(".newsolv-XXXXXX", 'DIR' => '/var/cache/solv');
165 my $ff = solv::xfopen_dup(undef, fileno($f));
167 $self->{'handle'}->write($ff);
171 $self->{'handle'}->write_first_repodata($ff);
174 if ($self->{'type'} ne 'system' && !$ext) {
175 $self->genextcookie($f) unless $self->{'extcookie'};
176 syswrite($f, $self->{'extcookie'});
178 syswrite($f, $ext ? $self->{'extcookie'} : $self->{'cookie'});
180 if ($self->{'handle'}->iscontiguous()) {
181 $f = solv::xfopen($tmpname);
184 $self->{'handle'}->empty();
185 die("internal error, cannot reload solv file\n") unless $self->{'handle'}->add_solv($f, $solv::Repo::SOLV_ADD_NO_STUBS);
187 $info->extend_to_repo();
188 $info->add_solv($f, $solv::Repo::REPO_EXTEND_SOLVABLES);
193 rename($tmpname, $self->cachepath($ext));
198 our @ISA = ('Repo::generic');
201 my ($self, $what) = @_;
202 my $di = $self->{'handle'}->Dataiterator($solv::SOLVID_META, $solv::REPOSITORY_REPOMD_TYPE, $what, $solv::Dataiterator::SEARCH_STRING);
203 $di->prepend_keyname($solv::REPOSITORY_REPOMD);
206 my $filename = $d->{'pool'}->lookup_str($solv::SOLVID_POS, $solv::REPOSITORY_REPOMD_LOCATION);
207 next unless $filename;
208 my $chksum = $d->{'pool'}->lookup_checksum($solv::SOLVID_POS, $solv::REPOSITORY_REPOMD_CHECKSUM);
210 print "no $filename file checksum!\n";
211 return (undef, undef);
213 return ($filename, $chksum);
215 return (undef, undef);
219 my ($self, $repodata, $what, $ext) = @_;
220 my ($filename, $chksum) = $self->find($what);
221 ($filename, $chksum) = $self->find('prestodelta') if !$filename && $what eq 'deltainfo';
222 return unless $filename;
223 my $handle = $repodata->new_handle();
224 $repodata->set_poolstr($handle, $solv::REPOSITORY_REPOMD_TYPE, $what);
225 $repodata->set_str($handle, $solv::REPOSITORY_REPOMD_LOCATION, $filename);
226 $repodata->set_checksum($handle, $solv::REPOSITORY_REPOMD_CHECKSUM, $chksum);
228 $repodata->add_idarray($handle, $solv::REPOSITORY_KEYS, $solv::REPOSITORY_DELTAINFO);
229 $repodata->add_idarray($handle, $solv::REPOSITORY_KEYS, $solv::REPOKEY_TYPE_FLEXARRAY);
230 } elsif ($ext eq 'FL') {
231 $repodata->add_idarray($handle, $solv::REPOSITORY_KEYS, $solv::SOLVABLE_FILELIST);
232 $repodata->add_idarray($handle, $solv::REPOSITORY_KEYS, $solv::REPOKEY_TYPE_DIRSTRARRAY);
234 $repodata->add_flexarray($solv::SOLVID_META, $solv::REPOSITORY_EXTERNAL, $handle);
239 my $repodata = $self->{'handle'}->add_repodata(0);
240 $self->add_ext($repodata, 'deltainfo', 'DL');
241 $self->add_ext($repodata, 'filelists', 'FL');
242 $repodata->internalize();
246 my ($self, $repodata) = @_;
247 my $repomdtype = $repodata->lookup_str($solv::SOLVID_META, $solv::REPOSITORY_REPOMD_TYPE);
249 if ($repomdtype eq 'filelists') {
251 } elsif ($repomdtype eq 'deltainfo') {
256 print("[$self->{'alias'}:$ext: ");
258 if ($self->usecachedrepo($ext)) {
263 my $filename = $repodata->lookup_str($solv::SOLVID_META, $solv::REPOSITORY_REPOMD_LOCATION);
264 my $filechksum = $repodata->lookup_checksum($solv::SOLVID_META, $solv::REPOSITORY_REPOMD_CHECKSUM);
265 my $f = $self->download($filename, 1, $filechksum);
268 $self->{'handle'}->add_rpmmd($f, 'FL', $solv::Repo::REPO_USE_LOADING|$solv::Repo::REPO_EXTEND_SOLVABLES);
269 } elsif ($ext eq 'FL') {
270 $self->{'handle'}->add_deltainfoxml($f, $solv::Repo::REPO_USE_LOADING);
273 $self->writecachedrepo($ext, $repodata);
277 sub load_if_changed {
279 print "rpmmd repo '$self->{'alias'}': ";
281 my $f = $self->download("repodata/repomd.xml");
283 print "no repomd.xml file, skipped\n";
284 $self->{'handle'}->free(1);
285 delete $self->{'handle'};
288 $self->{'cookie'} = $self->calc_cookie_fp($f);
289 if ($self->usecachedrepo(undef, 1)) {
294 $self->{'handle'}->add_repomdxml($f, 0);
297 my ($filename, $filechksum) = $self->find('primary');
299 $f = $self->download($filename, 1, $filechksum, 1);
301 $self->{'handle'}->add_rpmmd($f, undef, 0);
304 return undef if $self->{'incomplete'};
306 ($filename, $filechksum) = $self->find('updateinfo');
308 $f = $self->download($filename, 1, $filechksum, 1);
310 $self->{'handle'}->add_updateinfoxml($f, 0);
315 $self->writecachedrepo() unless $self->{'incomplete'};
316 $self->{'handle'}->create_stubs();
320 package Repo::susetags;
322 our @ISA = ('Repo::generic');
325 my ($self, $what) = @_;
327 my $di = $self->{'handle'}->Dataiterator($solv::SOLVID_META, $solv::SUSETAGS_FILE_NAME, $what, $solv::Dataiterator::SEARCH_STRING);
328 $di->prepend_keyname($solv::SUSETAGS_FILE);
331 my $chksum = $d->{'pool'}->lookup_checksum($solv::SOLVID_POS, $solv::SUSETAGS_FILE_CHECKSUM);
332 return ($what, $chksum);
334 return (undef, undef);
338 $solv::SOLVABLE_SUMMARY => $solv::REPOKEY_TYPE_STR,
339 $solv::SOLVABLE_DESCRIPTION => $solv::REPOKEY_TYPE_STR,
340 $solv::SOLVABLE_EULA => $solv::REPOKEY_TYPE_STR,
341 $solv::SOLVABLE_MESSAGEINS => $solv::REPOKEY_TYPE_STR,
342 $solv::SOLVABLE_MESSAGEDEL => $solv::REPOKEY_TYPE_STR,
343 $solv::SOLVABLE_CATEGORY => $solv::REPOKEY_TYPE_ID,
347 my ($self, $repodata, $what, $ext) = @_;
348 my ($filename, $chksum) = $self->find($what);
349 my $handle = $repodata->new_handle();
350 $repodata->set_str($handle, $solv::SUSETAGS_FILE_NAME, $filename);
351 $repodata->set_checksum($handle, $solv::SUSETAGS_FILE_CHECKSUM, $chksum);
353 $repodata->add_idarray($handle, $solv::REPOSITORY_KEYS, $solv::REPOSITORY_DELTAINFO);
354 $repodata->add_idarray($handle, $solv::REPOSITORY_KEYS, $solv::REPOKEY_TYPE_FLEXARRAY);
355 } elsif ($ext eq 'DU') {
356 $repodata->add_idarray($handle, $solv::REPOSITORY_KEYS, $solv::SOLVABLE_DISKUSAGE);
357 $repodata->add_idarray($handle, $solv::REPOSITORY_KEYS, $solv::REPOKEY_TYPE_DIRNUMNUMARRAY);
358 } elsif ($ext eq 'FL') {
359 $repodata->add_idarray($handle, $solv::REPOSITORY_KEYS, $solv::SOLVABLE_FILELIST);
360 $repodata->add_idarray($handle, $solv::REPOSITORY_KEYS, $solv::REPOKEY_TYPE_DIRSTRARRAY);
362 for my $langid (sort {$a <=> $b} keys %langtags) {
363 $repodata->add_idarray($handle, $solv::REPOSITORY_KEYS, $self->{'handle'}->{'pool'}->id2langid($langid, $ext, 1));
364 $repodata->add_idarray($handle, $solv::REPOSITORY_KEYS, $langtags{$langid});
367 $repodata->add_flexarray($solv::SOLVID_META, $solv::REPOSITORY_EXTERNAL, $handle);
372 my $repodata = $self->{'handle'}->add_repodata(0);
373 my $di = $self->{'handle'}->Dataiterator($solv::SOLVID_META, $solv::SUSETAGS_FILE_NAME, undef, 0);
374 $di->prepend_keyname($solv::SUSETAGS_FILE);
376 my $filename = $d->str();
377 next unless $filename && $filename =~ /^packages\.(..)(?:\..*)$/;
378 next if $1 eq 'en' || $1 eq 'gz';
379 $self->add_ext($repodata, $filename, $1);
381 $repodata->internalize();
385 my ($self, $repodata) = @_;
386 my $filename = $repodata->lookup_str($solv::SOLVID_META, $solv::SUSETAGS_FILE_NAME);
387 my $ext = substr($filename, 9, 2);
388 print("[$self->{'alias'}:$ext: ");
390 if ($self->usecachedrepo($ext)) {
395 my $defvendorid = $self->{'handle'}->lookup_id($solv::SOLVID_META, $solv::SUSETAGS_DEFAULTVENDOR);
396 my $descrdir = $self->{'handle'}->lookup_str($solv::SOLVID_META, $solv::SUSETAGS_DESCRDIR) || 'suse/setup/descr';
397 my $filechksum = $repodata->lookup_checksum($solv::SOLVID_META, $solv::SUSETAGS_FILE_CHECKSUM);
398 my $f = $self->download("$descrdir/$filename", 1, $filechksum);
400 $self->{'handle'}->add_susetags($f, $defvendorid, $ext, $solv::Repo::REPO_USE_LOADING|$solv::Repo::REPO_EXTEND_SOLVABLES);
402 $self->writecachedrepo($ext, $repodata);
406 sub load_if_changed {
408 print "susetags repo '$self->{'alias'}': ";
410 my $f = $self->download("content");
412 print "no content file, skipped\n";
413 $self->{'handle'}->free(1);
414 delete $self->{'handle'};
417 $self->{'cookie'} = $self->calc_cookie_fp($f);
418 if ($self->usecachedrepo(undef, 1)) {
423 $self->{'handle'}->add_content($f, 0);
426 my $defvendorid = $self->{'handle'}->lookup_id($solv::SOLVID_META, $solv::SUSETAGS_DEFAULTVENDOR);
427 my $descrdir = $self->{'handle'}->lookup_str($solv::SOLVID_META, $solv::SUSETAGS_DESCRDIR) || 'suse/setup/descr';
428 my ($filename, $filechksum) = $self->find('packages.gz');
429 ($filename, $filechksum) = $self->find('packages') 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::SUSETAGS_RECORD_SHARES);
435 ($filename, $filechksum) = $self->find('packages.en.gz');
436 ($filename, $filechksum) = $self->find('packages.en') unless $filename;
438 $f = $self->download("$descrdir/$filename", 1, $filechksum, 1);
440 $self->{'handle'}->add_susetags($f, $defvendorid, undef, $solv::Repo::REPO_NO_INTERNALIZE|$solv::Repo::REPO_REUSE_REPODATA|$solv::Repo::REPO_EXTEND_SOLVABLES);
444 $self->{'handle'}->internalize();
448 $self->writecachedrepo() unless $self->{'incomplete'};
449 $self->{'handle'}->create_stubs();
453 package Repo::unknown;
455 our @ISA = ('Repo::generic');
458 my ($self, $pool) = @_;
459 print "unsupported repo '$self->{'alias'}': skipped\n";
463 package Repo::system;
465 our @ISA = ('Repo::generic');
468 my ($self, $pool) = @_;
470 $self->{'handle'} = $pool->add_repo($self->{'alias'});
471 $self->{'handle'}->{'appdata'} = $self;
472 $pool->{'installed'} = $self->{'handle'};
473 print "rpm database: ";
474 $self->{'cookie'} = $self->calc_cookie_file('/var/lib/rpm/Packages');
475 if ($self->usecachedrepo()) {
480 $self->{'handle'}->add_products("/etc/products.d", $solv::Repo::REPO_NO_INTERNALIZE);
481 $self->{'handle'}->add_rpmdb(undef, $solv::Repo::REPO_REUSE_REPODATA);
482 $self->writecachedrepo();
489 my ($pool, $arch) = @_;
490 return undef unless $arch;
491 my $id = $pool->str2id($arch, 0);
492 return $id && $pool->isknownarch($id) ? 1 : undef;
496 my ($pool, $name, $globname, $globdep) = @_;
497 my $id = $pool->str2id($name, 0);
500 for my $s ($pool->whatprovides($id)) {
501 return $pool->Job($solv::Job::SOLVER_SOLVABLE_NAME, $id) if $globname && $s->{'nameid'} == $id;
505 print "[using capability match for '$name']\n" if $globname && $globdep;
506 return $pool->Job($solv::Job::SOLVER_SOLVABLE_PROVIDES, $id);
509 return unless $name =~ /[[*?]/;
512 for my $d (@{$pool->Dataiterator(0, $solv::SOLVABLE_NAME, $name, $solv::Dataiterator::SEARCH_GLOB)}) {
513 my $s = $d->{'solvable'};
514 $idmatches{$s->{'nameid'}} = 1 if $s->installable();
517 return map {$pool->Job($solv::Job::SOLVER_SOLVABLE_NAME, $_)} sort(keys %idmatches);
521 my @idmatches = $pool->matchprovidingids($name, $solv::Dataiterator::SEARCH_GLOB);
523 print "[using capability match for '$name']\n";
524 return map {$pool->Job($solv::Job::SOLVER_SOLVABLE_PROVIDES, $_)} sort(@idmatches);
531 my ($pool, $jobs, $flags, $evrstr) = @_;
533 my $evr = $pool->str2id($evrstr);
535 my $how = $j->{'how'};
536 my $sel = $how & $solv::Job::SOLVER_SELECTMASK;
537 my $what = $pool->rel2id($j->{'what'}, $evr, $flags);
538 if ($flags == $solv::REL_ARCH) {
539 $how |= $solv::Job::SOLVER_SETARCH;
540 } elsif ($flags == $solv::REL_EQ && $sel == $solv::Job::SOLVER_SOLVABLE_NAME) {
541 $how |= $evrstr =~ /-/ ? $solv::Job::SOLVER_SETEVR : $solv::Job::SOLVER_SETEV;
543 push @jobs, $pool->Job($how, $what);
548 sub limitjobs_evrarch {
549 my ($pool, $jobs, $flags, $evrstr) = @_;
550 if ($evrstr =~ /^(.+)\.(.+?)$/ && validarch($pool, $2)) {
552 $jobs = [ limitjobs($pool, $jobs, $solv::REL_ARCH, $2) ];
554 return limitjobs($pool, $jobs, $flags, $evrstr);
558 my ($pool, $cmd, $name, $rel, $evr) = @_;
560 $flags |= $solv::REL_LT if $rel =~ /</;
561 $flags |= $solv::REL_EQ if $rel =~ /=/;
562 $flags |= $solv::REL_GT if $rel =~ />/;
563 my @jobs = depglob($pool, $name, 1, 1);
564 return limitjobs($pool, \@jobs, $flags, $evr) if @jobs;
565 if (($name =~ /^(.+)\.(.+?)$/s) && validarch($pool, $2)) {
567 @jobs = depglob($pool, $1, 1, 1);
569 @jobs = limitjobs($pool, \@jobs, $solv::REL_ARCH, $arch);
570 return limitjobs($pool, \@jobs, $flags, $evr);
577 my ($pool, $cmd, $arg) = @_;
578 my @jobs = depglob($pool, $arg, 1, 1);
579 return @jobs if @jobs;
580 if (($arg =~ /^(.+)\.(.+?)$/s) && validarch($pool, $2)) {
582 @jobs = depglob($pool, $1, 1, 1);
583 return limitjobs($pool, \@jobs, $solv::REL_ARCH, $arch) if @jobs;
585 if ($arg =~ /^(.+)-(.+?)$/s) {
587 @jobs = depglob($pool, $1, 1, 0);
588 return limitjobs_evrarch($pool, \@jobs, $solv::REL_EQ, $evr) if @jobs;
590 if ($arg =~ /^(.+)-(.+?-.+?)$/s) {
592 @jobs = depglob($pool, $1, 1, 0);
593 return limitjobs_evrarch($pool, \@jobs, $solv::REL_EQ, $evr) if @jobs;
598 sub mkjobs_filelist {
599 my ($pool, $cmd, $arg) = @_;
600 my $type = ($arg =~ /[[*?]/) ? $solv::Dataiterator::SEARCH_GLOB : $solv::Dataiterator::SEARCH_STRING;
601 $type |= $solv::Dataiterator::SEARCH_FILES | $solv::Dataiterator::SEARCH_COMPLETE_FILELIST;
603 if ($cmd eq 'erase') {
604 $di = $pool->{'installed'}->Dataiterator(0, $solv::SOLVABLE_FILELIST, $arg, $type);
606 $di = $pool->Dataiterator(0, $solv::SOLVABLE_FILELIST, $arg, $type);
610 my $s = $d->{'solvable'};
611 next unless $s && $s->installable();
612 push @matches, $s->{'id'};
613 $di->skip_solvable();
615 return () unless @matches;
616 print "[using file list match for '$arg']\n";
618 return $pool->Job($solv::Job::SOLVER_SOLVABLE_ONE_OF, $pool->towhatprovides(\@matches));
620 return $pool->Job($solv::Job::SOLVER_SOLVABLE | $solv::Job::SOLVER_NOAUTOSET, $matches[0]);
625 my ($pool, $cmd, $arg) = @_;
626 if ($arg && $arg =~ /^\//) {
627 my @jobs = mkjobs_filelist($pool, $cmd, $arg);
628 return @jobs if @jobs;
630 if ($arg =~ /^(.+?)\s*([<=>]+)\s*(.+?)$/s) {
631 return mkjobs_rel($pool, $cmd, $1, $2, $3);
633 return mkjobs_nevra($pool, $cmd, $arg);
639 my $repo = $repodata->{'repo'}->{'appdata'};
640 return $repo ? $repo->load_ext($repodata) : 0;
643 die("Usage: p5solv COMMAND [ARGS]\n") unless @ARGV;
644 my $cmd = shift @ARGV;
645 $cmd = 'list' if $cmd eq 'li';
646 $cmd = 'install' if $cmd eq 'in';
647 $cmd = 'erase' if $cmd eq 'rm';
648 $cmd = 'verify' if $cmd eq 've';
649 $cmd = 'search' if $cmd eq 'se';
652 for my $reposdir ('/etc/zypp/repos.d') {
653 next unless -d $reposdir;
654 next unless opendir(DIR, $reposdir);
655 for my $reponame (sort(grep {/\.repo$/} readdir(DIR))) {
656 my $cfg = new Config::IniFiles('-file' => "$reposdir/$reponame");
657 for my $alias ($cfg->Sections()) {
658 my $repoattr = {'alias' => $alias, 'enabled' => 0, 'priority' => 99, 'autorefresh' => 1, 'type' => 'rpm-md', 'metadata_expire' => 900};
659 for my $p ($cfg->Parameters($alias)) {
660 $repoattr->{$p} = $cfg->val($alias, $p);
663 if ($repoattr->{'type'} eq 'rpm-md') {
664 $repo = Repo::rpmmd->new($alias, 'repomd', $repoattr);
665 } elsif ($repoattr->{'type'} eq 'yast2') {
666 $repo = Repo::susetags->new($alias, 'susetags', $repoattr);
668 $repo = Repo::unknown->new($alias, 'unknown', $repoattr);
675 my $pool = solv::Pool->new();
676 $pool->setarch((POSIX::uname())[4]);
677 $pool->set_loadcallback(\&load_stub);
679 my $sysrepo = Repo::system->new('@System', 'system');
680 $sysrepo->load($pool);
681 for my $repo (@repos) {
682 $repo->load($pool) if $repo->{'enabled'};
685 if ($cmd eq 'search') {
687 my $di = $pool->Dataiterator(0, $solv::SOLVABLE_NAME, $ARGV[0], $solv::Dataiterator::SEARCH_SUBSTRING | $solv::Dataiterator::SEARCH_NOCASE);
689 $matches{$d->{'solvid'}} = 1;
691 for my $solvid (sort keys %matches) {
692 my $s = $pool->{'solvables'}->[$solvid];
693 print "- ".$s->str()." [$s->{'repo'}->{'name'}] ".$s->lookup_str($solv::SOLVABLE_SUMMARY)."\n";
698 my @addedprovides = $pool->addfileprovides_ids();
699 $pool->createwhatprovides();
702 for my $arg (@ARGV) {
703 my @njobs = mkjobs($pool, $cmd, $arg);
704 die("nothing matches '$arg'\n") unless @njobs;
708 if ($cmd eq 'list' || $cmd eq 'info') {
709 die("no package matched.\n") unless @jobs;
710 for my $job (@jobs) {
711 for my $s ($job->solvables()) {
712 if ($cmd eq 'info') {
713 printf "Name: %s\n", $s->str();
714 printf "Repo: %s\n", $s->{'repo'}->{'name'};
715 printf "Summary: %s\n", $s->lookup_str($solv::SOLVABLE_SUMMARY);
716 my $str = $s->lookup_str($solv::SOLVABLE_URL);
717 printf "Url: %s\n", $str if $str;
718 $str = $s->lookup_str($solv::SOLVABLE_LICENSE);
719 printf "License: %s\n", $str if $str;
720 printf "Description:\n%s\n", $s->lookup_str($solv::SOLVABLE_DESCRIPTION);
722 printf " - %s [%s]\n", $s->str(), $s->{'repo'}->{'name'};
723 printf " %s\n", $s->lookup_str($solv::SOLVABLE_SUMMARY);
730 if ($cmd eq 'install' || $cmd eq 'erase' || $cmd eq 'up' || $cmd eq 'dup' || $cmd eq 'verify') {
732 if ($cmd eq 'up' || $cmd eq 'verify') {
733 push @jobs, $pool->Job($solv::Job::SOLVER_SOLVABLE_ALL, 0);
734 } elsif ($cmd ne 'dup') {
735 die("no package matched.\n");
738 for my $job (@jobs) {
740 if ($job->{'how'} == $solv::Job::SOLVER_SOLVABLE_ALL || grep {$_->isinstalled()} $job->solvables()) {
741 $job->{'how'} |= $solv::Job::SOLVER_UPDATE;
743 $job->{'how'} |= $solv::Job::SOLVER_INSTALL;
745 } elsif ($cmd eq 'install') {
746 $job->{'how'} |= $solv::Job::SOLVER_INSTALL;
747 } elsif ($cmd eq 'erase') {
748 $job->{'how'} |= $solv::Job::SOLVER_ERASE;
749 } elsif ($cmd eq 'dup') {
750 $job->{'how'} |= $solv::Job::SOLVER_DISTUPGRADE;
751 } elsif ($cmd eq 'verify') {
752 $job->{'how'} |= $solv::Job::SOLVER_VERIFY;
757 $solver = $pool->Solver();
758 $solver->{'ignorealreadyrecommended'} = 1;
759 $solver->{'allowuninstall'} = 1 if $cmd eq 'erase';
760 if ($cmd eq 'dup' && !@jobs) {
761 $solver->{'distupgrade'} = 1;
762 $solver->{'updatesystem'} = 1;
763 $solver->{'allowdowngrade'} = 1;
764 $solver->{'allowvendorchange'} = 1;
765 $solver->{'allowarchchange'} = 1;
766 $solver->{'dosplitprovides'} = 1;
767 } elsif ($cmd eq 'up' and @jobs == 1 and $jobs[0]->{'how'} == ($solv::Job::SOLVER_UPDATE | $solv::Job::SOLVER_SOLVABLE_ALL)) {
768 $solver->{'dosplitprovides'} = 1;
770 my @problems = $solver->solve(\@jobs);
771 last unless @problems;
772 for my $problem (@problems) {
773 print "Problem $problem->{'id'}/".@problems.":\n";
774 my $r = $problem->findproblemrule();
776 print $ri->problemstr()."\n";
777 my @solutions = $problem->solutions();
778 for my $solution (@solutions) {
779 print " Solution $solution->{'id'}:\n";
780 for my $element ($solution->elements()) {
781 my $etype = $element->{'type'};
782 if ($etype == $solv::Solver::SOLVER_SOLUTION_JOB) {
783 print " - do not ask to ".$jobs[$element->{'jobidx'}]->str()."\n";
784 } elsif ($etype == $solv::Solver::SOLVER_SOLUTION_INFARCH) {
785 if ($element->{'solvable'}->isinstalled()) {
786 print " - keep ".$element->{'solvable'}->str()." despite the inferior architecture\n";
788 print " - install ".$element->{'solvable'}->str()." despite the inferior architecture\n";
790 } elsif ($etype == $solv::Solver::SOLVER_SOLUTION_DISTUPGRADE) {
791 if ($element->{'solvable'}->isinstalled()) {
792 print " - keep obsolete ".$element->{'solvable'}->str()."\n";
794 print " - install ".$element->{'solvable'}->str()." from excluded repository\n";
796 } elsif ($etype == $solv::Solver::SOLVER_SOLUTION_REPLACE) {
797 print " - allow replacement of ".$element->{'solvable'}->str()." with ".$element->{'replacement'}->str()."\n";
798 } elsif ($etype == $solv::Solver::SOLVER_SOLUTION_ERASE) {
799 print " - allow deinstallation of ".$element->{'solvable'}->str()."\n";
801 print " - allow something else\n";
808 print "Please choose a solution: ";
811 last if $sol eq 's' || $sol eq 'q' || ($sol =~ /^\d+$/ && $sol >= 1 && $sol <= @solutions);
814 exit(1) if $sol eq 'q';
815 my $solution = $solutions[$sol - 1];
816 for my $element ($solution->elements()) {
817 my $etype = $element->{'type'};
818 if ($etype == $solv::Solver::SOLVER_SOLUTION_JOB) {
819 $jobs[$element->{'jobidx'}] = $pool->Job($solv::Job::SOLVER_NOOP, 0);
821 my $newjob = $element->Job();
822 push @jobs, $newjob if $newjob && !grep {$_ == $newjob} @jobs;
827 my $trans = $solver->transaction();
829 if ($trans->isempty()) {
830 print "Nothing to do.\n";
833 print "\nTransaction summary:\n\n";
834 for my $c ($trans->classify()) {
835 if ($c->{'type'} == $solv::Transaction::SOLVER_TRANSACTION_ERASE) {
836 print "$c->{'count'} erased packages:\n";
837 } elsif ($c->{'type'} == $solv::Transaction::SOLVER_TRANSACTION_INSTALL) {
838 print "$c->{'count'} installed packages:\n";
839 } elsif ($c->{'type'} == $solv::Transaction::SOLVER_TRANSACTION_REINSTALLED) {
840 print "$c->{'count'} reinstalled packages:\n";
841 } elsif ($c->{'type'} == $solv::Transaction::SOLVER_TRANSACTION_DOWNGRADED) {
842 print "$c->{'count'} downgraded packages:\n";
843 } elsif ($c->{'type'} == $solv::Transaction::SOLVER_TRANSACTION_CHANGED) {
844 print "$c->{'count'} changed packages:\n";
845 } elsif ($c->{'type'} == $solv::Transaction::SOLVER_TRANSACTION_UPGRADED) {
846 print "$c->{'count'} upgraded packages:\n";
847 } elsif ($c->{'type'} == $solv::Transaction::SOLVER_TRANSACTION_VENDORCHANGE) {
848 printf "$c->{'count'} vendor changes from '%s' to '%s':\n", $pool->id2str($c->{'fromid'}), $pool->id2str($c->{'toid'});
849 } elsif ($c->{'type'} == $solv::Transaction::SOLVER_TRANSACTION_ARCHCHANGE) {
850 printf "$c->{'count'} arch changes from '%s' to '%s':\n", $pool->id2str($c->{'fromid'}), $pool->id2str($c->{'toid'});
854 for my $p ($c->solvables()) {
855 if ($c->{'type'} == $solv::Transaction::SOLVER_TRANSACTION_UPGRADED || $c->{'type'} == $solv::Transaction::SOLVER_TRANSACTION_DOWNGRADED) {
856 my $other = $trans->othersolvable($p);
857 printf " - %s -> %s\n", $p->str(), $other->str();
859 printf " - %s\n", $p->str();
864 printf "install size change: %d K\n\n", $trans->calc_installsizechange();
866 print("OK to continue (y/n)? ");
870 exit(1) if $yn eq 'n';
872 my @newpkgs = $trans->newpackages();
875 my $downloadsize = 0;
876 $downloadsize += $_->lookup_num($solv::SOLVABLE_DOWNLOADSIZE) for @newpkgs;
877 printf "Downloading %d packages, %d K\n", scalar(@newpkgs), $downloadsize;
878 for my $p (@newpkgs) {
879 my $repo = $p->{'repo'}->{'appdata'};
880 my ($location, $medianr) = $p->lookup_location();
881 next unless $location;
882 if ($repo->{'type'} eq 'susetags') {
883 $location = ($repo->{'handle'}->lookup_str($solv::SOLVID_META, $solv::SUSETAGS_DATADIR) || 'suse') ."/$location";
885 my $chksum = $p->lookup_checksum($solv::SOLVABLE_CHECKSUM);
886 my $f = $repo->download($location, 0, $chksum);
887 die("\n$repo->{'alias'}: $location not found in repository\n") unless $f;
888 $newpkgsfps{$p->{'id'}} = $f;
894 print "Committing transaction:\n\n";
896 for my $p ($trans->steps()) {
897 my $steptype = $trans->steptype($p, $solv::Transaction::SOLVER_TRANSACTION_RPM_ONLY);
898 if ($steptype == $solv::Transaction::SOLVER_TRANSACTION_ERASE) {
899 print "erase ".$p->str()."\n";
900 next unless $p->lookup_num($solv::RPM_RPMDBID);
901 my $evr = $p->{'evr'};
902 $evr =~ s/^[0-9]+://; # strip epoch
903 system('rpm', '-e', '--nodeps', '--nodigest', '--nosignature', "$p->{'name'}-$evr.$p->{'arch'}") && die("rpm failed: $?\n");
904 } elsif ($steptype == $solv::Transaction::SOLVER_TRANSACTION_INSTALL || $steptype == $solv::Transaction::SOLVER_TRANSACTION_MULTIINSTALL) {
905 print "install ".$p->str()."\n";
906 my $f = $newpkgsfps{$p->{'id'}};
907 my $mode = $steptype == $solv::Transaction::SOLVER_TRANSACTION_INSTALL ? '-U' : '-i';
908 system('rpm', $mode, '--force', '--nodeps', '--nodigest', '--nosignature', "/dev/fd/".solv::xfileno($f)) && die("rpm failed: $?\n");
910 delete $newpkgsfps{$p->{'id'}};