aboutsummaryrefslogtreecommitdiffstats
path: root/URPM.pm
blob: 51ba47a64782df922ade10c06067d47debb00748 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
package URPM;

use strict;
use warnings;
use DynaLoader;

# Make sure debugging with Data::Dumper is more easily comparable:
$Data::Dumper::Sortkeys = 1;

# different files, but same package
# require them here to avoid dependencies
use URPM::Build;
use URPM::Resolve;
use URPM::Signature;

our @ISA = qw(DynaLoader);
our $VERSION = 'v5.122';

URPM->bootstrap($VERSION);

sub new {
    my ($class, %options) = @_;
    my $self = bless {
	depslist => [],
	provides => {},
	obsoletes => {},
    }, $class;
    $self->{nofatal} = 1 if $options{nofatal};
    $self;
}

sub set_nofatal {
    my ($urpm, $bool) = @_;
    $urpm->{nofatal} = $bool }

sub packages_providing {
    my ($urpm, $name) = @_;
    grep { $_ } map { $urpm->{depslist}[$_] } sort { $a <=> $b } keys %{$urpm->{provides}{$name} || {}};
}

sub packages_obsoleting {
    my ($urpm, $name) = @_;
    map { $urpm->{depslist}[$_] } keys %{$urpm->{obsoletes}{$name} || {}};
}

sub packages_by_name {
    my ($urpm, $name) = @_;
    grep { $name eq $_->name } packages_providing($urpm, $name);
}

sub search {
    my ($urpm, $name, %options) = @_;
    my $best;

    #- tries other alternative if no strict searching.
    unless ($options{strict_name}) {
	if ($name =~ /^(.*)-([^\-]*)-([^\-]*)\.([^\.\-]*)$/) {
	    foreach my $pkg (packages_providing($urpm, $1)) {
		$pkg->fullname eq $name and return $pkg;
	    }
	}
	unless ($options{strict_fullname}) {
	    if ($name =~ /^(.*)-([^\-]*)-([^\-]*)$/) {
		foreach my $pkg (packages_providing($urpm, $1)) {
		    my ($n, $v, $r, $a) = $pkg->fullname;
		    $options{src} && $a eq 'src' || $pkg->is_arch_compat or next;
		    "$n-$v-$r" eq $name or next;
		    !$best || $pkg->compare_pkg($best) > 0 and $best = $pkg;
		}
		$best and return $best;
	    }
	    if ($name =~ /^(.*)-([^\-]*)$/) {
		foreach my $pkg (packages_providing($urpm, $1)) {
		    my ($n, $v, undef, $a) = $pkg->fullname;
		    $options{src} && $a eq 'src' || $pkg->is_arch_compat or next;
		    "$n-$v" eq $name or next;
		    !$best || $pkg->compare_pkg($best) > 0 and $best = $pkg;
		}
		$best and return $best;
	    }
	}
    }

    unless ($options{strict_fullname}) {
	foreach my $pkg (packages_providing($urpm, $name)) {
	    my ($n, undef, undef, $a) = $pkg->fullname;
	    $options{src} && $a eq 'src' || $pkg->is_arch_compat or next;
	    $n eq $name or next;
	    !$best || $pkg->compare_pkg($best) > 0 and $best = $pkg;
	}
    }

    return $best;
}

