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);
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, $f, $cookie) = @_;
41 my $chksum = solv::Chksum->new($solv::REPOKEY_TYPE_SHA256);
43 $chksum->add($cookie);
44 $chksum->add_fstat(fileno($f));
45 my $extcookie = $chksum->raw();
46 substr($extcookie, 0, 1) = chr(1) if ord(substr($extcookie, 0, 1)) == 0;
51 my ($self, $ext) = @_;
52 my $path = $self->{'alias'};
54 $path .= $ext ? "_$ext.solvx" : '.solv';
56 return "/var/cache/solv/$path";
60 my ($self, $pool) = @_;
61 $self->{'handle'} = $pool->add_repo($self->{'alias'});
62 $self->{'handle'}->{'appdata'} = $self;
63 $self->{'handle'}->{'priority'} = 99 - $self->{'priority'};
64 my $dorefresh = $self->{'autorefresh'};
66 my @s = stat($self->cachepath());
67 $dorefresh = 0 if @s && ($self->{'metadata_expire'} == -1 || time() - $s[9] < $self->{'metadata_expire'});
69 $self->{'cookie'} = '';
70 if (!$dorefresh && $self->usecachedrepo()) {
71 print "repo: '$self->{'alias'}' cached\n";
74 return $self->load_if_changed();
86 my ($self, $file, $uncompress, $chksum, $markincomplete) = @_;
87 if (!$self->{'baseurl'}) {
88 print "$self->{'alias'}: no baseurl\n";
91 my $url = $self->{'baseurl'};
94 open(my $f, '+>', undef) || die;
95 fcntl($f, Fcntl::F_SETFD, 0);
96 my $st = system('curl', '-f', '-s', '-L', '-o', "/dev/fd/".fileno($f), '--', $url);
97 if (POSIX::lseek(fileno($f), 0, POSIX::SEEK_END) == 0 && ($st == 0 || !$chksum)) {
100 POSIX::lseek(fileno($f), 0, POSIX::SEEK_SET);
102 print "$file: download error #$st\n";
103 $self->{'incomplete'} = 1 if $markincomplete;
107 my $fchksum = solv::Chksum->new($chksum->{'type'});
108 $fchksum->add_fd(fileno($f));
109 if ($fchksum != $chksum) {
110 print "$file: checksum error\n";
111 $self->{'incomplete'} = 1 if $markincomplete;
116 return solv::xfopen_dup($file, fileno($f));
118 return solv::xfopen_dup(undef, fileno($f));
123 my ($self, $ext, $mark) = @_;
124 my $cookie = $ext ? $self->{'extcookie'} : $self->{'cookie'};
125 my $handle = $self->{'handle'};
126 my $cachepath = $self->cachepath($ext);
128 if (sysopen(my $f, $cachepath, POSIX::O_RDONLY)) {
129 sysseek($f, -32, Fcntl::SEEK_END);
131 return undef if sysread($f, $fcookie, 32) != 32;
132 return undef if $cookie && $fcookie ne $cookie;
133 if ($self->{'type'} ne 'system' && !$ext) {
134 sysseek($f, -32 * 2, Fcntl::SEEK_END);
135 return undef if sysread($f, $fextcookie, 32) != 32;
137 sysseek($f, 0, Fcntl::SEEK_SET);
138 my $fd = solv::xfopen_dup(undef, fileno($f));
139 my $flags = $ext ? $solv::Repo::REPO_USE_LOADING|$solv::Repo::REPO_EXTEND_SOLVABLES : 0;
140 $flags |= $solv::Repo::REPO_LOCALPOOL if $ext && $ext ne 'DL';
141 if (!$self->{'handle'}->add_solv($fd, $flags)) {
146 $self->{'cookie'} = $fcookie unless $ext;
147 $self->{'extcookie'} = $fextcookie if $fextcookie;
148 utime undef, undef, $f if $mark;
154 sub writecachedrepo {
155 my ($self, $ext, $info) = @_;
156 mkdir("/var/cache/solv", 0755) unless -d "/var/cache/solv";
159 ($f, $tmpname) = File::Temp::tempfile(".newsolv-XXXXXX", 'DIR' => '/var/cache/solv');
163 my $ff = solv::xfopen_dup(undef, fileno($f));
165 $self->{'handle'}->write($ff);
169 $self->{'handle'}->write_first_repodata($ff);
172 if ($self->{'type'} ne 'system' && !$ext) {
173 $self->{'extcookie'} ||= $self->calc_cookie_ext($f, $self->{'cookie'});
174 syswrite($f, $self->{'extcookie'});
176 syswrite($f, $ext ? $self->{'extcookie'} : $self->{'cookie'});
178 if ($self->{'handle'}->iscontiguous()) {
179 $f = solv::xfopen($tmpname);
182 $self->{'handle'}->empty();
183 die("internal error, cannot reload solv file\n") unless $self->{'handle'}->add_solv($f, $solv::Repo::SOLV_ADD_NO_STUBS);
185 $info->extend_to_repo();
186 $info->add_solv($f, $solv::Repo::REPO_EXTEND_SOLVABLES);
191 rename($tmpname, $self->cachepath($ext));
201 our @ISA = ('Repo::generic');
204 my ($self, $what) = @_;
205 my $di = $self->{'handle'}->Dataiterator($solv::SOLVID_META, $solv::REPOSITORY_REPOMD_TYPE, $what, $solv::Dataiterator::SEARCH_STRING);
206 $di->prepend_keyname($solv::REPOSITORY_REPOMD);
208 my $dp = $d->parentpos();
209 my $filename = $dp->lookup_str($solv::REPOSITORY_REPOMD_LOCATION);
210 next unless $filename;
211 my $chksum = $dp->lookup_checksum($solv::REPOSITORY_REPOMD_CHECKSUM);
213 print "no $filename file checksum!\n";
214 return (undef, undef);
216 return ($filename, $chksum);
218 return (undef, undef);
222 my ($self, $repodata, $what, $ext) = @_;
223 my ($filename, $chksum) = $self->find($what);
224 ($filename, $chksum) = $self->find('prestodelta') if !$filename && $what eq 'deltainfo';
225 return unless $filename;
226 my $handle = $repodata->new_handle();
227 $repodata->set_poolstr($handle, $solv::REPOSITORY_REPOMD_TYPE, $what);
228 $repodata->set_str($handle, $solv::REPOSITORY_REPOMD_LOCATION, $filename);
229 $repodata->set_checksum($handle, $solv::REPOSITORY_REPOMD_CHECKSUM, $chksum);
231 $repodata->add_idarray($handle, $solv::REPOSITORY_KEYS, $solv::REPOSITORY_DELTAINFO);
232 $repodata->add_idarray($handle, $solv::REPOSITORY_KEYS, $solv::REPOKEY_TYPE_FLEXARRAY);
233 } elsif ($ext eq 'FL') {
234 $repodata->add_idarray($handle, $solv::REPOSITORY_KEYS, $solv::SOLVABLE_FILELIST);
235 $repodata->add_idarray($handle, $solv::REPOSITORY_KEYS, $solv::REPOKEY_TYPE_DIRSTRARRAY);
237 $repodata->add_flexarray($solv::SOLVID_META, $solv::REPOSITORY_EXTERNAL, $handle);
242 my $repodata = $self->{'handle'}->add_repodata(0);
243 $self->add_ext($repodata, 'deltainfo', 'DL');
244 $self->add_ext($repodata, 'filelists', 'FL');
245 $repodata->internalize();
249 my ($self, $repodata) = @_;
250 my $repomdtype = $repodata->lookup_str($solv::SOLVID_META, $solv::REPOSITORY_REPOMD_TYPE);
252 if ($repomdtype eq 'filelists') {
254 } elsif ($repomdtype eq 'deltainfo') {
259 print("[$self->{'alias'}:$ext: ");
261 if ($self->usecachedrepo($ext)) {
266 my $filename = $repodata->lookup_str($solv::SOLVID_META, $solv::REPOSITORY_REPOMD_LOCATION);
267 my $filechksum = $repodata->lookup_checksum($solv::SOLVID_META, $solv::REPOSITORY_REPOMD_CHECKSUM);
268 my $f = $self->download($filename, 1, $filechksum);
271 $self->{'handle'}->add_rpmmd($f, 'FL', $solv::Repo::REPO_USE_LOADING|$solv::Repo::REPO_EXTEND_SOLVABLES);
272 } elsif ($ext eq 'FL') {
273 $self->{'handle'}->add_deltainfoxml($f, $solv::Repo::REPO_USE_LOADING);
276 $self->writecachedrepo($ext, $repodata);
280 sub load_if_changed {
282 print "rpmmd repo '$self->{'alias'}': ";
284 my $f = $self->download("repodata/repomd.xml");
286 print "no repomd.xml file, skipped\n";
287 $self->{'handle'}->free(1);
288 delete $self->{'handle'};
291 $self->{'cookie'} = $self->calc_cookie_fp($f);
292 if ($self->usecachedrepo(undef, 1)) {
297 $self->{'handle'}->add_repomdxml($f, 0);
300 my ($filename, $filechksum) = $self->find('primary');
302 $f = $self->download($filename, 1, $filechksum, 1);
304 $self->{'handle'}->add_rpmmd($f, undef, 0);
307 return undef if $self->{'incomplete'};
309 ($filename, $filechksum) = $self->find('updateinfo');
311 $f = $self->download($filename, 1, $filechksum, 1);
313 $self->{'handle'}->add_updateinfoxml($f, 0);
318 $self->writecachedrepo() unless $self->{'incomplete'};
319 $self->{'handle'}->create_stubs();
323 package Repo::susetags;
325 our @ISA = ('Repo::generic');
328 my ($self, $what) = @_;
330 my $di = $self->{'handle'}->Dataiterator($solv::SOLVID_META, $solv::SUSETAGS_FILE_NAME, $what, $solv::Dataiterator::SEARCH_STRING);
331 $di->prepend_keyname($solv::SUSETAGS_FILE);
333 my $dp = $d->parentpos();
334 my $chksum = $dp->lookup_checksum($solv::SUSETAGS_FILE_CHECKSUM);
335 return ($what, $chksum);
337 return (undef, undef);
341 $solv::SOLVABLE_SUMMARY => $solv::REPOKEY_TYPE_STR,
342 $solv::SOLVABLE_DESCRIPTION => $solv::REPOKEY_TYPE_STR,
343 $solv::SOLVABLE_EULA => $solv::REPOKEY_TYPE_STR,
344 $solv::SOLVABLE_MESSAGEINS => $solv::REPOKEY_TYPE_STR,
345 $solv::SOLVABLE_MESSAGEDEL => $solv::REPOKEY_TYPE_STR,
346 $solv::SOLVABLE_CATEGORY => $solv::REPOKEY_TYPE_ID,
350 my ($self, $repodata, $what, $ext) = @_;
351 my ($filename, $chksum) = $self->find($what);
352 my $handle = $repodata->new_handle();
353 $repodata->set_str($handle, $solv::SUSETAGS_FILE_NAME, $filename);
354 $repodata->set_checksum($handle, $solv::SUSETAGS_FILE_CHECKSUM, $chksum);
356 $repodata->add_idarray($handle, $solv::REPOSITORY_KEYS, $solv::REPOSITORY_DELTAINFO);
357 $repodata->add_idarray($handle, $solv::REPOSITORY_KEYS, $solv::REPOKEY_TYPE_FLEXARRAY);
358 } elsif ($ext eq 'DU') {
359 $repodata->add_idarray($handle, $solv::REPOSITORY_KEYS, $solv::SOLVABLE_DISKUSAGE);
360 $repodata->add_idarray($handle, $solv::REPOSITORY_KEYS, $solv::REPOKEY_TYPE_DIRNUMNUMARRAY);
361 } elsif ($ext eq 'FL') {
362 $repodata->add_idarray($handle, $solv::REPOSITORY_KEYS, $solv::SOLVABLE_FILELIST);
363 $repodata->add_idarray($handle, $solv::REPOSITORY_KEYS, $solv::REPOKEY_TYPE_DIRSTRARRAY);
365 for my $langid (sort {$a <=> $b} keys %langtags) {
366 $repodata->add_idarray($handle, $solv::REPOSITORY_KEYS, $self->{'handle'}->{'pool'}->id2langid($langid, $ext, 1));
367 $repodata->add_idarray($handle, $solv::REPOSITORY_KEYS, $langtags{$langid});
370 $repodata->add_flexarray($solv::SOLVID_META, $solv::REPOSITORY_EXTERNAL, $handle);
375 my $repodata = $self->{'handle'}->add_repodata(0);
376 my $di = $self->{'handle'}->Dataiterator($solv::SOLVID_META, $solv::SUSETAGS_FILE_NAME, undef, 0);
377 $di->prepend_keyname($solv::SUSETAGS_FILE);
379 my $filename = $d->str();
380 next unless $filename && $filename =~ /^packages\.(..)(?:\..*)$/;
381 next if $1 eq 'en' || $1 eq 'gz';
382 $self->add_ext($repodata, $filename, $1);
384 $repodata->internalize();
388 my ($self, $repodata) = @_;
389 my $filename = $repodata->lookup_str($solv::SOLVID_META, $solv::SUSETAGS_FILE_NAME);
390 my $ext = substr($filename, 9, 2);
391 print("[$self->{'alias'}:$ext: ");
393 if ($self->usecachedrepo($ext)) {
398 my $defvendorid = $self->{'handle'}->lookup_id($solv::SOLVID_META, $solv::SUSETAGS_DEFAULTVENDOR);
399 my $descrdir = $self->{'handle'}->lookup_str($solv::SOLVID_META, $solv::SUSETAGS_DESCRDIR) || 'suse/setup/descr';
400 my $filechksum = $repodata->lookup_checksum($solv::SOLVID_META, $solv::SUSETAGS_FILE_CHECKSUM);
401 my $f = $self->download("$descrdir/$filename", 1, $filechksum);
403 $self->{'handle'}->add_susetags($f, $defvendorid, $ext, $solv::Repo::REPO_USE_LOADING|$solv::Repo::REPO_EXTEND_SOLVABLES);
405 $self->writecachedrepo($ext, $repodata);
409 sub load_if_changed {
411 print "susetags repo '$self->{'alias'}': ";
413 my $f = $self->download("content");
415 print "no content file, skipped\n";
416 $self->{'handle'}->free(1);
417 delete $self->{'handle'};
420 $self->{'cookie'} = $self->calc_cookie_fp($f);
421 if ($self->usecachedrepo(undef, 1)) {
426 $self->{'handle'}->add_content($f, 0);
429 my $defvendorid = $self->{'handle'}->lookup_id($solv::SOLVID_META, $solv::SUSETAGS_DEFAULTVENDOR);
430 my $descrdir = $self->{'handle'}->lookup_str($solv::SOLVID_META, $solv::SUSETAGS_DESCRDIR) || 'suse/setup/descr';
431 my ($filename, $filechksum) = $self->find('packages.gz');
432 ($filename, $filechksum) = $self->find('packages') unless $filename;
434 $f = $self->download("$descrdir/$filename", 1, $filechksum, 1);
436 $self->{'handle'}->add_susetags($f, $defvendorid, undef, $solv::Repo::REPO_NO_INTERNALIZE|$solv::Repo::SUSETAGS_RECORD_SHARES);
438 ($filename, $filechksum) = $self->find('packages.en.gz');
439 ($filename, $filechksum) = $self->find('packages.en') unless $filename;
441 $f = $self->download("$descrdir/$filename", 1, $filechksum, 1);
443 $self->{'handle'}->add_susetags($f, $defvendorid, undef, $solv::Repo::REPO_NO_INTERNALIZE|$solv::Repo::REPO_REUSE_REPODATA|$solv::Repo::REPO_EXTEND_SOLVABLES);
447 $self->{'handle'}->internalize();
451 $self->writecachedrepo() unless $self->{'incomplete'};
452 $self->{'handle'}->create_stubs();
458 return ($self->{'handle'}->lookup_str($solv::SOLVID_META, $solv::SUSETAGS_DATADIR) || 'suse') . '/';
461 package Repo::unknown;
463 our @ISA = ('Repo::generic');
466 my ($self, $pool) = @_;
467 print "unsupported repo '$self->{'alias'}': skipped\n";
471 package Repo::system;
473 our @ISA = ('Repo::generic');
476 my ($self, $pool) = @_;
478 $self->{'handle'} = $pool->add_repo($self->{'alias'});
479 $self->{'handle'}->{'appdata'} = $self;
480 $pool->{'installed'} = $self->{'handle'};
481 print "rpm database: ";
482 $self->{'cookie'} = $self->calc_cookie_file('/var/lib/rpm/Packages');
483 if ($self->usecachedrepo()) {
488 if (defined(&solv::Repo::add_products)) {
489 $self->{'handle'}->add_products("/etc/products.d", $solv::Repo::REPO_NO_INTERNALIZE);
491 $self->{'handle'}->add_rpmdb(undef, $solv::Repo::REPO_REUSE_REPODATA);
492 $self->writecachedrepo();
500 my $repo = $repodata->{'repo'}->{'appdata'};
501 return $repo ? $repo->load_ext($repodata) : 0;
504 die("Usage: p5solv COMMAND [ARGS]\n") unless @ARGV;
505 my $cmd = shift @ARGV;
506 $cmd = 'list' if $cmd eq 'li';
507 $cmd = 'install' if $cmd eq 'in';
508 $cmd = 'erase' if $cmd eq 'rm';
509 $cmd = 'verify' if $cmd eq 've';
510 $cmd = 'search' if $cmd eq 'se';
514 if (-d '/etc/zypp/repos.d') {
515 @reposdirs = ( '/etc/zypp/repos.d' );
517 @reposdirs = ( '/etc/yum/repos.d' );
519 for my $reposdir (@reposdirs) {
520 next unless -d $reposdir;
521 next unless opendir(DIR, $reposdir);
522 for my $reponame (sort(grep {/\.repo$/} readdir(DIR))) {
523 my $cfg = new Config::IniFiles('-file' => "$reposdir/$reponame");
524 for my $alias ($cfg->Sections()) {
525 my $repoattr = {'alias' => $alias, 'enabled' => 0, 'priority' => 99, 'autorefresh' => 1, 'type' => 'rpm-md', 'metadata_expire' => 900};
526 for my $p ($cfg->Parameters($alias)) {
527 $repoattr->{$p} = $cfg->val($alias, $p);
530 if ($repoattr->{'type'} eq 'rpm-md') {
531 $repo = Repo::rpmmd->new($alias, 'repomd', $repoattr);
532 } elsif ($repoattr->{'type'} eq 'yast2') {
533 $repo = Repo::susetags->new($alias, 'susetags', $repoattr);
535 $repo = Repo::unknown->new($alias, 'unknown', $repoattr);
542 my $pool = solv::Pool->new();
543 $pool->setarch((POSIX::uname())[4]);
544 $pool->set_loadcallback(\&load_stub);
546 my $sysrepo = Repo::system->new('@System', 'system');
547 $sysrepo->load($pool);
548 for my $repo (@repos) {
549 $repo->load($pool) if $repo->{'enabled'};
552 if ($cmd eq 'search') {
554 my $di = $pool->Dataiterator(0, $solv::SOLVABLE_NAME, $ARGV[0], $solv::Dataiterator::SEARCH_SUBSTRING | $solv::Dataiterator::SEARCH_NOCASE);
556 $matches{$d->{'solvid'}} = 1;
558 for my $solvid (sort keys %matches) {
559 my $s = $pool->{'solvables'}->[$solvid];
560 print "- ".$s->str()." [$s->{'repo'}->{'name'}] ".$s->lookup_str($solv::SOLVABLE_SUMMARY)."\n";
565 my @addedprovides = $pool->addfileprovides_queue();
566 $pool->createwhatprovides();
569 for my $arg (@ARGV) {
570 my $flags = $solv::Selection::SELECTION_NAME | $solv::Selection::SELECTION_PROVIDES | $solv::Selection::SELECTION_GLOB;
572 $flags |= $solv::Selection::SELECTION_FILELIST;
573 $flags |= $solv::Selection::SELECTION_INSTALLED_ONLY if $cmd eq 'erase';
575 my $sel = $pool->select($arg, $flags);
576 if ($sel->isempty()) {
577 $sel = $pool->select($arg, $flags | $solv::Selection::SELECTION_NOCASE);
578 print "[ignoring case for '$arg']\n" unless $sel->isempty();
580 die("nothing matches '$arg'\n") if $sel->isempty();
581 print "[using file list match for '$arg']\n" if $sel->flags() & $solv::Selection::SELECTION_FILELIST;
582 print "[using capability match for '$arg']\n" if $sel->flags() & $solv::Selection::SELECTION_PROVIDES;
583 push @jobs, $sel->jobs(0);
585 if (!@jobs && ($cmd eq 'up' || $cmd eq 'dup' || $cmd eq 'verify')) {
586 my $sel = $pool->Selection();
587 $sel->addsimple($solv::Job::SOLVER_SOLVABLE_ALL, 0);
588 push @jobs, $sel->jobs(0);
591 if ($cmd eq 'list' || $cmd eq 'info') {
592 die("no package matched.\n") unless @jobs;
593 for my $job (@jobs) {
594 for my $s ($job->solvables()) {
595 if ($cmd eq 'info') {
596 printf "Name: %s\n", $s->str();
597 printf "Repo: %s\n", $s->{'repo'}->{'name'};
598 printf "Summary: %s\n", $s->lookup_str($solv::SOLVABLE_SUMMARY);
599 my $str = $s->lookup_str($solv::SOLVABLE_URL);
600 printf "Url: %s\n", $str if $str;
601 $str = $s->lookup_str($solv::SOLVABLE_LICENSE);
602 printf "License: %s\n", $str if $str;
603 printf "Description:\n%s\n", $s->lookup_str($solv::SOLVABLE_DESCRIPTION);
605 printf " - %s [%s]\n", $s->str(), $s->{'repo'}->{'name'};
606 printf " %s\n", $s->lookup_str($solv::SOLVABLE_SUMMARY);
613 if ($cmd eq 'install' || $cmd eq 'erase' || $cmd eq 'up' || $cmd eq 'dup' || $cmd eq 'verify') {
614 die("no package matched.\n") unless @jobs;
615 for my $job (@jobs) {
617 if ($job->{'how'} == $solv::Job::SOLVER_SOLVABLE_ALL || grep {$_->isinstalled()} $job->solvables()) {
618 $job->{'how'} |= $solv::Job::SOLVER_UPDATE;
620 $job->{'how'} |= $solv::Job::SOLVER_INSTALL;
622 } elsif ($cmd eq 'install') {
623 $job->{'how'} |= $solv::Job::SOLVER_INSTALL;
624 } elsif ($cmd eq 'erase') {
625 $job->{'how'} |= $solv::Job::SOLVER_ERASE;
626 } elsif ($cmd eq 'dup') {
627 $job->{'how'} |= $solv::Job::SOLVER_DISTUPGRADE;
628 } elsif ($cmd eq 'verify') {
629 $job->{'how'} |= $solv::Job::SOLVER_VERIFY;
634 $solver = $pool->Solver();
635 $solver->set_flag($solv::Solver::SOLVER_FLAG_SPLITPROVIDES, 1);
636 $solver->set_flag($solv::Solver::SOLVER_FLAG_ALLOW_UNINSTALL, 1) if $cmd eq 'erase';
637 my @problems = $solver->solve(\@jobs);
638 last unless @problems;
639 for my $problem (@problems) {
640 print "Problem $problem->{'id'}/".@problems.":\n";
641 my $r = $problem->findproblemrule();
643 print $ri->problemstr()."\n";
644 my @solutions = $problem->solutions();
645 for my $solution (@solutions) {
646 print " Solution $solution->{'id'}:\n";
647 for my $element ($solution->elements(1)) {
648 print " - ".$element->str()."\n";
654 print "Please choose a solution: ";
657 last if $sol eq 's' || $sol eq 'q' || ($sol =~ /^\d+$/ && $sol >= 1 && $sol <= @solutions);
660 exit(1) if $sol eq 'q';
661 my $solution = $solutions[$sol - 1];
662 for my $element ($solution->elements()) {
663 my $newjob = $element->Job();
664 if ($element->{'type'} == $solv::Solver::SOLVER_SOLUTION_JOB) {
665 $jobs[$element->{'jobidx'}] = $newjob;
667 push @jobs, $newjob if $newjob && !grep {$_ == $newjob} @jobs;
672 my $trans = $solver->transaction();
674 if ($trans->isempty()) {
675 print "Nothing to do.\n";
678 print "\nTransaction summary:\n\n";
679 for my $c ($trans->classify()) {
680 if ($c->{'type'} == $solv::Transaction::SOLVER_TRANSACTION_ERASE) {
681 print "$c->{'count'} erased packages:\n";
682 } elsif ($c->{'type'} == $solv::Transaction::SOLVER_TRANSACTION_INSTALL) {
683 print "$c->{'count'} installed packages:\n";
684 } elsif ($c->{'type'} == $solv::Transaction::SOLVER_TRANSACTION_REINSTALLED) {
685 print "$c->{'count'} reinstalled packages:\n";
686 } elsif ($c->{'type'} == $solv::Transaction::SOLVER_TRANSACTION_DOWNGRADED) {
687 print "$c->{'count'} downgraded packages:\n";
688 } elsif ($c->{'type'} == $solv::Transaction::SOLVER_TRANSACTION_CHANGED) {
689 print "$c->{'count'} changed packages:\n";
690 } elsif ($c->{'type'} == $solv::Transaction::SOLVER_TRANSACTION_UPGRADED) {
691 print "$c->{'count'} upgraded packages:\n";
692 } elsif ($c->{'type'} == $solv::Transaction::SOLVER_TRANSACTION_VENDORCHANGE) {
693 printf "$c->{'count'} vendor changes from '%s' to '%s':\n", $pool->id2str($c->{'fromid'}), $pool->id2str($c->{'toid'});
694 } elsif ($c->{'type'} == $solv::Transaction::SOLVER_TRANSACTION_ARCHCHANGE) {
695 printf "$c->{'count'} arch changes from '%s' to '%s':\n", $pool->id2str($c->{'fromid'}), $pool->id2str($c->{'toid'});
699 for my $p ($c->solvables()) {
700 if ($c->{'type'} == $solv::Transaction::SOLVER_TRANSACTION_UPGRADED || $c->{'type'} == $solv::Transaction::SOLVER_TRANSACTION_DOWNGRADED) {
701 my $other = $trans->othersolvable($p);
702 printf " - %s -> %s\n", $p->str(), $other->str();
704 printf " - %s\n", $p->str();
709 printf "install size change: %d K\n\n", $trans->calc_installsizechange();
711 print("OK to continue (y/n)? ");
715 exit(1) if $yn eq 'n';
717 my @newpkgs = $trans->newpackages();
720 my $downloadsize = 0;
721 $downloadsize += $_->lookup_num($solv::SOLVABLE_DOWNLOADSIZE) for @newpkgs;
722 printf "Downloading %d packages, %d K\n", scalar(@newpkgs), $downloadsize;
723 for my $p (@newpkgs) {
724 my $repo = $p->{'repo'}->{'appdata'};
725 my ($location, $medianr) = $p->lookup_location();
726 next unless $location;
727 $location = $repo->packagespath() . $location;
728 my $chksum = $p->lookup_checksum($solv::SOLVABLE_CHECKSUM);
729 my $f = $repo->download($location, 0, $chksum);
730 die("\n$repo->{'alias'}: $location not found in repository\n") unless $f;
731 $newpkgsfps{$p->{'id'}} = $f;
737 print "Committing transaction:\n\n";
739 for my $p ($trans->steps()) {
740 my $steptype = $trans->steptype($p, $solv::Transaction::SOLVER_TRANSACTION_RPM_ONLY);
741 if ($steptype == $solv::Transaction::SOLVER_TRANSACTION_ERASE) {
742 print "erase ".$p->str()."\n";
743 next unless $p->lookup_num($solv::RPM_RPMDBID);
744 my $evr = $p->{'evr'};
745 $evr =~ s/^[0-9]+://; # strip epoch
746 system('rpm', '-e', '--nodeps', '--nodigest', '--nosignature', "$p->{'name'}-$evr.$p->{'arch'}") && die("rpm failed: $?\n");
747 } elsif ($steptype == $solv::Transaction::SOLVER_TRANSACTION_INSTALL || $steptype == $solv::Transaction::SOLVER_TRANSACTION_MULTIINSTALL) {
748 print "install ".$p->str()."\n";
749 my $f = $newpkgsfps{$p->{'id'}};
750 my $mode = $steptype == $solv::Transaction::SOLVER_TRANSACTION_INSTALL ? '-U' : '-i';
751 system('rpm', $mode, '--force', '--nodeps', '--nodigest', '--nosignature', "/dev/fd/".solv::xfileno($f)) && die("rpm failed: $?\n");
753 delete $newpkgsfps{$p->{'id'}};