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";
82 my ($self, $file, $uncompress, $chksum, $markincomplete) = @_;
83 if (!$self->{'baseurl'}) {
84 print "$self->{'alias'}: no baseurl\n";
87 my $url = $self->{'baseurl'};
90 open(my $f, '+>', undef) || die;
91 fcntl($f, Fcntl::F_SETFD, 0);
92 my $st = system('curl', '-f', '-s', '-L', '-o', "/dev/fd/".fileno($f), '--', $url);
93 if (POSIX::lseek(fileno($f), 0, POSIX::SEEK_END) == 0 && ($st == 0 || !$chksum)) {
96 POSIX::lseek(fileno($f), 0, POSIX::SEEK_SET);
98 print "$file: download error #$st\n";
99 $self->{'incomplete'} = 1 if $markincomplete;
103 my $fchksum = solv::Chksum->new($chksum->{'type'});
104 $fchksum->add_fd(fileno($f));
105 if ($fchksum != $chksum) {
106 print "$file: checksum error\n";
107 $self->{'incomplete'} = 1 if $markincomplete;
112 return solv::xfopen_fd($file, fileno($f));
114 return solv::xfopen_fd(undef, fileno($f));
119 my ($self, $ext, $mark) = @_;
120 my $cookie = $ext ? $self->{'extcookie'} : $self->{'cookie'};
121 my $handle = $self->{'handle'};
122 my $cachepath = $self->cachepath($ext);
124 if (sysopen(my $f, $cachepath, POSIX::O_RDONLY)) {
125 sysseek($f, -32, Fcntl::SEEK_END);
127 return undef if sysread($f, $fcookie, 32) != 32;
128 return undef if $cookie && $fcookie ne $cookie;
129 if ($self->{'type'} ne 'system' && !$ext) {
130 sysseek($f, -32 * 2, Fcntl::SEEK_END);
131 return undef if sysread($f, $fextcookie, 32) != 32;
133 sysseek($f, 0, Fcntl::SEEK_SET);
134 my $fd = solv::xfopen_fd(undef, fileno($f));
135 my $flags = $ext ? $solv::Repo::REPO_USE_LOADING|$solv::Repo::REPO_EXTEND_SOLVABLES : 0;
136 $flags |= $solv::Repo::REPO_LOCALPOOL if $ext && $ext ne 'DL';
137 if (!$self->{'handle'}->add_solv($fd, $flags)) {
140 $self->{'cookie'} = $fcookie unless $ext;
141 $self->{'extcookie'} = $fextcookie if $fextcookie;
142 utime undef, undef, $f if $mark;
148 sub writecachedrepo {
149 my ($self, $ext, $info) = @_;
150 return if $self->{'incomplete'};
151 mkdir("/var/cache/solv", 0755) unless -d "/var/cache/solv";
154 ($f, $tmpname) = File::Temp::tempfile(".newsolv-XXXXXX", 'DIR' => '/var/cache/solv');
158 my $ff = solv::xfopen_fd(undef, fileno($f));
160 $self->{'handle'}->write($ff);
164 $self->{'handle'}->write_first_repodata($ff);
166 undef $ff; # also flushes
167 if ($self->{'type'} ne 'system' && !$ext) {
168 $self->{'extcookie'} ||= $self->calc_cookie_ext($f, $self->{'cookie'});
169 syswrite($f, $self->{'extcookie'});
171 syswrite($f, $ext ? $self->{'extcookie'} : $self->{'cookie'});
173 if ($self->{'handle'}->iscontiguous()) {
174 $f = solv::xfopen($tmpname);
177 $self->{'handle'}->empty();
178 die("internal error, cannot reload solv file\n") unless $self->{'handle'}->add_solv($f, $solv::Repo::SOLV_ADD_NO_STUBS);
180 $info->extend_to_repo();
181 $info->add_solv($f, $solv::Repo::REPO_EXTEND_SOLVABLES);
185 rename($tmpname, $self->cachepath($ext));
195 our @ISA = ('Repo::generic');
198 my ($self, $what) = @_;
199 my $di = $self->{'handle'}->Dataiterator($solv::SOLVID_META, $solv::REPOSITORY_REPOMD_TYPE, $what, $solv::Dataiterator::SEARCH_STRING);
200 $di->prepend_keyname($solv::REPOSITORY_REPOMD);
202 my $dp = $d->parentpos();
203 my $filename = $dp->lookup_str($solv::REPOSITORY_REPOMD_LOCATION);
204 next unless $filename;
205 my $chksum = $dp->lookup_checksum($solv::REPOSITORY_REPOMD_CHECKSUM);
207 print "no $filename file checksum!\n";
208 return (undef, undef);
210 return ($filename, $chksum);
212 return (undef, undef);
216 my ($self, $repodata, $what, $ext) = @_;
217 my ($filename, $chksum) = $self->find($what);
218 ($filename, $chksum) = $self->find('prestodelta') if !$filename && $what eq 'deltainfo';
219 return unless $filename;
220 my $handle = $repodata->new_handle();
221 $repodata->set_poolstr($handle, $solv::REPOSITORY_REPOMD_TYPE, $what);
222 $repodata->set_str($handle, $solv::REPOSITORY_REPOMD_LOCATION, $filename);
223 $repodata->set_checksum($handle, $solv::REPOSITORY_REPOMD_CHECKSUM, $chksum);
225 $repodata->add_idarray($handle, $solv::REPOSITORY_KEYS, $solv::REPOSITORY_DELTAINFO);
226 $repodata->add_idarray($handle, $solv::REPOSITORY_KEYS, $solv::REPOKEY_TYPE_FLEXARRAY);
227 } elsif ($ext eq 'FL') {
228 $repodata->add_idarray($handle, $solv::REPOSITORY_KEYS, $solv::SOLVABLE_FILELIST);
229 $repodata->add_idarray($handle, $solv::REPOSITORY_KEYS, $solv::REPOKEY_TYPE_DIRSTRARRAY);
231 $repodata->add_flexarray($solv::SOLVID_META, $solv::REPOSITORY_EXTERNAL, $handle);
236 my $repodata = $self->{'handle'}->add_repodata(0);
237 $self->add_ext($repodata, 'deltainfo', 'DL');
238 $self->add_ext($repodata, 'filelists', 'FL');
239 $repodata->internalize();
243 my ($self, $repodata) = @_;
244 my $repomdtype = $repodata->lookup_str($solv::SOLVID_META, $solv::REPOSITORY_REPOMD_TYPE);
246 if ($repomdtype eq 'filelists') {
248 } elsif ($repomdtype eq 'deltainfo') {
253 print("[$self->{'alias'}:$ext: ");
255 if ($self->usecachedrepo($ext)) {
260 my $filename = $repodata->lookup_str($solv::SOLVID_META, $solv::REPOSITORY_REPOMD_LOCATION);
261 my $filechksum = $repodata->lookup_checksum($solv::SOLVID_META, $solv::REPOSITORY_REPOMD_CHECKSUM);
262 my $f = $self->download($filename, 1, $filechksum);
265 $self->{'handle'}->add_rpmmd($f, 'FL', $solv::Repo::REPO_USE_LOADING|$solv::Repo::REPO_EXTEND_SOLVABLES);
266 } elsif ($ext eq 'FL') {
267 $self->{'handle'}->add_deltainfoxml($f, $solv::Repo::REPO_USE_LOADING);
269 $self->writecachedrepo($ext, $repodata);
274 my ($self, $pool) = @_;
275 return 1 if $self->Repo::generic::load($pool);
276 print "rpmmd repo '$self->{'alias'}': ";
278 my $f = $self->download("repodata/repomd.xml");
280 print "no repomd.xml file, skipped\n";
281 $self->{'handle'}->free(1);
282 delete $self->{'handle'};
285 $self->{'cookie'} = $self->calc_cookie_fp($f);
286 if ($self->usecachedrepo(undef, 1)) {
290 $self->{'handle'}->add_repomdxml($f, 0);
292 my ($filename, $filechksum) = $self->find('primary');
294 $f = $self->download($filename, 1, $filechksum, 1);
296 $self->{'handle'}->add_rpmmd($f, undef, 0);
298 return undef if $self->{'incomplete'};
300 ($filename, $filechksum) = $self->find('updateinfo');
302 $f = $self->download($filename, 1, $filechksum, 1);
304 $self->{'handle'}->add_updateinfoxml($f, 0);
308 $self->writecachedrepo();
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);
323 my $dp = $d->parentpos();
324 my $chksum = $dp->lookup_checksum($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_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->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);
394 $self->writecachedrepo($ext, $repodata);
399 my ($self, $pool) = @_;
400 return 1 if $self->Repo::generic::load($pool);
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)) {
415 $self->{'handle'}->add_content($f, 0);
417 my $defvendorid = $self->{'handle'}->lookup_id($solv::SOLVID_META, $solv::SUSETAGS_DEFAULTVENDOR);
418 my $descrdir = $self->{'handle'}->lookup_str($solv::SOLVID_META, $solv::SUSETAGS_DESCRDIR) || 'suse/setup/descr';
419 my ($filename, $filechksum) = $self->find('packages.gz');
420 ($filename, $filechksum) = $self->find('packages') unless $filename;
422 $f = $self->download("$descrdir/$filename", 1, $filechksum, 1);
424 $self->{'handle'}->add_susetags($f, $defvendorid, undef, $solv::Repo::REPO_NO_INTERNALIZE|$solv::Repo::SUSETAGS_RECORD_SHARES);
425 ($filename, $filechksum) = $self->find('packages.en.gz');
426 ($filename, $filechksum) = $self->find('packages.en') unless $filename;
428 $f = $self->download("$descrdir/$filename", 1, $filechksum, 1);
430 $self->{'handle'}->add_susetags($f, $defvendorid, undef, $solv::Repo::REPO_NO_INTERNALIZE|$solv::Repo::REPO_REUSE_REPODATA|$solv::Repo::REPO_EXTEND_SOLVABLES);
433 $self->{'handle'}->internalize();
437 $self->writecachedrepo();
438 $self->{'handle'}->create_stubs();
444 return ($self->{'handle'}->lookup_str($solv::SOLVID_META, $solv::SUSETAGS_DATADIR) || 'suse') . '/';
447 package Repo::unknown;
449 our @ISA = ('Repo::generic');
452 my ($self, $pool) = @_;
453 print "unsupported repo '$self->{'alias'}': skipped\n";
457 package Repo::system;
459 our @ISA = ('Repo::generic');
462 my ($self, $pool) = @_;
464 $self->{'handle'} = $pool->add_repo($self->{'alias'});
465 $self->{'handle'}->{'appdata'} = $self;
466 $pool->{'installed'} = $self->{'handle'};
467 print "rpm database: ";
468 $self->{'cookie'} = $self->calc_cookie_file('/var/lib/rpm/Packages');
469 if ($self->usecachedrepo()) {
474 if (defined(&solv::Repo::add_products)) {
475 $self->{'handle'}->add_products("/etc/products.d", $solv::Repo::REPO_NO_INTERNALIZE);
477 $self->{'handle'}->add_rpmdb(undef, $solv::Repo::REPO_REUSE_REPODATA);
478 $self->writecachedrepo();
486 my $repo = $repodata->{'repo'}->{'appdata'};
487 return $repo ? $repo->load_ext($repodata) : 0;
490 die("Usage: p5solv COMMAND [ARGS]\n") unless @ARGV;
491 my $cmd = shift @ARGV;
492 $cmd = 'list' if $cmd eq 'li';
493 $cmd = 'install' if $cmd eq 'in';
494 $cmd = 'erase' if $cmd eq 'rm';
495 $cmd = 'verify' if $cmd eq 've';
496 $cmd = 'search' if $cmd eq 'se';
500 if (-d '/etc/zypp/repos.d') {
501 @reposdirs = ( '/etc/zypp/repos.d' );
503 @reposdirs = ( '/etc/yum/repos.d' );
505 for my $reposdir (@reposdirs) {
506 next unless -d $reposdir;
507 next unless opendir(DIR, $reposdir);
508 for my $reponame (sort(grep {/\.repo$/} readdir(DIR))) {
509 my $cfg = new Config::IniFiles('-file' => "$reposdir/$reponame");
510 for my $alias ($cfg->Sections()) {
511 my $repoattr = {'alias' => $alias, 'enabled' => 0, 'priority' => 99, 'autorefresh' => 1, 'type' => 'rpm-md', 'metadata_expire' => 900};
512 for my $p ($cfg->Parameters($alias)) {
513 $repoattr->{$p} = $cfg->val($alias, $p);
516 if ($repoattr->{'type'} eq 'rpm-md') {
517 $repo = Repo::rpmmd->new($alias, 'repomd', $repoattr);
518 } elsif ($repoattr->{'type'} eq 'yast2') {
519 $repo = Repo::susetags->new($alias, 'susetags', $repoattr);
521 $repo = Repo::unknown->new($alias, 'unknown', $repoattr);
528 my $pool = solv::Pool->new();
530 $pool->set_loadcallback(\&load_stub);
532 my $sysrepo = Repo::system->new('@System', 'system');
533 $sysrepo->load($pool);
534 for my $repo (@repos) {
535 $repo->load($pool) if $repo->{'enabled'};
538 if ($cmd eq 'search') {
540 my $di = $pool->Dataiterator(0, $solv::SOLVABLE_NAME, $ARGV[0], $solv::Dataiterator::SEARCH_SUBSTRING | $solv::Dataiterator::SEARCH_NOCASE);
542 $matches{$d->{'solvid'}} = 1;
544 for my $solvid (sort keys %matches) {
545 my $s = $pool->{'solvables'}->[$solvid];
546 print "- ".$s->str()." [$s->{'repo'}->{'name'}] ".$s->lookup_str($solv::SOLVABLE_SUMMARY)."\n";
551 my @addedprovides = $pool->addfileprovides_queue();
552 $pool->createwhatprovides();
555 for my $arg (@ARGV) {
556 my $flags = $solv::Selection::SELECTION_NAME | $solv::Selection::SELECTION_PROVIDES | $solv::Selection::SELECTION_GLOB;
558 $flags |= $solv::Selection::SELECTION_FILELIST;
559 $flags |= $solv::Selection::SELECTION_INSTALLED_ONLY if $cmd eq 'erase';
561 my $sel = $pool->select($arg, $flags);
562 if ($sel->isempty()) {
563 $sel = $pool->select($arg, $flags | $solv::Selection::SELECTION_NOCASE);
564 print "[ignoring case for '$arg']\n" unless $sel->isempty();
566 die("nothing matches '$arg'\n") if $sel->isempty();
567 print "[using file list match for '$arg']\n" if $sel->flags() & $solv::Selection::SELECTION_FILELIST;
568 print "[using capability match for '$arg']\n" if $sel->flags() & $solv::Selection::SELECTION_PROVIDES;
569 push @jobs, $sel->jobs(0);
571 if (!@jobs && ($cmd eq 'up' || $cmd eq 'dup' || $cmd eq 'verify')) {
572 my $sel = $pool->Selection();
573 $sel->addsimple($solv::Job::SOLVER_SOLVABLE_ALL, 0);
574 push @jobs, $sel->jobs(0);
577 if ($cmd eq 'list' || $cmd eq 'info') {
578 die("no package matched.\n") unless @jobs;
579 for my $job (@jobs) {
580 for my $s ($job->solvables()) {
581 if ($cmd eq 'info') {
582 printf "Name: %s\n", $s->str();
583 printf "Repo: %s\n", $s->{'repo'}->{'name'};
584 printf "Summary: %s\n", $s->lookup_str($solv::SOLVABLE_SUMMARY);
585 my $str = $s->lookup_str($solv::SOLVABLE_URL);
586 printf "Url: %s\n", $str if $str;
587 $str = $s->lookup_str($solv::SOLVABLE_LICENSE);
588 printf "License: %s\n", $str if $str;
589 printf "Description:\n%s\n", $s->lookup_str($solv::SOLVABLE_DESCRIPTION);
591 printf " - %s [%s]\n", $s->str(), $s->{'repo'}->{'name'};
592 printf " %s\n", $s->lookup_str($solv::SOLVABLE_SUMMARY);
599 if ($cmd eq 'install' || $cmd eq 'erase' || $cmd eq 'up' || $cmd eq 'dup' || $cmd eq 'verify') {
600 die("no package matched.\n") unless @jobs;
601 for my $job (@jobs) {
603 if ($job->{'how'} == $solv::Job::SOLVER_SOLVABLE_ALL || grep {$_->isinstalled()} $job->solvables()) {
604 $job->{'how'} |= $solv::Job::SOLVER_UPDATE;
606 $job->{'how'} |= $solv::Job::SOLVER_INSTALL;
608 } elsif ($cmd eq 'install') {
609 $job->{'how'} |= $solv::Job::SOLVER_INSTALL;
610 } elsif ($cmd eq 'erase') {
611 $job->{'how'} |= $solv::Job::SOLVER_ERASE;
612 } elsif ($cmd eq 'dup') {
613 $job->{'how'} |= $solv::Job::SOLVER_DISTUPGRADE;
614 } elsif ($cmd eq 'verify') {
615 $job->{'how'} |= $solv::Job::SOLVER_VERIFY;
620 $solver = $pool->Solver();
621 $solver->set_flag($solv::Solver::SOLVER_FLAG_SPLITPROVIDES, 1);
622 $solver->set_flag($solv::Solver::SOLVER_FLAG_ALLOW_UNINSTALL, 1) if $cmd eq 'erase';
623 my @problems = $solver->solve(\@jobs);
624 last unless @problems;
625 for my $problem (@problems) {
626 print "Problem $problem->{'id'}/".@problems.":\n";
627 my $r = $problem->findproblemrule();
629 print $ri->problemstr()."\n";
630 my @solutions = $problem->solutions();
631 for my $solution (@solutions) {
632 print " Solution $solution->{'id'}:\n";
633 for my $element ($solution->elements(1)) {
634 print " - ".$element->str()."\n";
640 print "Please choose a solution: ";
643 last if $sol eq 's' || $sol eq 'q' || ($sol =~ /^\d+$/ && $sol >= 1 && $sol <= @solutions);
646 exit(1) if $sol eq 'q';
647 my $solution = $solutions[$sol - 1];
648 for my $element ($solution->elements()) {
649 my $newjob = $element->Job();
650 if ($element->{'type'} == $solv::Solver::SOLVER_SOLUTION_JOB) {
651 $jobs[$element->{'jobidx'}] = $newjob;
653 push @jobs, $newjob if $newjob && !grep {$_ == $newjob} @jobs;
658 my $trans = $solver->transaction();
660 if ($trans->isempty()) {
661 print "Nothing to do.\n";
664 print "\nTransaction summary:\n\n";
665 for my $c ($trans->classify()) {
666 if ($c->{'type'} == $solv::Transaction::SOLVER_TRANSACTION_ERASE) {
667 print "$c->{'count'} erased packages:\n";
668 } elsif ($c->{'type'} == $solv::Transaction::SOLVER_TRANSACTION_INSTALL) {
669 print "$c->{'count'} installed packages:\n";
670 } elsif ($c->{'type'} == $solv::Transaction::SOLVER_TRANSACTION_REINSTALLED) {
671 print "$c->{'count'} reinstalled packages:\n";
672 } elsif ($c->{'type'} == $solv::Transaction::SOLVER_TRANSACTION_DOWNGRADED) {
673 print "$c->{'count'} downgraded packages:\n";
674 } elsif ($c->{'type'} == $solv::Transaction::SOLVER_TRANSACTION_CHANGED) {
675 print "$c->{'count'} changed packages:\n";
676 } elsif ($c->{'type'} == $solv::Transaction::SOLVER_TRANSACTION_UPGRADED) {
677 print "$c->{'count'} upgraded packages:\n";
678 } elsif ($c->{'type'} == $solv::Transaction::SOLVER_TRANSACTION_VENDORCHANGE) {
679 printf "$c->{'count'} vendor changes from '%s' to '%s':\n", $c->fromdep()->str(), $c->todep()->str();
680 } elsif ($c->{'type'} == $solv::Transaction::SOLVER_TRANSACTION_ARCHCHANGE) {
681 printf "$c->{'count'} arch changes from '%s' to '%s':\n", $c->fromdep()->str(), $c->todep()->str();
685 for my $p ($c->solvables()) {
686 if ($c->{'type'} == $solv::Transaction::SOLVER_TRANSACTION_UPGRADED || $c->{'type'} == $solv::Transaction::SOLVER_TRANSACTION_DOWNGRADED) {
687 my $other = $trans->othersolvable($p);
688 printf " - %s -> %s\n", $p->str(), $other->str();
690 printf " - %s\n", $p->str();
695 printf "install size change: %d K\n\n", $trans->calc_installsizechange();
697 print("OK to continue (y/n)? ");
701 exit(1) if $yn eq 'n';
703 my @newpkgs = $trans->newpackages();
706 my $downloadsize = 0;
707 $downloadsize += $_->lookup_num($solv::SOLVABLE_DOWNLOADSIZE) for @newpkgs;
708 printf "Downloading %d packages, %d K\n", scalar(@newpkgs), $downloadsize;
709 for my $p (@newpkgs) {
710 my $repo = $p->{'repo'}->{'appdata'};
711 my ($location, $medianr) = $p->lookup_location();
712 next unless $location;
713 $location = $repo->packagespath() . $location;
714 my $chksum = $p->lookup_checksum($solv::SOLVABLE_CHECKSUM);
715 my $f = $repo->download($location, 0, $chksum);
716 die("\n$repo->{'alias'}: $location not found in repository\n") unless $f;
717 $newpkgsfps{$p->{'id'}} = $f;
723 print "Committing transaction:\n\n";
725 for my $p ($trans->steps()) {
726 my $steptype = $trans->steptype($p, $solv::Transaction::SOLVER_TRANSACTION_RPM_ONLY);
727 if ($steptype == $solv::Transaction::SOLVER_TRANSACTION_ERASE) {
728 print "erase ".$p->str()."\n";
729 next unless $p->lookup_num($solv::RPM_RPMDBID);
730 my $evr = $p->{'evr'};
731 $evr =~ s/^[0-9]+://; # strip epoch
732 system('rpm', '-e', '--nodeps', '--nodigest', '--nosignature', "$p->{'name'}-$evr.$p->{'arch'}") && die("rpm failed: $?\n");
733 } elsif ($steptype == $solv::Transaction::SOLVER_TRANSACTION_INSTALL || $steptype == $solv::Transaction::SOLVER_TRANSACTION_MULTIINSTALL) {
734 print "install ".$p->str()."\n";
735 my $f = $newpkgsfps{$p->{'id'}};
736 my $mode = $steptype == $solv::Transaction::SOLVER_TRANSACTION_INSTALL ? '-U' : '-i';
737 system('rpm', $mode, '--force', '--nodeps', '--nodigest', '--nosignature', "/dev/fd/".$f->fileno()) && die("rpm failed: $?\n");
738 delete $newpkgsfps{$p->{'id'}};