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
|
# $Id: /local/youri/soft/trunk/lib/Youri/Package/URPM.pm 2129 2006-06-23T09:41:01.599329Z guillomovitch $
package Youri::Package::RPM4;
=head1 NAME
Youri::Package::RPM4 - URPM-based rpm package implementation
=head1 DESCRIPTION
This is an RPM4-based L<Youri::Package> implementation for rpm.
=cut
use strict;
use warnings;
use Carp;
use RPM4;
use RPM4::Header;
use RPM4::Sign;
use File::Spec;
use Scalar::Util qw/refaddr/;
use base 'Youri::Package::RPM';
use overload
'""' => 'as_string',
'0+' => '_to_number',
fallback => 1;
=head1 CLASS METHODS
=head2 new(%args)
Creates and returns a new Youri::Package::RPM4 object.
Specific parameters:
=over
=item file $file
Path of file to use for creating this package.
=item header $header
L<RPM4::Header> object to use for creating this package.
=back
=cut
sub _init {
my ($self, %options) = @_;
my $header;
HEADER: {
if (exists $options{header}) {
croak "undefined header"
unless $options{header};
croak "invalid header"
unless $options{header}->isa('RPM4::Header');
$header = $options{header};
last HEADER;
}
if (exists $options{file}) {
croak "undefined file"
unless $options{file};
croak "non-existing file $options{file}"
unless -f $options{file};
croak "non-readable file $options{file}"
unless -r $options{file};
$header = RPM4::Header->new($options{file});
croak "Can't get header from file $options{file}" if (!$header);
last HEADER;
}
croak "no way to extract header from arguments";
}
$self->{_header} = $header;
$self->{_file} = File::Spec->rel2abs($options{file});
}
sub compare_versions {
my ($class, $version1, $version2) = @_;
return RPM4::rpmvercmp($version1, $version2);
}
sub _depsense2flag {
my ($string) = @_;
my @flags = 0;
push(@flags, 'EQUAL') if ($string =~ /=/);
push(@flags, 'LESS') if ($string =~ /</);
push(@flags, 'GREATER') if ($string =~ />/);
return \@flags;
}
sub check_ranges_compatibility {
my ($class, $range1, $range2) = @_;
my @deps1 = split(/ /, $range1);
my @deps2 = split(/ /, $range2);
$deps1[1] = _depsense2flag($range1);
$deps2[1] = _depsense2flag($range2);
my $dep1 = RPM4::Header::Dependencies(
"PROVIDENAME",
\@deps1,
);
my $dep2 = RPM4::Header::Dependencies(
"PROVIDENAME",
\@deps2,
);
return $dep1->overlap($dep2);
}
sub get_name {
my ($self) = @_;
croak "Not a class method" unless ref $self;
return $self->{_header}->tag('name');
}
sub get_version {
my ($self) = @_;
croak "Not a class method" unless ref $self;
return $self->{_header}->tag('version');
}
sub get_release {
my ($self) = @_;
croak "Not a class method" unless ref $self;
return $self->{_header}->tag('release');
}
sub get_revision {
my ($self) = @_;
croak "Not a class method" unless ref $self;
return $self->{_header}->queryformat('%|EPOCH?{%{EPOCH}:}:{}|%{VERSION}-%{RELEASE}');
}
sub get_file_name {
my ($self) = @_;
croak "Not a class method" unless ref $self;
return $self->{_header}->queryformat('%{NAME}-%{VERSION}-%{RELEASE}.%|SOURCERPM?{%{ARCH}}:{src}|.rpm');
}
sub get_arch {
my ($self) = @_;
croak "Not a class method" unless ref $self;
return $self->{_header}->queryformat('%|SOURCERPM?{%{ARCH}}:{src}|');
}
sub get_url {
my ($self) = @_;
croak "Not a class method" unless ref $self;
return $self->{_header}->tag('url');
}
sub get_summary {
my ($self) = @_;
croak "Not a class method" unless ref $self;
return $self->{_header}->tag('summary');
}
sub get_description {
my ($self) = @_;
croak "Not a class method" unless ref $self;
return $self->{_header}->tag('description');
}
sub get_packager {
my ($self) = @_;
croak "Not a class method" unless ref $self;
return $self->{_header}->tag('packager');
}
sub is_source {
my ($self) = @_;
croak "Not a class method" unless ref $self;
return $self->{_header}->issrc();
}
sub is_binary {
my ($self) = @_;
croak "Not a class method" unless ref $self;
return !$self->{_header}->issrc();
}
sub get_type {
my ($self) = @_;
croak "Not a class method" unless ref $self;
return
$self->{_header}->issrc() ?
"source" :
"binary";
}
sub get_age {
my ($self) = @_;
croak "Not a class method" unless ref $self;
return $self->{_header}->tag('buildtime');
}
sub get_source_package {
my ($self) = @_;
croak "Not a class method" unless ref $self;
return $self->{_header}->tag('sourcerpm');
}
sub get_canonical_name {
my ($self) = @_;
croak "Not a class method" unless ref $self;
$self->{_header}->sourcerpmname() =~ /^(\S+)-[^-]+-[^-]+\.src\.rpm$/;
return $1;
}
sub get_tag {
my ($self, $tag) = @_;
croak "Not a class method" unless ref $self;
#croak "invalid tag $tag" unless $self->{_header}->can($tag);
return $self->{_header}->tag($tag);
}
sub _get_dependencies {
my ($self, $deptype) = @_;
my $deps = $self->{_header}->dep($deptype);
my @deps_list;
if ($deps) {
$deps->init();
while ($deps->next() >= 0) {
my @deps = $deps->info();
$deps[1] =~ m/^rpmlib\(/ and next; # skipping internal rpmlib dep
$deps[2] =~ s/^=$/==/; # rpm say foo = 1, not foo == 1, == come from URPM, which sucks
my $range = $deps[3] ? ($deps[2] . ' ' . $deps[3]) : undef;
push(@deps_list, [ $deps[1], $range ]);
}
}
@deps_list
}
sub get_requires {
my ($self) = @_;
return $self->_get_dependencies('REQUIRENAME');
}
sub get_provides {
my ($self) = @_;
return $self->_get_dependencies('PROVIDENAME');
}
sub get_obsoletes {
my ($self) = @_;
return $self->_get_dependencies('OBSOLETENAME');
}
sub get_conflicts {
my ($self) = @_;
return $self->_get_dependencies('CONFLICTNAME');
}
sub get_files {
my ($self) = @_;
my $files = $self->{_header}->files();
my @fileslist;
if ($files) {
$files->init();
while ($files->next() >= 0) {
my $smode = $files->mode();
my $umode = 0;
foreach (0..15) { # converting unsigned to signed int :\
$umode |= $smode & (1 << $_);
}
push(@fileslist, [ $files->filename(), $umode, $files->md5() || '' ]);
}
}
@fileslist
}
sub get_gpg_key {
my ($self) = @_;
my $signature = $self->{_header}->queryformat('%{SIGGPG:pgpsig}');
return if $signature eq '(not a blob)';
my $key_id = (split(/\s+/, $signature))[-1];
return substr($key_id, 8);
}
sub get_information {
my ($self) = @_;
return $self->{_header}->queryformat(<<EOF);
Name : %-27{NAME} Relocations: %|PREFIXES?{[%{PREFIXES} ]}:{(not relocatable)}|
Version : %-27{VERSION} Vendor: %{VENDOR}
Release : %-27{RELEASE} Build Date: %{BUILDTIME:date}
Install Date: %|INSTALLTIME?{%-27{INSTALLTIME:date}}:{(not installed) }| Build Host: %{BUILDHOST}
Group : %-27{GROUP} Source RPM: %{SOURCERPM}
Size : %-27{SIZE}%|LICENSE?{ License: %{LICENSE}}|
Signature : %|DSAHEADER?{%{DSAHEADER:pgpsig}}:{%|RSAHEADER?{%{RSAHEADER:pgpsig}}:{%|SIGGPG?{%{SIGGPG:pgpsig}}:{%|SIGPGP?{%{SIGPGP:pgpsig}}:{(none)}|}|}|}|
%|PACKAGER?{Packager : %{PACKAGER}\n}|%|URL?{URL : %{URL}\n}|Summary : %{SUMMARY}
Description :\n%{DESCRIPTION}
EOF
}
sub get_changes {
my ($self) = @_;
my @names = $self->{_header}->tag('changelogname');
my @time = $self->{_header}->tag('changelogtime');
my @text = $self->{_header}->tag('changelogtext');
my @changes;
foreach my $i (0 .. $#names) {
$changes[$i] = [
$names[$i],
$time[$i],
$text[$i],
];
}
return @changes;
}
sub get_last_change {
my ($self) = @_;
return [
($self->{_header}->tag('changelogname'))[0],
($self->{_header}->tag('changelogtime'))[0],
($self->{_header}->tag('changelogtext'))[0],
];
}
sub as_string {
my ($self) = @_;
croak "Not a class method" unless ref $self;
return $self->{_header}->fullname();
}
sub as_formated_string {
my ($self, $format) = @_;
croak "Not a class method" unless ref $self;
return $self->{_header}->queryformat($format);
}
sub _to_number {
return refaddr($_[0]);
}
sub compare {
my ($self, $package) = @_;
croak "Not a class method" unless ref $self;
return $self->{_header}->compare($package->{_header}) || 0;
}
sub satisfy_range {
my ($self, $range) = @_;
croak "Not a class method" unless ref $self;
return $self->check_range_compatibility($self->get_revision(), $range);
}
sub sign {
my ($self, $name, $path, $passphrase) = @_;
croak "Not a class method" unless ref $self;
# check if parent directory is writable
my $parent = (File::Spec->splitpath($self->{_file}))[1];
croak "Unsignable package, parent directory is read-only"
unless -w $parent;
my $sign = RPM4::Sign->new(
name => $name,
path => $path,
);
$sign->{passphrase} = $passphrase;
$sign->rpmssign($self->{_file})
}
sub extract {
my ($self) = @_;
croak "Not a class method" unless ref $self;
system("rpm2cpio $self->{_file} | cpio -id >/dev/null 2>&1");
}
=head1 COPYRIGHT AND LICENSE
Copyright (C) 2002-2006, YOURI project
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
=cut
1;
|