#- Olivier Thauvin:
#- Returns @$listid, $start .. $end or the whole deplist id
#- according to the given args
sub build_listid {
    my ($urpm, $start, $end, $listid) = @_;

    @{$listid || []} > 0 ? @$listid :
        (($start || 0) .. (defined($end) ? $end : $#{$urpm->{depslist}}));
}

#- this is used when faking a URPM::DB: $urpm can be used as-a $db
#- (used for urpmi --env)
sub traverse {
    my ($urpm, $callback) = @_;

    if ($callback) {
	foreach my $p (@{$urpm->{depslist} || []}) {
	    $callback->($p);
	}
    }

    scalar @{$urpm->{depslist} || []};
}


#- this is used when faking a URPM::DB: $urpm can be used as-a $db
#- (used for urpmi --env)
sub traverse_tag {
    my ($urpm, $tag, $names, $callback) = @_;
    my $count = 0; 
    my %names;

    if (@{$names || []}) {
	if ($tag eq 'name') {
	    foreach my $n (@$names) {
		foreach my $p (packages_providing($urpm, $n)) {
		    $p->name eq $n or next;
		    $callback and $callback->($p);
		    ++$count;
		}
	    }
	} elsif ($tag eq 'whatprovides') {
	    foreach (@$names) {
		foreach (keys %{$urpm->{provides}{$_} || {}}) {
		    $callback and $callback->($urpm->{depslist}[$_]);
		    ++$count;
		}
	    }
	} else {
	    @names{@$names} = ();
	    if ($tag eq 'whatrequires') {
		foreach (@{$urpm->{depslist} || []}) {
		    if (grep { exists $names{$_} } $_->requires_nosense) {
			$callback and $callback->($_);
			++$count;
		    }
		}
	    } elsif ($tag eq 'whatconflicts') {
		foreach (@{$urpm->{depslist} || []}) {
		    if (grep { exists $names{$_} } $_->conflicts_nosense) {
			$callback and $callback->($_);
			++$count;
		    }
		}
	    } elsif ($tag eq 'group') {
		foreach (@{$urpm->{depslist} || []}) {
		    if (exists $names{$_->group}) {
			$callback and $callback->($_);
			++$count;
		    }
		}
	    } elsif ($tag eq 'triggeredby' || $tag eq 'path') {
		foreach (@{$urpm->{depslist} || []}) {
		    if (grep { exists $names{$_} } $_->files, grep { m!^/! } $_->provides_nosense) {
			$callback and $callback->($_);
			++$count;
		    }
		}
	    } else {
		die "unknown tag";
	    }
	}
    }

    $count;
}

#- this is used when faking a URPM::DB: $urpm can be used as-a $db
#- (used for urpmi --env)
sub traverse_tag_find {
    my ($urpm, $tag, $name, $callback) = @_;
    $urpm->traverse_tag($tag, [ $name ], $callback);
}


#- this is used when faking a URPM::DB: $urpm can be used as-a $db
#- (used for urpmi --env)
sub create_transaction {
    my ($_urpm) = @_; # same args as URPM.xs:create_transaction()
    die "Installing is not supported with a fake environment!";
}

# wrapper around XS functions
# it handles error cases
sub _parse_hdlist_or_synthesis {
    my ($parse_func, $urpm, $file, %options) = @_;

    my $previous_indice = @{$urpm->{depslist}};
    if (my ($start, $end) = $parse_func->($urpm, $file, %options)) {
	($start, $end);
    } elsif (!$options{callback}) {
	#- parse_hdlist__XS may have added some pkgs to {depslist},
	#- but we don't want those pkgs since reading hdlist failed later.
	#- so we need to drop them
	#- FIXME: {provides} would need to be reverted too!
	splice(@{$urpm->{depslist}}, $previous_indice);
	();
    } else {
	#- we need to keep them since the callback has been used
	#- and we can't pretend we didn't parse anything
	#- (needed for genhdlist2)
	();
    }
}
sub parse_synthesis { _parse_hdlist_or_synthesis(\&parse_synthesis__XS, @_) }
sub parse_hdlist { _parse_hdlist_or_synthesis(\&parse_hdlist__XS, @_) }

sub add_macro {
    my ($s) = @_;
    #- quote for rpmlib, *sigh*
    $s =~ s/\n/\\\n/g;
    add_macro_noexpand($s);
}

package URPM::Package;
our @ISA = qw(); # help perl_checker

#- debug help for urpmi
sub dump_flags {
    my ($pkg) = @_;
    <<EODUMP;
available:	  ${\($pkg->flag_available)}
base:		  ${\($pkg->flag_base)}
disable_obsolete: ${\($pkg->flag_disable_obsolete)}
installed:	  ${\($pkg->flag_installed)}
requested:	  ${\($pkg->flag_requested)}
required:	  ${\($pkg->flag_required)}
selected:	  ${\($pkg->flag_selected)}
skip:		  ${\($pkg->flag_skip)}
upgrade:	  ${\($pkg->flag_upgrade)}
EODUMP
}

my %arch_cache;
sub is_arch_compat {
    my ($pkg) = @_;
    my $arch = $pkg->arch;
    exists $arch_cache{$arch} and return $arch_cache{$arch};

    $arch_cache{$arch} = is_arch_compat__XS($pkg);
}

sub changelogs {
    my ($pkg) = @_;

    my @ti = $pkg->changelog_time or return;
    my @na = $pkg->changelog_name or return;
    my @tx = $pkg->changelog_text or return;
    map {
	{ time => $ti[$_], name => $na[$_], text => $tx[$_] };
    } 0 .. $#ti;
}

package URPM::Transaction;
our @ISA = qw(); # help perl_checker

package URPM::DB;
our @ISA = qw(); # help perl_checker

1;

__END__

=head1 NAME

URPM - Manipulate RPM files and headers

=head1 SYNOPSIS

    use URPM;

    # using the local RPM database
    my $db = URPM::DB::open();
    $db->traverse(sub {
	my ($package) = @_; # this is a URPM::Package object
	print $package->name, "\n";
	# ...
    });

    # loading and parsing a synthesis file
    my $urpm = new URPM;
    $urpm->parse_synthesis("synthesis.sample.cz");
    $urpm->traverse(sub {
	# retrieve all packages from the dependency list
	# ...
    });

=head1 DESCRIPTION

The URPM module allows you to manipulate RPM files, RPM header files and
hdlist files and manage them in memory. It is notably used by the L<urpmi>
utility. It provides four classes : C<URPM>, C<URPM::DB>, C<URPM::Package>,
and C<URPM::Transaction>.

=head2 The URPM class

=head3 Initialization

=over 4

=item URPM->new()

The constructor creates a new, empty URPM object. It's a blessed hash that
contains three fields:

=over

=item *

B<depslist> is an arrayref containing the list of depending packages (which are
C<URPM::Package> objects).

=item *

B<obsoletes> is an hashref containing as keys the list of property names
obsoleted by the URPM object.

=item *

B<provides> is an hashref containing as keys the list of property names
provided by the URPM object. The associated value is true if the property is
versioned.

=back

If the constructor is called with the arguments C<< nofatal => 1 >>, various
fatal error messages are suppressed (file not found in parse_hdlist() and
parse_synthesis()).

=item URPM::read_config_files()

Force the re-reading of the RPM configuration files.

=back

=head3 Loading packages data

$urpm->{depslist} is loaded when parsing sources (synthesis, hdlists or a plain
rpm file).

Synthesis and hdlists files are generated by L<genhdlist2> or L<gendistrib> (a
gendhlist2 wrapper handling a whole media set) from L<rpmtools> package.

=over

=item $urpm->parse_synthesis($file [, callback => sub {...} ])

This method gets the B<depslist> and the B<provides> from a synthesis file
and adds them to the URPM object.

Callback signature is callback(C<URPM>, C<URPM::Package>).

The return value is a two-element array containing the first and the last id
parsed.

=item $urpm->parse_hdlist($file, %options)

This method loads rpm informations from rpm headers contained in an hdlist
file and adds them to the URPM object. Allowed options are 

    packing => 0 / 1
    callback => sub { ... }
    keep_all_tags => 0 / 1

Callback signature is callback(C<URPM>, C<URPM::Package>).

The return value is a two-element array containing the first and the last id
parsed.

=item $urpm->parse_rpm($file, %options)

This method gets the B<depslist> and the B<provides> from an RPM file
and adds them to the URPM object. Allowed options are

    packing => 0 / 1
    keep_all_tags => 0 / 1
    callback => sub { ... }

If C<keep_all_tags> isn't specified, URPM will drop all memory-consuming tags
(notably changelogs, filelists, scriptlets).

Callback signature is callback(URPM::Package).

=back

=head3 Searching packages

=over

=item URPM::ranges_overlap($range1, $range2)

This utility function compares two version ranges, in order to calculate
dependencies properly. The ranges have roughly the form

    [<|<=|==|=>|>] [epoch:]version[-release]

where epoch, version and release are RPM-style version numbers.

=item $urpm->packages_providing($name)

Returns a list of C<URPM::Package> providing <$name>

=item $urpm->packages_by_name($name)

Returns a list of C<URPM::Package> corresponding to the wanted <$name>

=item $urpm->search($name, %options)

Search an RPM by name or by part of name in the list of RPMs represented by
this $urpm. The behaviour of the search is influenced by several options:

=over

=item  strict_name only match short name (N) =>  0 / 1

=item strict_fullname only match fullname (NVRA) (fast) => 0 / 1

=item src => look only for srpms => 0 / 1

=back

=back

=head3 Debuging

These are used when faking a URPM::DB: $urpm can be used as-a $db

=over

=item $urpm->traverse($callback)

Executes the callback for each package in the depslist, passing a
C<URPM::Package> object as argument the callback.

=item $urpm->traverse_tag($tag, $names, $callback)

$tag may be one of C<name>, C<whatprovides>, C<whatrequires>, C<whatconflicts>,
C<group>, C<triggeredby>, or C<path>.
$names is a reference to an array, holding the acceptable values of the said
tag for the searched variables.
Then, $callback is called for each matching package in the depslist.

Callback signature is callback(URPM::Package).

=item $urpm->traverse_tag_find($tag,$name,$callback)

Quite similar to C<traverse_tag>, but stops when $callback returns true.

(also note that only one $name is handled)

Callback signature is callback(URPM::Package).

=back

=head3 Checking packages

=over

=item URPM::verify_rpm($file, %options)

Verifies an RPM file.
Returns 0 on failure, 1 on success.
Recognized options are:

    nodigests => 0 / 1
    nosignatures => 0 / 1

=item URPM::verify_signature($file)

Verifies the signature of an RPM file. Returns a string that will contain "OK"
or "NOT OK" as well as a description of the found key (if successful) or of the
error (if signature verification failed.)

=item $urpm->import_pubkey(%options)

Imports a key in the RPM database.

    db => $urpm_db
    root => '...'
    block => '...'
    filename => '...'

=back

=head2 The URPM::DB class

=over 4

=item open($prefix, $write_perm)

Returns a new C<URPM::DB> object pointing on the local RPM database (or
C<undef> on failure).

$prefix defaults to C<""> and indicates the RPM DB root directory prefix if
any. (See the B<--root> option to rpm(1)).

$write_perm is a boolean that defaults to false, and that indicates whether
the RPM DB should be open in read/write mode.

=item rebuild($prefix)

Rebuilds the RPM database (like C<rpm --rebuilddb>). $prefix defaults to C<"">.

=item verify($prefix)

Verify the RPM database (like C<rpmdb --verify>). $prefix defaults to C<"">.

=item $db->traverse($callback)

Executes the specified callback (a code reference) for each package
in the DB, passing a C<URPM::Package> object as argument the callback.

Returns the number of packages seen (all).

=item $db->traverse_tag($tag,$names,$callback)

$tag may be one of C<name>, C<whatprovides>, C<whatrequires>, C<whatconflicts>,
C<group>, C<triggeredby>, or C<path>.
$names is a reference to an array, holding the acceptable values of the said
tag for the searched variables.
Then, $callback is called for each matching package in the DB.

Callback signature is callback(URPM::Package).

Returns the number of packages seen (all those that matched provided names).

=item $db->traverse_tag_find($tag,$name,$callback)

Quite similar to C<traverse_tag>, but stops when $callback returns true.

(also note that only one $name is handled)

Callback signature is callback(URPM::Package).

Returns whether callback returned true once.

=item $db->create_transaction()

Creates and returns a new transaction (an C<URPM::Transaction> object) on the
specified DB.

=back

=head2 The URPM::Package class

=head3 Getting a URPM::Package object

URPM::Package objects are usually retrieved from $urpm->{depslist} after
having loaded either the RPM DB and/or synthesis files.

It's also possible to get such an object with:

=over

=item URPM::spec2srcheader($specfile)

Returns a URPM::Package object containing the header of the source rpm produced
by the evaluation of the specfile whose path is given as argument. All
dependencies stored in this header are exactly the one needed to build the
specfile.

=item URPM::stream2header($fp)

Returns a URPM::Package object containing the header read from $fp.

=back

=head3 Methods

Most methods of C<URPM::Package> are accessors for the various properties
of an RPM package.

=over 4

=item $package->arch()

Gives the package architecture

=item $package->build_header($fileno)

Writes the rpm header to the specified file ($fileno being an integer).

=item $package->build_info($fileno, [$provides_files])

Writes a line of information in a synthesis file.

=item $package->buildarchs()

=item $package->buildhost()

=item $package->buildtime()

=item $package->changelog_name()

=item $package->changelog_text()

=item $package->changelog_time()

=item $package->compare($evr)

=item $package->compare_pkg($other_pkg)

=item $package->conf_files()

=item $package->conflicts()

Full conflicts tags

=item $package->conflicts_nosense()

Just the conflicted package name.
This is only used when faking a URPM::DB: $urpm can be used as-a $db

=item $package->description()

=item $package->dirnames()

=item $package->distribution()

=item $package->epoch()

=item $package->EVR()

=item $package->excludearchs()

=item $package->exclusivearchs()

=item $package->filelinktos()

=item $package->files()

List of files in this rpm.

=item $package->files_flags()

=item $package->files_gid()

=item $package->files_group()

=item $package->files_md5sum()

=item $package->files_mode()

=item $package->files_mtime()

=item $package->files_owner()

=item $package->files_size()

=item $package->files_uid()

=item $package->flag($name)

=item $package->flag_available()

=item $package->flag_base()

=item $package->flag_disable_obsolete()

=item $package->flag_installed()

=item $package->flag_requested()

=item $package->flag_required()

=item $package->flag_selected()

=item $package->flag_skip()

=item $package->flag_upgrade()

=item $package->free_header()

=item $package->fullname()

Returns a 4 element list: name, version, release and architecture in an array
context. Returns a string NAME-VERSION-RELEASE.ARCH in scalar context.

=item $package->get_tag($tagid)

Returns an array containing values of $tagid. $tagid is the numerical value of
rpm tags. See rpmlib.h. 

=item $package->queryformat($format)

Querying the package like rpm --queryformat do. 

The function calls directly the rpmlib, then use header informations, so it 
silently failed if you use synthesis instead of hdlist/rpm/header files or rpmdb.

=item $package->get_tag_modifiers($tagid)

Return an array of human readable view of tag values. $tagid is the numerical value of rpm tags.

=item $package->group()

=item $package->id()

=item $package->installtid()

=item $package->is_arch_compat()

Returns whether this package is compatible with the current machine's
architecture. 0 means not compatible. The lower the result is, the preferred
the package is.

=item $package->license()

=item $package->name()

The rpm's bare name.

=item $package->obsoletes()

Full obsoletes tags

=item $package->obsoletes_nosense()

Just the obsoleted package name.

=item $package->obsoletes_overlap($s)

=item $package->os()

=item $package->pack_header()

If a header is associated with the package, fill the package fields from
the header's tags (NEVRA,
requires/recommends/obsoletes/conflicts/provides/summary)
then free the header

It's useful when traversing the rpm DB, if one wants to keep around a
package from the DB
else the info would not be available outside the traverse_*() function.

It's also useful when creating a URPM_Package from a package file in
order to shrink memory footprint.

=item $package->packager()

=item $package->payload_format()

=item $package->provides()

Full provides tags

=item $package->provides_nosense()

Just the provided package name.

=item $package->provides_overlap($s)

=item $package->rate()

=item $package->release()

=item $package->requires()

=item $package->recommends()

Full requires tags

=item $package->requires_nosense()

Just the required package name.

=item $package->recommends_nosense()

=item $package->rflags()

=item $package->filesize()

Size of the rpm file (ie the rpm header + cpio body)

=item $package->set_flag($name, $value)

=item $package->set_flag_base($value)

=item $package->set_flag_disable_obsolete($value)

=item $package->set_flag_installed($value)

=item $package->set_flag_requested($value)

=item $package->set_flag_required($value)

=item $package->set_flag_skip($value)

=item $package->set_flag_upgrade($value)

=item $package->set_id($id)

=item $package->set_rate($rate)

=item $package->set_rflags(...)

=item $package->size()

=item $package->sourcerpm()

=item $package->summary()

=item $package->update_header($filename, ...)

=item $package->url()

=item $package->vendor()

=item $package->version()

=back

=head2 The URPM::Transaction class

=over 4

=item $trans->set_script_fd($fileno)

Sets the transaction output filehandle.

=item $trans->add($pkg, %options)

Adds a package to be installed to the transaction represented by $trans.
$pkg is an C<URPM::Package> object.

Options are:

    update => 0 / 1 : indicates whether this is an upgrade
    excludepath => [ ... ]

=item $trans->addReinstall($pkg)

Adds a package to be re-installed to the transaction represented by $trans.
$pkg is an C<URPM::Package> object.

=item $trans->remove($name)

Adds a package to be erased to the transaction represented by $trans.
$name is the name of the package.

=item $trans->check(%options)

Checks that all dependencies can be resolved in this transaction.

Options are:

    translate_message => 0 / 1 (currently ignored.)

In list context, returns an array of problems (an empty array indicates
success).

=item $trans->order()

Determines package order in a transaction set according to dependencies. In
list context, returns an array of problems (an empty array indicates success).

=item $trans->run($data, %options)

Runs the transaction.

$data is an arbitrary user-provided piece of data to be passed to callbacks.
It's usually the $urpm object.

Recognized options are:

    callback_close  => sub { ... }
    callback_elem   => sub { ... }
    callback_error  => sub { ... }
    callback_inst   => sub { ... }
    callback_open   => sub { ... }
    callback_trans  => sub { ... }
    callback_uninst => sub { ... }
    callback_verify => sub { ... }
    delta => used for progress callbacks (trans, uninst, inst)
    excludedocs => 0 / 1
    force => 0 / 1
    ignorearch => 0 / 1
    nosize => 0 / 1
    noscripts => 0 / 1
    oldpackage => 0 / 1
    test => 0 / 1
    translate_message => 1

They roughly correspond to command-line options to rpm(1).

'callback_open' signature is (C<$data>, C<$cb_type>, C<$pkg_id>). It _must_ return a file handler for the asked package.

'callback_close' signature is (C<$data>, C<$cb_type>, C<$pkg_id>). It is called just before URPM close the fd for the installed package.

C<$cb_type> is one of 'open' or 'close'.

Other Callbacks signature is callback(C<$data>, C<$cb_type>, C<$pkg_id>, C<$subtype>, C<$amout>, C<$total>)

C<$cb_type> is one of 'elem', 'error', 'inst', 'trans' or 'uninst'. C<$subtype> can be 'start', 'progress' or 'stop'.
For 'error', it can be 'cpio', 'script' or 'unpack'.

The purpose of those callbacks is to report progress (the two last parameters (C<$amount> & C<$total>) enable to compute progress percentage).

=item $trans->traverse($callback)

Executes the specified callback (a code reference) for each package in the
transaction, passing a C<URPM::Package> object as argument the callback.

=back

=head3 Transaction Element management

=over 4

=item $trans->NElements($fileno)

Returns the number of elements in the transaction.

=item $trans->Element_version($index)

Returns the version of the $index-th element in the transaction.

=item $trans->Element_release($index)

Returns the release of the $index-th element in the transaction.

=item $trans->Element_fullname($index)

Returns the fullname of the $index-th element in the transaction.

=back

=head2 Macro handling functions

=over

=item loadmacrosfile($filename)

Load the specified macro file. Sets $! if the file can't be read.

=item expand($name)

Expands the specified macro.

=item add_macro($macro_definition)

=item add_macro_noexpand($macro_definition)

Define a macro. For example,

    URPM::add_macro("vendor Mageia");
    my $vendor = URPM::expand("%vendor");

The 'noexpand' version doesn't expand literal newline characters in the
macro definition.

=item del_macro($name)

Delete a macro.

=item resetmacros()

Destroys macros.

=back

=head2 Misc other functions

=over

=item setVerbosity($level)

Sets rpm verbosity level. $level is an integer between 2 (RPMMESS_CRIT) and 7
(RPMMESS_DEBUG).

=item rpmErrorString()

=item rpmErrorWriteTo($fd)

=item archscore($arch)

Return the score of the given arch. 0 mean not compatible,
lower is prefered.

=item osscore($os)

Return the score of the given os. 0 mean not compatible,
lower is prefered.

=back

=head2 The $state object

It has the following fields:

B<backtrack>: { 
   selected => { id => undef }, 
   deadlock => { id|property => undef },
 }

B<cached_installed>: { property_name => { fullname => undef } }

B<oldpackage>: int
   # will be passed to $trans->run to set RPMPROB_FILTER_OLDPACKAGE

B<selected>: { id => { 
     requested => bool, install => bool,
     from => pkg, psel => pkg,
     promote => name, unsatisfied => [ id|property ]
 } }

B<rejected>: { fullname => { 
     size => int, removed => { fullname|"asked" => undef },
     obsoleted => { fullname|"asked" => undef },
     backtrack => { # those info are only used to display why package is unselected
         promote => [ name ], keep => [ fullname ], 
         unsatisfied => [ id|property ], 
         conflicts => [ fullname ],
     },
     closure => { fullname => { old_requested => bool, 
                                unsatisfied => [ id|property ],
                                conflicts => property },
                                avoid => bool },
     },
 } }

B<rejected_already_installed>: { id => pkg }

B<orphans_to_remove>: [ pkg ]

B<whatrequires>: { name => { id => undef } }
   # reversed requires_nosense for selected packages

B<unselected_uninstalled>: [ pkg ]
   # (old) packages which are needed, but installed package is newer

more fields only used in build_transaction_set and its callers):

B<transaction>: [ { upgrade => [ id ], remove => [ fullname ] } ]

B<transaction_state>: $state object


=head1 SEE ALSO

The L<URPM::Resolve> implements the resolving bits.

The L<URPM::Signature> implements the pubkey bits.

The L<urpm> package is a higher level module used by the urpmi command line tool,
the rpmdrake GUI and the drakx installer.

=head1 COPYRIGHT

Copyright 2002, 2003, 2004, 2005 MandrakeSoft SA

Copyright 2005, 2006, 2007, 2008 Mandriva SA

Copyright 2011, 2012, 2013, 2014, 2015, 2016 Mageia

FranE<ccedil>ois Pons (original author), Rafael Garcia-Suarez, Pixel, Thierry Vignaud <tv@mageia.org> (current maintainer)

This library is free software; you can redistribute it and/or modify it under
the same terms as Perl itself.

=cut