/usr/share/perl5/Dpkg/Control/Fields.pm is in libdpkg-perl 1.16.1.2ubuntu7.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 | # Copyright © 2007-2009 Raphaël Hertzog <hertzog@debian.org>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
package Dpkg::Control::Fields;
use strict;
use warnings;
our $VERSION = "1.00";
use base qw(Exporter);
use Dpkg::Gettext;
use Dpkg::ErrorHandling;
use Dpkg::Control::Types;
use Dpkg::Checksums;
use Dpkg::Vendor qw(run_vendor_hook);
our @EXPORT = qw(field_capitalize field_is_official field_is_allowed_in
field_transfer_single field_transfer_all
field_list_src_dep field_list_pkg_dep field_get_dep_type
field_ordered_list field_register
field_insert_after field_insert_before);
use constant {
ALL_PKG => CTRL_INFO_PKG | CTRL_INDEX_PKG | CTRL_PKG_DEB | CTRL_FILE_STATUS,
ALL_SRC => CTRL_INFO_SRC | CTRL_INDEX_SRC | CTRL_PKG_SRC,
ALL_CHANGES => CTRL_FILE_CHANGES | CTRL_CHANGELOG,
};
# The canonical list of fields
# Note that fields used only in dpkg's available file are not listed
# Deprecated fields of dpkg's status file are also not listed
our %FIELDS = (
'Architecture' => {
allowed => (ALL_PKG | ALL_SRC | CTRL_FILE_CHANGES) & (~CTRL_INFO_SRC),
},
'Binary' => {
allowed => CTRL_PKG_SRC | CTRL_FILE_CHANGES,
},
'Breaks' => {
allowed => ALL_PKG,
dependency => 'union',
dep_order => 7,
},
'Bugs' => {
allowed => (ALL_PKG | CTRL_INFO_SRC | CTRL_FILE_VENDOR) & (~CTRL_INFO_PKG),
},
'Build-Conflicts' => {
allowed => ALL_SRC,
dependency => 'union',
dep_order => 3,
},
'Build-Conflicts-Indep' => {
allowed => ALL_SRC,
dependency => 'union',
dep_order => 4,
},
'Build-Depends' => {
allowed => ALL_SRC,
dependency => 'normal',
dep_order => 1,
},
'Build-Depends-Indep' => {
allowed => ALL_SRC,
dependency => 'normal',
dep_order => 2,
},
'Built-Using' => {
allowed => ALL_PKG,
dependency => 'union',
dep_order => 10,
},
'Changed-By' => {
allowed => CTRL_FILE_CHANGES,
},
'Changes' => {
allowed => ALL_CHANGES,
},
'Closes' => {
allowed => ALL_CHANGES,
},
'Conffiles' => {
allowed => CTRL_FILE_STATUS,
},
'Config-Version' => {
allowed => CTRL_FILE_STATUS,
},
'Conflicts' => {
allowed => ALL_PKG,
dependency => 'union',
dep_order => 6,
},
'Date' => {
allowed => ALL_CHANGES,
},
'Depends' => {
allowed => ALL_PKG,
dependency => 'normal',
dep_order => 2,
},
'Description' => {
allowed => ALL_PKG | CTRL_FILE_CHANGES,
},
'Directory' => {
allowed => CTRL_INDEX_SRC,
},
'Distribution' => {
allowed => ALL_CHANGES,
},
'Enhances' => {
allowed => ALL_PKG,
dependency => 'union',
dep_order => 5,
},
'Essential' => {
allowed => ALL_PKG,
},
'Filename' => {
allowed => CTRL_INDEX_PKG,
},
'Files' => {
allowed => CTRL_PKG_SRC | CTRL_FILE_CHANGES,
},
'Format' => {
allowed => CTRL_PKG_SRC | CTRL_FILE_CHANGES,
},
'Homepage' => {
allowed => ALL_SRC | ALL_PKG,
},
'Installed-Size' => {
allowed => ALL_PKG & ~CTRL_INFO_PKG,
},
'Installer-Menu-Item' => {
allowed => ALL_PKG,
},
'Kernel-Version' => {
allowed => ALL_PKG,
},
'Origin' => {
allowed => (ALL_PKG | ALL_SRC) & (~CTRL_INFO_PKG),
},
'Maintainer' => {
allowed => CTRL_PKG_DEB | ALL_SRC | ALL_CHANGES,
},
'Multi-Arch' => {
allowed => ALL_PKG,
},
'Package' => {
allowed => ALL_PKG,
},
'Package-List' => {
allowed => ALL_SRC & ~CTRL_INFO_SRC,
},
'Package-Type' => {
allowed => ALL_PKG,
},
'Parent' => {
allowed => CTRL_FILE_VENDOR,
},
'Pre-Depends' => {
allowed => ALL_PKG,
dependency => 'normal',
dep_order => 1,
},
'Priority' => {
allowed => CTRL_INFO_SRC | CTRL_INDEX_SRC | ALL_PKG,
},
'Provides' => {
allowed => ALL_PKG,
dependency => 'union',
dep_order => 9,
},
'Recommends' => {
allowed => ALL_PKG,
dependency => 'normal',
dep_order => 3,
},
'Replaces' => {
allowed => ALL_PKG,
dependency => 'union',
dep_order => 8,
},
'Section' => {
allowed => CTRL_INFO_SRC | CTRL_INDEX_SRC | ALL_PKG,
},
'Size' => {
allowed => CTRL_INDEX_PKG,
},
'Source' => {
allowed => (ALL_PKG | ALL_SRC | ALL_CHANGES) &
(~(CTRL_INDEX_SRC | CTRL_INFO_PKG)),
},
'Standards-Version' => {
allowed => ALL_SRC,
},
'Status' => {
allowed => CTRL_FILE_STATUS,
},
'Subarchitecture' => {
allowed => ALL_PKG,
},
'Suggests' => {
allowed => ALL_PKG,
dependency => 'normal',
dep_order => 4,
},
'Tag' => {
allowed => ALL_PKG,
},
'Task' => {
allowed => ALL_PKG,
},
'Triggers-Awaited' => {
allowed => CTRL_FILE_STATUS,
},
'Triggers-Pending' => {
allowed => CTRL_FILE_STATUS,
},
'Uploaders' => {
allowed => ALL_SRC,
},
'Urgency' => {
allowed => ALL_CHANGES,
},
'Vcs-Browser' => {
allowed => ALL_SRC,
},
'Vcs-Arch' => {
allowed => ALL_SRC,
},
'Vcs-Bzr' => {
allowed => ALL_SRC,
},
'Vcs-Cvs' => {
allowed => ALL_SRC,
},
'Vcs-Darcs' => {
allowed => ALL_SRC,
},
'Vcs-Git' => {
allowed => ALL_SRC,
},
'Vcs-Hg' => {
allowed => ALL_SRC,
},
'Vcs-Mtn' => {
allowed => ALL_SRC,
},
'Vcs-Svn' => {
allowed => ALL_SRC,
},
'Vendor' => {
allowed => CTRL_FILE_VENDOR,
},
'Vendor-Url' => {
allowed => CTRL_FILE_VENDOR,
},
'Version' => {
allowed => (ALL_PKG | ALL_SRC | ALL_CHANGES) &
(~(CTRL_INFO_SRC | CTRL_INFO_PKG)),
},
);
my @checksum_fields = map { field_capitalize("Checksums-$_") } checksums_get_list();
my @sum_fields = map { $_ eq "md5" ? "MD5sum" : field_capitalize($_) }
checksums_get_list();
&field_register($_, CTRL_PKG_SRC | CTRL_FILE_CHANGES) foreach @checksum_fields;
&field_register($_, CTRL_INDEX_PKG) foreach @sum_fields;
our %FIELD_ORDER = (
CTRL_PKG_DEB() => [
qw(Package Package-Type Source Version Built-Using Kernel-Version
Architecture Subarchitecture Installer-Menu-Item Essential Origin Bugs
Maintainer Installed-Size), &field_list_pkg_dep(),
qw(Section Priority Multi-Arch Homepage Description Tag Task)
],
CTRL_PKG_SRC() => [
qw(Format Source Binary Architecture Version Origin Maintainer
Uploaders Homepage Standards-Version Vcs-Browser
Vcs-Arch Vcs-Bzr Vcs-Cvs Vcs-Darcs Vcs-Git Vcs-Hg Vcs-Mtn
Vcs-Svn), &field_list_src_dep(), qw(Package-List),
@checksum_fields, qw(Files)
],
CTRL_FILE_CHANGES() => [
qw(Format Date Source Binary Architecture Version Distribution
Urgency Maintainer Changed-By Description Closes Changes),
@checksum_fields, qw(Files)
],
CTRL_CHANGELOG() => [
qw(Source Version Distribution Urgency Maintainer Date Closes
Changes Timestamp Header Items Trailer Urgency_comment
Urgency_lc)
],
CTRL_FILE_STATUS() => [ # Same as fieldinfos in lib/dpkg/parse.c
qw(Package Essential Status Priority Section Installed-Size Origin
Maintainer Bugs Architecture Source Version Config-Version
Replaces Provides Depends Pre-Depends Recommends Suggests Breaks
Conflicts Enhances Conffiles Description Triggers-Pending
Triggers-Awaited)
],
);
# Order for CTRL_INDEX_PKG is derived from CTRL_PKG_DEB
$FIELD_ORDER{CTRL_INDEX_PKG()} = [ @{$FIELD_ORDER{CTRL_PKG_DEB()}} ];
&field_insert_before(CTRL_INDEX_PKG, 'Section', 'Filename', 'Size', @sum_fields);
# Order for CTRL_INDEX_SRC is derived from CTRL_PKG_SRC
$FIELD_ORDER{CTRL_INDEX_SRC()} = [ @{$FIELD_ORDER{CTRL_PKG_SRC()}} ];
@{$FIELD_ORDER{CTRL_INDEX_SRC()}} = map { $_ eq "Source" ? "Package" : $_ }
@{$FIELD_ORDER{CTRL_PKG_SRC()}};
&field_insert_after(CTRL_INDEX_SRC, "Version", "Priority", "Section");
&field_insert_before(CTRL_INDEX_SRC, "Checksums-Md5", "Directory");
# Register vendor specifics fields
foreach my $op (run_vendor_hook("register-custom-fields")) {
next if not (defined $op and ref $op); # Skip when not implemented by vendor
my $func = shift @$op;
if ($func eq "register") {
&field_register(@$op);
} elsif ($func eq "insert_before") {
&field_insert_before(@$op);
} elsif ($func eq "insert_after") {
&field_insert_after(@$op);
} else {
error("vendor hook register-custom-fields sent bad data: @$op");
}
}
=encoding utf8
=head1 NAME
Dpkg::Control::Fields - manage (list of official) control fields
=head1 DESCRIPTION
The modules contains a list of fieldnames with associated meta-data explaining
in which type of control information they are allowed. The types are the
CTRL_* constants exported by Dpkg::Control.
=head1 FUNCTIONS
=over 4
=item my $f = field_capitalize($field_name)
Returns the field name properly capitalized. All characters are lowercase,
except the first of each word (words are separated by a dash in field names).
=cut
sub field_capitalize($) {
my $field = lc(shift);
# Some special cases due to history
return "MD5sum" if $field eq "md5sum";
return uc($field) if checksums_is_supported($field);
# Generic case
return join '-', map { ucfirst } split /-/, $field;
}
=item field_is_official($fname)
Returns true if the field is official and known.
=cut
sub field_is_official($) {
return exists $FIELDS{field_capitalize($_[0])};
}
=item field_is_allowed_in($fname, @types)
Returns true (1) if the field $fname is allowed in all the types listed in
the list. Note that you can use type sets instead of individual types (ex:
CTRL_FILE_CHANGES | CTRL_CHANGELOG).
field_allowed_in(A|B, C) returns true only if the field is allowed in C
and either A or B.
Undef is returned for non-official fields.
=cut
sub field_is_allowed_in($@) {
my ($field, @types) = @_;
$field = field_capitalize($field);
return undef unless field_is_official($field);
return 0 if not scalar(@types);
foreach my $type (@types) {
next if $type == CTRL_UNKNOWN; # Always allowed
return 0 unless $FIELDS{$field}{'allowed'} & $type;
}
return 1;
}
=item field_transfer_single($from, $to, $field)
If appropriate, copy the value of the field named $field taken from the
$from Dpkg::Control object to the $to Dpkg::Control object.
Official fields are copied only if the field is allowed in both types of
objects. Custom fields are treated in a specific manner. When the target
is not among CTRL_PKG_SRC, CTRL_PKG_DEB or CTRL_FILE_CHANGES, then they
are alway copied as is (the X- prefix is kept). Otherwise they are not
copied except if the target object matches the target destination encoded
in the field name. The initial X denoting custom fields can be followed by
one or more letters among "S" (Source: corresponds to CTRL_PKG_SRC), "B"
(Binary: corresponds to CTRL_PKG_DEB) or "C" (Changes: corresponds to
CTRL_FILE_CHANGES).
Returns undef if nothing has been copied or the name of the new field
added to $to otherwise.
=cut
sub field_transfer_single($$;$) {
my ($from, $to, $field) = @_;
$field = $_ unless defined $field;
my ($from_type, $to_type) = ($from->get_type(), $to->get_type());
$field = field_capitalize($field);
if (field_is_allowed_in($field, $from_type, $to_type)) {
$to->{$field} = $from->{$field};
return $field;
} elsif ($field =~ /^X([SBC]*)-/i) {
my $dest = $1;
if (($dest =~ /B/i and $to_type == CTRL_PKG_DEB) or
($dest =~ /S/i and $to_type == CTRL_PKG_SRC) or
($dest =~ /C/i and $to_type == CTRL_FILE_CHANGES))
{
my $new = $field;
$new =~ s/^X([SBC]*)-//i;
$to->{$new} = $from->{$field};
return $new;
} elsif ($to_type != CTRL_PKG_DEB and
$to_type != CTRL_PKG_SRC and
$to_type != CTRL_FILE_CHANGES)
{
$to->{$field} = $from->{$field};
return $field;
}
} elsif (not field_is_allowed_in($field, $from_type)) {
warning(_g("unknown information field '%s' in input data in %s"),
$field, $from->get_option("name") || _g("control information"));
}
return undef;
}
=item field_transfer_all($from, $to)
Transfer all appropriate fields from $from to $to. Calls
field_transfer_single() on all fields available in $from.
Returns the list of fields that have been added to $to.
=cut
sub field_transfer_all($$) {
my ($from, $to) = @_;
my (@res, $res);
foreach my $k (keys %$from) {
$res = field_transfer_single($from, $to, $k);
push @res, $res if $res and defined wantarray;
}
return @res;
}
=item field_ordered_list($type)
Returns an ordered list of fields for a given type of control information.
This list can be used to output the fields in a predictable order.
The list might be empty for types where the order does not matter much.
=cut
sub field_ordered_list($) {
my ($type) = @_;
return @{$FIELD_ORDER{$type}} if exists $FIELD_ORDER{$type};
return ();
}
=item field_list_src_dep()
List of fields that contains dependencies-like information in a source
Debian package.
=cut
sub field_list_src_dep() {
return sort {
$FIELDS{$a}{'dep_order'} <=> $FIELDS{$b}{'dep_order'}
} grep {
field_is_allowed_in($_, CTRL_PKG_SRC) and
exists $FIELDS{$_}{'dependency'}
} keys %FIELDS;
}
=item field_list_pkg_dep()
List of fields that contains dependencies-like information in a binary
Debian package. The fields that express real dependencies are sorted from
the stronger to the weaker.
=cut
sub field_list_pkg_dep() {
my @keys = keys %FIELDS;
return sort {
$FIELDS{$a}{'dep_order'} <=> $FIELDS{$b}{'dep_order'}
} grep {
field_is_allowed_in($_, CTRL_PKG_DEB) and
exists $FIELDS{$_}{'dependency'}
} @keys;
}
=item field_get_dep_type($field)
Return the type of the dependency expressed by the given field. Can
either be "normal" for a real dependency field (Pre-Depends, Depends, ...)
or "union" for other relation fields sharing the same syntax (Conflicts,
Breaks, ...). Returns undef for fields which are not dependencies.
=cut
sub field_get_dep_type($) {
my $field = field_capitalize($_[0]);
return undef unless field_is_official($field);
return $FIELDS{$field}{'dependency'} if exists $FIELDS{$field}{'dependency'};
return undef;
}
=item field_register($field, $allowed_types, %opts)
Register a new field as being allowed in control information of specified
types. %opts is optional
=cut
sub field_register($$;@) {
my ($field, $types, %opts) = @_;
$field = field_capitalize($field);
$FIELDS{$field} = {
allowed => $types,
%opts
};
}
=item field_insert_after($type, $ref, @fields)
Place field after another one ($ref) in output of control information of
type $type.
=cut
sub field_insert_after($$@) {
my ($type, $field, @fields) = @_;
return 0 if not exists $FIELD_ORDER{$type};
($field, @fields) = map { field_capitalize($_) } ($field, @fields);
@{$FIELD_ORDER{$type}} = map {
($_ eq $field) ? ($_, @fields) : $_
} @{$FIELD_ORDER{$type}};
return 1;
}
=item field_insert_before($type, $ref, @fields)
Place field before another one ($ref) in output of control information of
type $type.
=cut
sub field_insert_before($$@) {
my ($type, $field, @fields) = @_;
return 0 if not exists $FIELD_ORDER{$type};
($field, @fields) = map { field_capitalize($_) } ($field, @fields);
@{$FIELD_ORDER{$type}} = map {
($_ eq $field) ? (@fields, $_) : $_
} @{$FIELD_ORDER{$type}};
return 1;
}
=back
=head1 AUTHOR
Raphaël Hertzog <hertzog@debian.org>.
=cut
1;
|