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 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419
|
# Copyright © 2007-2009 Raphaël Hertzog <hertzog@debian.org>
# Copyright © 2012-2024 Guillem Jover <guillem@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 <https://www.gnu.org/licenses/>.
=encoding utf8
=head1 NAME
Dpkg::Control::FieldsCore - manage (list of official) control fields
=head1 DESCRIPTION
The modules contains a list of field names with associated meta-data explaining
in which type of control information they are allowed. The types are the
CTRL_* constants exported by L<Dpkg::Control>.
=cut
package Dpkg::Control::FieldsCore 1.04;
use v5.36;
our @EXPORT = qw(
field_capitalize
field_is_official
field_is_allowed_in
field_transfer_single
field_transfer_all
field_parse_binary_source
field_list_src_dep
field_list_pkg_dep
field_get_dep_type
field_get_sep_type
field_get_default_value
field_ordered_list
field_register
field_insert_after
field_insert_before
FIELD_SEP_UNKNOWN
FIELD_SEP_SPACE
FIELD_SEP_COMMA
FIELD_SEP_LINE
);
use Exporter qw(import);
use Dpkg::Gettext;
use Dpkg::ErrorHandling;
use Dpkg::Control::Types;
use constant {
ALL_PKG => CTRL_TMPL_PKG | CTRL_REPO_PKG | CTRL_DEB | CTRL_FILE_STATUS,
ALL_SRC => CTRL_TMPL_SRC | CTRL_REPO_SRC | CTRL_DSC,
ALL_FILE_MANIFEST => CTRL_FILE_BUILDINFO | CTRL_FILE_CHANGES,
ALL_CHANGES => CTRL_FILE_CHANGES | CTRL_CHANGELOG,
ALL_COPYRIGHT => CTRL_COPYRIGHT_HEADER | CTRL_COPYRIGHT_FILES | CTRL_COPYRIGHT_LICENSE,
};
use constant {
FIELD_SEP_UNKNOWN => 0,
FIELD_SEP_SPACE => 1,
FIELD_SEP_COMMA => 2,
FIELD_SEP_LINE => 4,
};
# 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 = (
'acquire-by-hash' => {
name => 'Acquire-By-Hash',
allowed => CTRL_REPO_RELEASE,
},
'architecture' => {
name => 'Architecture',
allowed => (ALL_PKG | ALL_SRC | ALL_FILE_MANIFEST | CTRL_TESTS) & (~CTRL_TMPL_SRC),
separator => FIELD_SEP_SPACE,
},
'architectures' => {
name => 'Architectures',
allowed => CTRL_REPO_RELEASE,
separator => FIELD_SEP_SPACE,
},
'auto-built-package' => {
name => 'Auto-Built-Package',
allowed => ALL_PKG & ~CTRL_TMPL_PKG,
separator => FIELD_SEP_SPACE,
},
'binary' => {
name => 'Binary',
allowed => CTRL_DSC | CTRL_REPO_SRC | ALL_FILE_MANIFEST,
# XXX: This field values are separated either by space or comma
# depending on the context.
separator => FIELD_SEP_SPACE | FIELD_SEP_COMMA,
},
'binary-only' => {
name => 'Binary-Only',
allowed => ALL_CHANGES,
},
'binary-only-changes' => {
name => 'Binary-Only-Changes',
allowed => CTRL_FILE_BUILDINFO,
},
'breaks' => {
name => 'Breaks',
allowed => ALL_PKG,
separator => FIELD_SEP_COMMA,
dependency => 'union',
dep_order => 7,
},
'bugs' => {
name => 'Bugs',
allowed => (ALL_PKG | CTRL_TMPL_SRC | CTRL_FILE_VENDOR) & (~CTRL_TMPL_PKG),
},
'build-architecture' => {
name => 'Build-Architecture',
allowed => CTRL_FILE_BUILDINFO,
},
'build-conflicts' => {
name => 'Build-Conflicts',
allowed => ALL_SRC,
separator => FIELD_SEP_COMMA,
dependency => 'union',
dep_order => 4,
},
'build-conflicts-arch' => {
name => 'Build-Conflicts-Arch',
allowed => ALL_SRC,
separator => FIELD_SEP_COMMA,
dependency => 'union',
dep_order => 5,
},
'build-conflicts-indep' => {
name => 'Build-Conflicts-Indep',
allowed => ALL_SRC,
separator => FIELD_SEP_COMMA,
dependency => 'union',
dep_order => 6,
},
'build-date' => {
name => 'Build-Date',
allowed => CTRL_FILE_BUILDINFO,
},
'build-depends' => {
name => 'Build-Depends',
allowed => ALL_SRC,
separator => FIELD_SEP_COMMA,
dependency => 'normal',
dep_order => 1,
},
'build-depends-arch' => {
name => 'Build-Depends-Arch',
allowed => ALL_SRC,
separator => FIELD_SEP_COMMA,
dependency => 'normal',
dep_order => 2,
},
'build-depends-indep' => {
name => 'Build-Depends-Indep',
allowed => ALL_SRC,
separator => FIELD_SEP_COMMA,
dependency => 'normal',
dep_order => 3,
},
'build-driver' => {
name => 'Build-Driver',
allowed => CTRL_TMPL_SRC,
},
'build-essential' => {
name => 'Build-Essential',
allowed => ALL_PKG,
},
'build-kernel-version' => {
name => 'Build-Kernel-Version',
allowed => CTRL_FILE_BUILDINFO,
},
'build-origin' => {
name => 'Build-Origin',
allowed => CTRL_FILE_BUILDINFO,
},
'build-path' => {
name => 'Build-Path',
allowed => CTRL_FILE_BUILDINFO,
},
'build-profiles' => {
name => 'Build-Profiles',
allowed => CTRL_TMPL_PKG,
separator => FIELD_SEP_SPACE,
},
'build-tainted-by' => {
name => 'Build-Tainted-By',
allowed => CTRL_FILE_BUILDINFO,
separator => FIELD_SEP_SPACE,
},
'built-for-profiles' => {
name => 'Built-For-Profiles',
allowed => ALL_PKG | CTRL_FILE_CHANGES,
separator => FIELD_SEP_SPACE,
},
'built-using' => {
name => 'Built-Using',
allowed => ALL_PKG,
separator => FIELD_SEP_COMMA,
dependency => 'union',
dep_order => 10,
},
'butautomaticupgrades' => {
name => 'ButAutomaticUpgrades',
allowed => CTRL_REPO_RELEASE,
},
'changed-by' => {
name => 'Changed-By',
allowed => CTRL_FILE_CHANGES,
},
'changelogs' => {
name => 'Changelogs',
allowed => CTRL_REPO_RELEASE,
},
'changes' => {
name => 'Changes',
allowed => ALL_CHANGES,
},
'checksums-md5' => {
name => 'Checksums-Md5',
allowed => CTRL_DSC | CTRL_REPO_SRC | ALL_FILE_MANIFEST,
},
'checksums-sha1' => {
name => 'Checksums-Sha1',
allowed => CTRL_DSC | CTRL_REPO_SRC | ALL_FILE_MANIFEST,
},
'checksums-sha256' => {
name => 'Checksums-Sha256',
allowed => CTRL_DSC | CTRL_REPO_SRC | ALL_FILE_MANIFEST,
},
'classes' => {
name => 'Classes',
allowed => CTRL_TESTS,
separator => FIELD_SEP_COMMA,
},
'closes' => {
name => 'Closes',
allowed => ALL_CHANGES,
separator => FIELD_SEP_SPACE,
},
'codename' => {
name => 'Codename',
allowed => CTRL_REPO_RELEASE,
},
'comment' => {
name => 'Comment',
allowed => ALL_COPYRIGHT,
},
'components' => {
name => 'Components',
allowed => CTRL_REPO_RELEASE,
separator => FIELD_SEP_SPACE,
},
'conffiles' => {
name => 'Conffiles',
allowed => CTRL_FILE_STATUS,
separator => FIELD_SEP_LINE | FIELD_SEP_SPACE,
},
'config-version' => {
name => 'Config-Version',
allowed => CTRL_FILE_STATUS,
},
'conflicts' => {
name => 'Conflicts',
allowed => ALL_PKG,
separator => FIELD_SEP_COMMA,
dependency => 'union',
dep_order => 6,
},
'copyright' => {
name => 'Copyright',
allowed => CTRL_COPYRIGHT_HEADER | CTRL_COPYRIGHT_FILES,
},
'date' => {
name => 'Date',
allowed => ALL_CHANGES | CTRL_REPO_RELEASE,
},
'depends' => {
name => 'Depends',
allowed => ALL_PKG | CTRL_TESTS,
separator => FIELD_SEP_COMMA,
dependency => 'normal',
dep_order => 2,
},
'description' => {
name => 'Description',
allowed => ALL_SRC | ALL_PKG | CTRL_FILE_CHANGES | CTRL_REPO_RELEASE,
},
'disclaimer' => {
name => 'Disclaimer',
allowed => CTRL_COPYRIGHT_HEADER,
},
'directory' => {
name => 'Directory',
allowed => CTRL_REPO_SRC,
},
'distribution' => {
name => 'Distribution',
allowed => ALL_CHANGES,
},
'enhances' => {
name => 'Enhances',
allowed => ALL_PKG,
separator => FIELD_SEP_COMMA,
dependency => 'union',
dep_order => 5,
},
'environment' => {
name => 'Environment',
allowed => CTRL_FILE_BUILDINFO,
separator => FIELD_SEP_LINE,
},
'essential' => {
name => 'Essential',
allowed => ALL_PKG,
},
'features' => {
name => 'Features',
allowed => CTRL_TESTS,
separator => FIELD_SEP_SPACE,
},
'filename' => {
name => 'Filename',
allowed => CTRL_REPO_PKG,
separator => FIELD_SEP_LINE | FIELD_SEP_SPACE,
},
'files' => {
name => 'Files',
allowed => CTRL_DSC | CTRL_REPO_SRC | CTRL_FILE_CHANGES | CTRL_COPYRIGHT_FILES,
separator => FIELD_SEP_LINE | FIELD_SEP_SPACE,
},
'format' => {
name => 'Format',
allowed => CTRL_DSC | CTRL_REPO_SRC | ALL_FILE_MANIFEST | CTRL_COPYRIGHT_HEADER,
},
'homepage' => {
name => 'Homepage',
allowed => ALL_SRC | ALL_PKG,
},
'installed-build-depends' => {
name => 'Installed-Build-Depends',
allowed => CTRL_FILE_BUILDINFO,
separator => FIELD_SEP_COMMA,
dependency => 'union',
dep_order => 12,
},
'installed-size' => {
name => 'Installed-Size',
allowed => ALL_PKG & ~CTRL_TMPL_PKG,
},
'installer-menu-item' => {
name => 'Installer-Menu-Item',
allowed => ALL_PKG,
},
'kernel-version' => {
name => 'Kernel-Version',
allowed => ALL_PKG,
},
'label' => {
name => 'Label',
allowed => CTRL_REPO_RELEASE,
},
'license' => {
name => 'License',
allowed => ALL_COPYRIGHT,
},
'origin' => {
name => 'Origin',
allowed => (ALL_PKG | ALL_SRC | CTRL_REPO_RELEASE) & (~CTRL_TMPL_PKG),
},
'maintainer' => {
name => 'Maintainer',
allowed => CTRL_DEB | CTRL_REPO_PKG | CTRL_FILE_STATUS | ALL_SRC | ALL_CHANGES,
},
'md5sum' => {
# XXX: Wrong capitalization due to historical reasons.
name => 'MD5sum',
allowed => CTRL_REPO_PKG | CTRL_REPO_RELEASE,
separator => FIELD_SEP_LINE | FIELD_SEP_SPACE,
},
'multi-arch' => {
name => 'Multi-Arch',
allowed => ALL_PKG,
},
'no-support-for-architecture-all' => {
name => 'No-Support-for-Architecture-all',
allowed => CTRL_REPO_RELEASE,
},
'notautomatic' => {
name => 'NotAutomatic',
allowed => CTRL_REPO_RELEASE,
},
'package' => {
name => 'Package',
allowed => ALL_PKG | CTRL_REPO_SRC,
},
'package-list' => {
name => 'Package-List',
allowed => ALL_SRC & ~CTRL_TMPL_SRC,
separator => FIELD_SEP_LINE | FIELD_SEP_SPACE,
},
'package-type' => {
name => 'Package-Type',
allowed => ALL_PKG,
},
'parent' => {
name => 'Parent',
allowed => CTRL_FILE_VENDOR,
},
'pre-depends' => {
name => 'Pre-Depends',
allowed => ALL_PKG,
separator => FIELD_SEP_COMMA,
dependency => 'normal',
dep_order => 1,
},
'priority' => {
name => 'Priority',
allowed => CTRL_TMPL_SRC | CTRL_REPO_SRC | ALL_PKG,
default => 'optional',
},
'protected' => {
name => 'Protected',
allowed => ALL_PKG,
},
'provides' => {
name => 'Provides',
allowed => ALL_PKG,
separator => FIELD_SEP_COMMA,
dependency => 'union',
dep_order => 9,
},
'recommends' => {
name => 'Recommends',
allowed => ALL_PKG,
separator => FIELD_SEP_COMMA,
dependency => 'normal',
dep_order => 3,
},
'replaces' => {
name => 'Replaces',
allowed => ALL_PKG,
separator => FIELD_SEP_COMMA,
dependency => 'union',
dep_order => 8,
},
'restrictions' => {
name => 'Restrictions',
allowed => CTRL_TESTS,
separator => FIELD_SEP_SPACE,
},
'rules-requires-root' => {
name => 'Rules-Requires-Root',
allowed => CTRL_TMPL_SRC,
separator => FIELD_SEP_SPACE,
},
'section' => {
name => 'Section',
allowed => CTRL_TMPL_SRC | CTRL_REPO_SRC | ALL_PKG,
default => 'unknown',
},
'sha1' => {
# XXX: Wrong capitalization due to historical reasons.
name => 'SHA1',
allowed => CTRL_REPO_PKG | CTRL_REPO_RELEASE,
separator => FIELD_SEP_LINE | FIELD_SEP_SPACE,
},
'sha256' => {
# XXX: Wrong capitalization due to historical reasons.
name => 'SHA256',
allowed => CTRL_REPO_PKG | CTRL_REPO_RELEASE,
separator => FIELD_SEP_LINE | FIELD_SEP_SPACE,
},
'size' => {
name => 'Size',
allowed => CTRL_REPO_PKG,
separator => FIELD_SEP_LINE | FIELD_SEP_SPACE,
},
'source' => {
name => 'Source',
allowed => (ALL_PKG | ALL_SRC | ALL_CHANGES | CTRL_COPYRIGHT_HEADER | CTRL_FILE_BUILDINFO) &
(~(CTRL_REPO_SRC | CTRL_TMPL_PKG)),
},
'standards-version' => {
name => 'Standards-Version',
allowed => ALL_SRC,
},
'static-built-using' => {
name => 'Static-Built-Using',
allowed => ALL_PKG,
separator => FIELD_SEP_COMMA,
dependency => 'union',
dep_order => 11,
},
'status' => {
name => 'Status',
allowed => CTRL_FILE_STATUS,
separator => FIELD_SEP_SPACE,
},
'subarchitecture' => {
name => 'Subarchitecture',
allowed => ALL_PKG,
},
'suite' => {
name => 'Suite',
allowed => CTRL_REPO_RELEASE,
},
'suggests' => {
name => 'Suggests',
allowed => ALL_PKG,
separator => FIELD_SEP_COMMA,
dependency => 'normal',
dep_order => 4,
},
'tag' => {
name => 'Tag',
allowed => ALL_PKG,
separator => FIELD_SEP_COMMA,
},
'task' => {
name => 'Task',
allowed => ALL_PKG,
},
'test-command' => {
name => 'Test-Command',
allowed => CTRL_TESTS,
},
'tests' => {
name => 'Tests',
allowed => CTRL_TESTS,
separator => FIELD_SEP_SPACE,
},
'tests-directory' => {
name => 'Tests-Directory',
allowed => CTRL_TESTS,
},
'testsuite' => {
name => 'Testsuite',
allowed => ALL_SRC,
separator => FIELD_SEP_COMMA,
},
'testsuite-triggers' => {
name => 'Testsuite-Triggers',
allowed => ALL_SRC,
separator => FIELD_SEP_COMMA,
},
'timestamp' => {
name => 'Timestamp',
allowed => CTRL_CHANGELOG,
},
'triggers-awaited' => {
name => 'Triggers-Awaited',
allowed => CTRL_FILE_STATUS,
separator => FIELD_SEP_SPACE,
},
'triggers-pending' => {
name => 'Triggers-Pending',
allowed => CTRL_FILE_STATUS,
separator => FIELD_SEP_SPACE,
},
'uploaders' => {
name => 'Uploaders',
allowed => ALL_SRC,
separator => FIELD_SEP_COMMA,
},
'upstream-name' => {
name => 'Upstream-Name',
allowed => CTRL_COPYRIGHT_HEADER,
},
'upstream-contact' => {
name => 'Upstream-Contact',
allowed => CTRL_COPYRIGHT_HEADER,
},
'urgency' => {
name => 'Urgency',
allowed => ALL_CHANGES,
},
'valid-until' => {
name => 'Valid-Until',
allowed => CTRL_REPO_RELEASE,
},
'vcs-browser' => {
name => 'Vcs-Browser',
allowed => ALL_SRC,
},
'vcs-arch' => {
name => 'Vcs-Arch',
allowed => ALL_SRC,
},
'vcs-bzr' => {
name => 'Vcs-Bzr',
allowed => ALL_SRC,
},
'vcs-cvs' => {
name => 'Vcs-Cvs',
allowed => ALL_SRC,
},
'vcs-darcs' => {
name => 'Vcs-Darcs',
allowed => ALL_SRC,
},
'vcs-git' => {
name => 'Vcs-Git',
allowed => ALL_SRC,
},
'vcs-hg' => {
name => 'Vcs-Hg',
allowed => ALL_SRC,
},
'vcs-mtn' => {
name => 'Vcs-Mtn',
allowed => ALL_SRC,
},
'vcs-svn' => {
name => 'Vcs-Svn',
allowed => ALL_SRC,
},
'vendor' => {
name => 'Vendor',
allowed => CTRL_FILE_VENDOR,
},
'vendor-url' => {
name => 'Vendor-Url',
allowed => CTRL_FILE_VENDOR,
},
'version' => {
name => 'Version',
allowed => (ALL_PKG | ALL_SRC | CTRL_FILE_BUILDINFO | ALL_CHANGES | CTRL_REPO_RELEASE) &
(~(CTRL_TMPL_SRC | CTRL_TMPL_PKG)),
},
);
my @src_vcs_fields = qw(
vcs-browser
vcs-arch
vcs-bzr
vcs-cvs
vcs-darcs
vcs-git
vcs-hg
vcs-mtn
vcs-svn
);
my @src_dep_fields = qw(
build-depends
build-depends-arch
build-depends-indep
build-conflicts
build-conflicts-arch
build-conflicts-indep
);
my @bin_dep_fields = qw(
pre-depends
depends
recommends
suggests
enhances
conflicts
breaks
replaces
provides
built-using
static-built-using
);
my @src_test_fields = qw(
testsuite
testsuite-triggers
);
my @src_checksums_fields = qw(
checksums-md5
checksums-sha1
checksums-sha256
);
my @bin_checksums_fields = qw(
md5sum
sha1
sha256
);
our %FIELD_ORDER = (
CTRL_TMPL_SRC() => [
qw(
source
section
priority
maintainer
uploaders
origin
bugs
),
@src_vcs_fields,
qw(
homepage
standards-version
rules-requires-root
),
@src_dep_fields,
@src_test_fields,
qw(
description
),
],
CTRL_TMPL_PKG() => [
qw(
package
package-type
section
priority
architecture
subarchitecture
multi-arch
essential
protected
build-essential
build-profiles
built-for-profiles
kernel-version
),
@bin_dep_fields,
qw(
homepage
installer-menu-item
task
tag
description
),
],
CTRL_DSC() => [
qw(
format
source
binary
architecture
version
origin
maintainer
uploaders
homepage
description
standards-version
),
@src_vcs_fields,
@src_test_fields,
@src_dep_fields,
qw(
package-list
),
@src_checksums_fields,
qw(
files
),
],
CTRL_DEB() => [
qw(
package
package-type
source
version
kernel-version
built-for-profiles
auto-built-package
architecture
subarchitecture
installer-menu-item
build-essential
essential
protected
origin
bugs
maintainer
installed-size
),
@bin_dep_fields,
qw(
section
priority
multi-arch
homepage
description
tag
task
),
],
CTRL_REPO_SRC() => [
qw(
format
package
binary
architecture
version
priority
section
origin
maintainer
uploaders
homepage
description
standards-version
),
@src_vcs_fields,
@src_test_fields,
@src_dep_fields,
qw(
package-list
directory
),
@src_checksums_fields,
qw(
files
),
],
CTRL_REPO_PKG() => [
qw(
package
package-type
source
version
kernel-version
built-for-profiles
auto-built-package
architecture
subarchitecture
installer-menu-item
build-essential
essential
protected
origin
bugs
maintainer
installed-size
),
@bin_dep_fields,
qw(
filename
size
),
@bin_checksums_fields,
qw(
section
priority
multi-arch
homepage
description
tag
task
),
],
CTRL_REPO_RELEASE() => [
qw(
origin
label
suite
version
codename
changelogs
date
valid-until
notautomatic
butautomaticupgrades
acquire-by-hash
no-support-for-architecture-all
architectures
components
description
),
@bin_checksums_fields
],
CTRL_CHANGELOG() => [
qw(
source
binary-only
version
distribution
urgency
maintainer
timestamp
date
closes
changes
),
],
CTRL_COPYRIGHT_HEADER() => [
qw(
format
upstream-name
upstream-contact
source
disclaimer
comment
license
copyright
),
],
CTRL_COPYRIGHT_FILES() => [
qw(
files
copyright
license
comment
),
],
CTRL_COPYRIGHT_LICENSE() => [
qw(
license
comment
),
],
CTRL_FILE_BUILDINFO() => [
qw(
format
source
binary
architecture
version
binary-only-changes
),
@src_checksums_fields,
qw(
build-origin
build-architecture
build-kernel-version
build-date
build-path
build-tainted-by
installed-build-depends
environment
),
],
CTRL_FILE_CHANGES() => [
qw(
format
date
source
binary
binary-only
built-for-profiles
architecture
version
distribution
urgency
maintainer
changed-by
description
closes
changes
),
@src_checksums_fields,
qw(
files
),
],
CTRL_FILE_VENDOR() => [
qw(
vendor
vendor-url
bugs
parent
),
],
CTRL_FILE_STATUS() => [
# Same as fieldinfos in «lib/dpkg/parse.c».
qw(
package
essential
protected
status
priority
section
installed-size
origin
maintainer
bugs
architecture
multi-arch
source
version
config-version
replaces
provides
depends
pre-depends
recommends
suggests
breaks
conflicts
enhances
conffiles
description
triggers-pending
triggers-awaited
),
# These are allowed here, but not tracked by lib/dpkg/parse.c.
qw(
auto-built-package
build-essential
built-for-profiles
built-using
static-built-using
homepage
installer-menu-item
kernel-version
package-type
subarchitecture
tag
task
),
],
CTRL_TESTS() => [
qw(
test-command
tests
tests-directory
architecture
restrictions
features
classes
depends
),
],
);
=head1 FUNCTIONS
=over 4
=item $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 hyphen in field names).
=cut
sub field_capitalize {
my $field = lc(shift);
# Use known fields first.
return $FIELDS{$field}{name} if exists $FIELDS{$field};
# Generic case.
return join '-', map { ucfirst } split /-/, $field;
}
=item $bool = field_is_official($fname)
Returns true if the field is official and known.
=cut
sub field_is_official {
my $field = lc shift;
return exists $FIELDS{$field};
}
=item $bool = 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 = lc $field;
return unless exists $FIELDS{$field};
return 0 if not scalar(@types);
foreach my $type (@types) {
# Unknown control type is always allowed.
next if $type == CTRL_UNKNOWN;
return 0 unless $FIELDS{$field}{allowed} & $type;
}
return 1;
}
=item $new_field = field_transfer_single($from, $to, $field)
If appropriate, copy the value of the field named $field taken from the
$from L<Dpkg::Control> object to the $to L<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_DSC, CTRL_DEB or CTRL_FILE_CHANGES, then they
are always 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_DSC), "B"
(Binary: corresponds to CTRL_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) = @_;
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 =~ /SC/i and $from_type == CTRL_TMPL_PKG) {
warning(g_('non-sensical field export rules (%s) in field %s in ' .
'binary stanza from source package template control file'),
$dest, $field);
}
if (($dest =~ /B/i and $to_type == CTRL_DEB) or
($dest =~ /S/i and $to_type == CTRL_DSC) 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_DEB and
$to_type != CTRL_DSC 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;
}
=item @field_list = 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_list = 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 = shift;
if (exists $FIELD_ORDER{$type}) {
return map { $FIELDS{$_}{name} } @{$FIELD_ORDER{$type}};
}
return ();
}
=item ($source, $version) = field_parse_binary_source($ctrl)
Parse the B<Source> field in a binary package control stanza. The field
contains the source package name where it was built from, and optionally
a space and the source version enclosed in parenthesis if it is different
from the binary version.
Returns a list with the $source name, and the source $version, or undef
or an empty list when $ctrl does not contain a binary package control stanza.
Neither $source nor $version are validated, but that can be done with
Dpkg::Package::pkg_name_is_invalid() and Dpkg::Version::version_check().
=cut
sub field_parse_binary_source {
my $ctrl = shift;
my $ctrl_type = $ctrl->get_type();
if ($ctrl_type != CTRL_REPO_PKG and
$ctrl_type != CTRL_DEB and
$ctrl_type != CTRL_FILE_CHANGES and
$ctrl_type != CTRL_FILE_BUILDINFO and
$ctrl_type != CTRL_FILE_STATUS) {
return;
}
my ($source, $version);
# For .changes and .buildinfo the Source field always exists,
# and there is no Package field.
if (exists $ctrl->{'Source'}) {
$source = $ctrl->{'Source'};
if ($source =~ m/^([^ ]+) +\(([^)]*)\)$/) {
$source = $1;
$version = $2;
} else {
$version = $ctrl->{'Version'};
}
} else {
$source = $ctrl->{'Package'};
$version = $ctrl->{'Version'};
}
return ($source, $version);
}
=item @field_list = field_list_src_dep()
List of fields that contains dependencies-like information in a source
Debian package.
=cut
sub field_list_src_dep {
my @list = map {
$FIELDS{$_}{name}
} sort {
$FIELDS{$a}{dep_order} <=> $FIELDS{$b}{dep_order}
} grep {
field_is_allowed_in($_, CTRL_DSC) and
exists $FIELDS{$_}{dependency}
} keys %FIELDS;
return @list;
}
=item @field_list = 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 @list = map {
$FIELDS{$_}{name}
} sort {
$FIELDS{$a}{dep_order} <=> $FIELDS{$b}{dep_order}
} grep {
field_is_allowed_in($_, CTRL_DEB) and
exists $FIELDS{$_}{dependency}
} keys %FIELDS;
return @list;
}
=item $dep_type = 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 = lc shift;
return $FIELDS{$field}{dependency}
if exists $FIELDS{$field} && exists $FIELDS{$field}{dependency};
return;
}
=item $sep_type = field_get_sep_type($field)
Return the type of the field value separator. Can be one of FIELD_SEP_UNKNOWN,
FIELD_SEP_SPACE, FIELD_SEP_COMMA or FIELD_SEP_LINE.
=cut
sub field_get_sep_type {
my $field = lc shift;
return $FIELDS{$field}{separator}
if exists $FIELDS{$field} && exists $FIELDS{$field}{separator};
return FIELD_SEP_UNKNOWN;
}
=item $value = field_get_default_value($field)
Return the default value (if any) for the field. If there is no default value
then it returns "undef".
=cut
sub field_get_default_value {
my $field = lc shift;
return $FIELDS{$field}{default}
if exists $FIELDS{$field} && exists $FIELDS{$field}{default};
return;
}
=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 = lc $field;
$FIELDS{$field} = {
name => field_capitalize($field),
allowed => $types,
%opts
};
return;
}
=item $bool = field_insert_after($type, $ref, @fields)
Place field after another one ($ref) in output of control information of
type $type.
Return true if the field was inserted, otherwise false.
=cut
sub field_insert_after {
my ($type, $field, @fields) = @_;
return 0 if not exists $FIELD_ORDER{$type};
($field, @fields) = map { lc } ($field, @fields);
@{$FIELD_ORDER{$type}} = map {
($_ eq $field) ? ($_, @fields) : $_
} @{$FIELD_ORDER{$type}};
return 1;
}
=item $bool = field_insert_before($type, $ref, @fields)
Place field before another one ($ref) in output of control information of
type $type.
Return true if the field was inserted, otherwise false.
=cut
sub field_insert_before {
my ($type, $field, @fields) = @_;
return 0 if not exists $FIELD_ORDER{$type};
($field, @fields) = map { lc } ($field, @fields);
@{$FIELD_ORDER{$type}} = map {
($_ eq $field) ? (@fields, $_) : $_
} @{$FIELD_ORDER{$type}};
return 1;
}
=back
=head1 CHANGES
=head2 Version 1.04 (dpkg 1.23.0)
Remove argument: field_transfer_single() implicit argument usage.
=head2 Version 1.03 (dpkg 1.22.12)
New function: field_get_default_value().
=head2 Version 1.02 (dpkg 1.22.0)
Deprecate argument: field_transfer_single() implicit argument usage.
=head2 Version 1.01 (dpkg 1.21.0)
New function: field_parse_binary_source().
=head2 Version 1.00 (dpkg 1.17.0)
Mark the module as public.
=cut
1;
|