aboutsummaryrefslogtreecommitdiff
path: root/archival/dpkg.c
diff options
context:
space:
mode:
authorandersen <andersen@69ca8d6d-28ef-0310-b511-8ec308f3f277>2004-03-15 08:29:22 +0000
committerandersen <andersen@69ca8d6d-28ef-0310-b511-8ec308f3f277>2004-03-15 08:29:22 +0000
commitb16674f3c1a961e0b5d6a57745f5f749d95c641e (patch)
tree4c6d2217f4d8306c59cf1096f8664e1cfd167213 /archival/dpkg.c
parente7135df4a650f9197b633784472f45602524855b (diff)
downloadbusybox-w32-b16674f3c1a961e0b5d6a57745f5f749d95c641e.tar.gz
busybox-w32-b16674f3c1a961e0b5d6a57745f5f749d95c641e.tar.bz2
busybox-w32-b16674f3c1a961e0b5d6a57745f5f749d95c641e.zip
Remove trailing whitespace. Update copyright to include 2004.
git-svn-id: svn://busybox.net/trunk/busybox@8630 69ca8d6d-28ef-0310-b511-8ec308f3f277
Diffstat (limited to 'archival/dpkg.c')
-rw-r--r--archival/dpkg.c84
1 files changed, 42 insertions, 42 deletions
diff --git a/archival/dpkg.c b/archival/dpkg.c
index 2ebbbdf4e..e192b4a62 100644
--- a/archival/dpkg.c
+++ b/archival/dpkg.c
@@ -4,7 +4,7 @@
4 * 4 *
5 * Written By Glenn McGrath with the help of others 5 * Written By Glenn McGrath with the help of others
6 * Copyright (C) 2001 by Glenn McGrath 6 * Copyright (C) 2001 by Glenn McGrath
7 * 7 *
8 * Started life as a busybox implementation of udpkg 8 * Started life as a busybox implementation of udpkg
9 * 9 *
10 * This program is free software; you can redistribute it and/or modify 10 * This program is free software; you can redistribute it and/or modify
@@ -54,7 +54,7 @@
54 * int's and chaos is assured, 16381 is the max prime for 14 bit field 54 * int's and chaos is assured, 16381 is the max prime for 14 bit field
55 */ 55 */
56 56
57/* NAME_HASH_PRIME, Stores package names and versions, 57/* NAME_HASH_PRIME, Stores package names and versions,
58 * I estimate it should be at least 50% bigger than PACKAGE_HASH_PRIME, 58 * I estimate it should be at least 50% bigger than PACKAGE_HASH_PRIME,
59 * as there a lot of duplicate version numbers */ 59 * as there a lot of duplicate version numbers */
60#define NAME_HASH_PRIME 16381 60#define NAME_HASH_PRIME 16381
@@ -150,7 +150,7 @@ void make_hash(const char *key, unsigned int *start, unsigned int *decrement, co
150 * shift amount is mod 24 because long int is 32 bit and data 150 * shift amount is mod 24 because long int is 32 bit and data
151 * to be shifted is 8, dont want to shift data to where it has 151 * to be shifted is 8, dont want to shift data to where it has
152 * no effect*/ 152 * no effect*/
153 hash_num += ((key[i] + key[i-1]) << ((key[i] * i) % 24)); 153 hash_num += ((key[i] + key[i-1]) << ((key[i] * i) % 24));
154 } 154 }
155 *start = (unsigned int) hash_num % hash_prime; 155 *start = (unsigned int) hash_num % hash_prime;
156 *decrement = (unsigned int) 1 + (hash_num % (hash_prime - 1)); 156 *decrement = (unsigned int) 1 + (hash_num % (hash_prime - 1));
@@ -464,11 +464,11 @@ void add_split_dependencies(common_node_t *parent_node, const char *whole_line,
464 } else { 464 } else {
465 or_edge = NULL; 465 or_edge = NULL;
466 } 466 }
467 467
468 if ( or_edge ) { 468 if ( or_edge ) {
469 or_edge->name = search_name_hashtable(field); 469 or_edge->name = search_name_hashtable(field);
470 or_edge->version = 0; // tracks the number of altenatives 470 or_edge->version = 0; // tracks the number of altenatives
471 471
472 add_edge_to_node(parent_node, or_edge); 472 add_edge_to_node(parent_node, or_edge);
473 } 473 }
474 474
@@ -572,7 +572,7 @@ unsigned int fill_package_struct(char *control_buffer)
572 goto fill_package_struct_cleanup; /* Oh no, the dreaded goto statement ! */ 572 goto fill_package_struct_cleanup; /* Oh no, the dreaded goto statement ! */
573 } 573 }
574 574
575 field_num = compare_string_array(field_names, field_name); 575 field_num = compare_string_array(field_names, field_name);
576 switch(field_num) { 576 switch(field_num) {
577 case 0: /* Package */ 577 case 0: /* Package */
578 new_node->name = search_name_hashtable(field_value); 578 new_node->name = search_name_hashtable(field_value);
@@ -697,7 +697,7 @@ const char *describe_status(int status_num) {
697 return "is marked to be removed"; 697 return "is marked to be removed";
698 if ( status_want == search_name_hashtable("purge") ) 698 if ( status_want == search_name_hashtable("purge") )
699 return "is marked to be purged"; 699 return "is marked to be purged";
700 } 700 }
701 if ( status_want == search_name_hashtable("unknown") ) 701 if ( status_want == search_name_hashtable("unknown") )
702 return "is in an indeterminate state"; 702 return "is in an indeterminate state";
703 if ( status_want == search_name_hashtable("install") ) 703 if ( status_want == search_name_hashtable("install") )
@@ -957,11 +957,11 @@ void write_status_file(deb_file_t **deb_file)
957 957
958 /* Create a seperate backfile to dpkg */ 958 /* Create a seperate backfile to dpkg */
959 if (rename("/var/lib/dpkg/status", "/var/lib/dpkg/status.udeb.bak") == -1) { 959 if (rename("/var/lib/dpkg/status", "/var/lib/dpkg/status.udeb.bak") == -1) {
960 struct stat stat_buf; 960 struct stat stat_buf;
961 if (stat("/var/lib/dpkg/status", &stat_buf) == 0) { 961 if (stat("/var/lib/dpkg/status", &stat_buf) == 0) {
962 bb_error_msg_and_die("Couldnt create backup status file"); 962 bb_error_msg_and_die("Couldnt create backup status file");
963 } 963 }
964 /* Its ok if renaming the status file fails becasue status 964 /* Its ok if renaming the status file fails becasue status
965 * file doesnt exist, maybe we are starting from scratch */ 965 * file doesnt exist, maybe we are starting from scratch */
966 bb_error_msg("No status file found, creating new one"); 966 bb_error_msg("No status file found, creating new one");
967 } 967 }
@@ -1056,10 +1056,10 @@ int check_deps(deb_file_t **deb_file, int deb_start, int dep_max_count)
1056 const edge_t *package_edge = package_node->edge[j]; 1056 const edge_t *package_edge = package_node->edge[j];
1057 1057
1058 if (package_edge->type == EDGE_CONFLICTS) { 1058 if (package_edge->type == EDGE_CONFLICTS) {
1059 const unsigned int package_num = 1059 const unsigned int package_num =
1060 search_package_hashtable(package_edge->name, 1060 search_package_hashtable(package_edge->name,
1061 package_edge->version, 1061 package_edge->version,
1062 package_edge->operator); 1062 package_edge->operator);
1063 int result = 0; 1063 int result = 0;
1064 if (package_hashtable[package_num] != NULL) { 1064 if (package_hashtable[package_num] != NULL) {
1065 status_num = search_status_hashtable(name_hashtable[package_hashtable[package_num]->name]); 1065 status_num = search_status_hashtable(name_hashtable[package_hashtable[package_num]->name]);
@@ -1078,7 +1078,7 @@ int check_deps(deb_file_t **deb_file, int deb_start, int dep_max_count)
1078 } 1078 }
1079 } 1079 }
1080 i++; 1080 i++;
1081 } 1081 }
1082 1082
1083 1083
1084 /* Check dependendcies */ 1084 /* Check dependendcies */
@@ -1098,7 +1098,7 @@ int check_deps(deb_file_t **deb_file, int deb_start, int dep_max_count)
1098 1098
1099 /* If there is no status then this package is a 1099 /* If there is no status then this package is a
1100 * virtual one provided by something else. In which 1100 * virtual one provided by something else. In which
1101 * case there are no dependencies to check. 1101 * case there are no dependencies to check.
1102 */ 1102 */
1103 if ( status_hashtable[status_num] == NULL ) continue; 1103 if ( status_hashtable[status_num] == NULL ) continue;
1104 1104
@@ -1125,7 +1125,7 @@ int check_deps(deb_file_t **deb_file, int deb_start, int dep_max_count)
1125 for (j = 0; j < package_node->num_of_edges; j++) { 1125 for (j = 0; j < package_node->num_of_edges; j++) {
1126 const edge_t *package_edge = package_node->edge[j]; 1126 const edge_t *package_edge = package_node->edge[j];
1127 unsigned int package_num; 1127 unsigned int package_num;
1128 1128
1129 if ( package_edge->type == EDGE_OR_PRE_DEPENDS || 1129 if ( package_edge->type == EDGE_OR_PRE_DEPENDS ||
1130 package_edge->type == EDGE_OR_DEPENDS ) { /* start an EDGE_OR_ list */ 1130 package_edge->type == EDGE_OR_DEPENDS ) { /* start an EDGE_OR_ list */
1131 number_of_alternatives = package_edge->version; 1131 number_of_alternatives = package_edge->version;
@@ -1147,26 +1147,26 @@ int check_deps(deb_file_t **deb_file, int deb_start, int dep_max_count)
1147 * this edge is the right type. 1147 * this edge is the right type.
1148 * 1148 *
1149 * EDGE_DEPENDS == OR_DEPENDS -1 1149 * EDGE_DEPENDS == OR_DEPENDS -1
1150 * EDGE_PRE_DEPENDS == OR_PRE_DEPENDS -1 1150 * EDGE_PRE_DEPENDS == OR_PRE_DEPENDS -1
1151 */ 1151 */
1152 if ( root_of_alternatives && package_edge->type != root_of_alternatives->type - 1) 1152 if ( root_of_alternatives && package_edge->type != root_of_alternatives->type - 1)
1153 bb_error_msg_and_die("Fatal error. Package dependencies corrupt: %d != %d - 1 \n", 1153 bb_error_msg_and_die("Fatal error. Package dependencies corrupt: %d != %d - 1 \n",
1154 package_edge->type, root_of_alternatives->type); 1154 package_edge->type, root_of_alternatives->type);
1155 1155
1156 if (package_hashtable[package_num] != NULL) 1156 if (package_hashtable[package_num] != NULL)
1157 result = !package_satisfies_dependency(package_num, package_edge->type); 1157 result = !package_satisfies_dependency(package_num, package_edge->type);
1158 1158
1159 if (result) { /* check for other package which provide what we are looking for */ 1159 if (result) { /* check for other package which provide what we are looking for */
1160 int provider = -1; 1160 int provider = -1;
1161 1161
1162 while ( (provider = search_for_provides(package_edge->name, provider) ) > -1 ) { 1162 while ( (provider = search_for_provides(package_edge->name, provider) ) > -1 ) {
1163 if ( package_hashtable[provider] == NULL ) { 1163 if ( package_hashtable[provider] == NULL ) {
1164 printf("Have a provider but no package information for it\n"); 1164 printf("Have a provider but no package information for it\n");
1165 continue; 1165 continue;
1166 } 1166 }
1167 result = !package_satisfies_dependency(provider, package_edge->type); 1167 result = !package_satisfies_dependency(provider, package_edge->type);
1168 1168
1169 if ( result == 0 ) 1169 if ( result == 0 )
1170 break; 1170 break;
1171 } 1171 }
1172 } 1172 }
@@ -1176,14 +1176,14 @@ int check_deps(deb_file_t **deb_file, int deb_start, int dep_max_count)
1176 if (result && number_of_alternatives == 0) { 1176 if (result && number_of_alternatives == 0) {
1177 if ( root_of_alternatives ) 1177 if ( root_of_alternatives )
1178 bb_error_msg_and_die( 1178 bb_error_msg_and_die(
1179 "Package %s %sdepends on %s, " 1179 "Package %s %sdepends on %s, "
1180 "which cannot be satisfied", 1180 "which cannot be satisfied",
1181 name_hashtable[package_node->name], 1181 name_hashtable[package_node->name],
1182 package_edge->type == EDGE_PRE_DEPENDS ? "pre-" : "", 1182 package_edge->type == EDGE_PRE_DEPENDS ? "pre-" : "",
1183 name_hashtable[root_of_alternatives->name]); 1183 name_hashtable[root_of_alternatives->name]);
1184 else 1184 else
1185 bb_error_msg_and_die( 1185 bb_error_msg_and_die(
1186 "Package %s %sdepends on %s, which %s\n", 1186 "Package %s %sdepends on %s, which %s\n",
1187 name_hashtable[package_node->name], 1187 name_hashtable[package_node->name],
1188 package_edge->type == EDGE_PRE_DEPENDS ? "pre-" : "", 1188 package_edge->type == EDGE_PRE_DEPENDS ? "pre-" : "",
1189 name_hashtable[package_edge->name], 1189 name_hashtable[package_edge->name],
@@ -1192,7 +1192,7 @@ int check_deps(deb_file_t **deb_file, int deb_start, int dep_max_count)
1192 /* we've found a package which 1192 /* we've found a package which
1193 * satisfies the dependency, 1193 * satisfies the dependency,
1194 * so skip over the rest of 1194 * so skip over the rest of
1195 * the alternatives. 1195 * the alternatives.
1196 */ 1196 */
1197 j += number_of_alternatives; 1197 j += number_of_alternatives;
1198 number_of_alternatives = 0; 1198 number_of_alternatives = 0;
@@ -1312,7 +1312,7 @@ char **all_control_list(const char *package_name)
1312 1312
1313void free_array(char **array) 1313void free_array(char **array)
1314{ 1314{
1315 1315
1316 if (array) { 1316 if (array) {
1317 unsigned short i = 0; 1317 unsigned short i = 0;
1318 while (array[i]) { 1318 while (array[i]) {
@@ -1325,7 +1325,7 @@ void free_array(char **array)
1325 1325
1326/* This function lists information on the installed packages. It loops through 1326/* This function lists information on the installed packages. It loops through
1327 * the status_hashtable to retrieve the info. This results in smaller code than 1327 * the status_hashtable to retrieve the info. This results in smaller code than
1328 * scanning the status file. The resulting list, however, is unsorted. 1328 * scanning the status file. The resulting list, however, is unsorted.
1329 */ 1329 */
1330void list_packages(void) 1330void list_packages(void)
1331{ 1331{
@@ -1333,7 +1333,7 @@ void list_packages(void)
1333 1333
1334 printf(" Name Version\n"); 1334 printf(" Name Version\n");
1335 printf("+++-==============-==============\n"); 1335 printf("+++-==============-==============\n");
1336 1336
1337 /* go through status hash, dereference package hash and finally strings */ 1337 /* go through status hash, dereference package hash and finally strings */
1338 for (i=0; i<STATUS_HASH_PRIME+1; i++) { 1338 for (i=0; i<STATUS_HASH_PRIME+1; i++) {
1339 1339
@@ -1342,22 +1342,22 @@ void list_packages(void)
1342 const char *name_str; /* package name */ 1342 const char *name_str; /* package name */
1343 const char *vers_str; /* version */ 1343 const char *vers_str; /* version */
1344 char s1, s2; /* status abbreviations */ 1344 char s1, s2; /* status abbreviations */
1345 int spccnt; /* space count */ 1345 int spccnt; /* space count */
1346 int j; 1346 int j;
1347 1347
1348 stat_str = name_hashtable[status_hashtable[i]->status]; 1348 stat_str = name_hashtable[status_hashtable[i]->status];
1349 name_str = name_hashtable[package_hashtable[status_hashtable[i]->package]->name]; 1349 name_str = name_hashtable[package_hashtable[status_hashtable[i]->package]->name];
1350 vers_str = name_hashtable[package_hashtable[status_hashtable[i]->package]->version]; 1350 vers_str = name_hashtable[package_hashtable[status_hashtable[i]->package]->version];
1351 1351
1352 /* get abbreviation for status field 1 */ 1352 /* get abbreviation for status field 1 */
1353 s1 = stat_str[0] == 'i' ? 'i' : 'r'; 1353 s1 = stat_str[0] == 'i' ? 'i' : 'r';
1354 1354
1355 /* get abbreviation for status field 2 */ 1355 /* get abbreviation for status field 2 */
1356 for (j=0, spccnt=0; stat_str[j] && spccnt<2; j++) { 1356 for (j=0, spccnt=0; stat_str[j] && spccnt<2; j++) {
1357 if (stat_str[j] == ' ') spccnt++; 1357 if (stat_str[j] == ' ') spccnt++;
1358 } 1358 }
1359 s2 = stat_str[j]; 1359 s2 = stat_str[j];
1360 1360
1361 /* print out the line formatted like Debian dpkg */ 1361 /* print out the line formatted like Debian dpkg */
1362 printf("%c%c %-14s %s\n", s1, s2, name_str, vers_str); 1362 printf("%c%c %-14s %s\n", s1, s2, name_str, vers_str);
1363 } 1363 }
@@ -1376,7 +1376,7 @@ void remove_package(const unsigned int package_num, int noisy)
1376 char conffile_name[package_name_length + 30]; 1376 char conffile_name[package_name_length + 30];
1377 int return_value; 1377 int return_value;
1378 1378
1379 if ( noisy ) 1379 if ( noisy )
1380 printf("Removing %s (%s) ...\n", package_name, package_version); 1380 printf("Removing %s (%s) ...\n", package_name, package_version);
1381 1381
1382 /* run prerm script */ 1382 /* run prerm script */
@@ -1464,12 +1464,12 @@ static archive_handle_t *init_archive_deb_ar(const char *filename)
1464{ 1464{
1465 archive_handle_t *ar_handle; 1465 archive_handle_t *ar_handle;
1466 1466
1467 /* Setup an ar archive handle that refers to the gzip sub archive */ 1467 /* Setup an ar archive handle that refers to the gzip sub archive */
1468 ar_handle = init_handle(); 1468 ar_handle = init_handle();
1469 ar_handle->filter = filter_accept_list_reassign; 1469 ar_handle->filter = filter_accept_list_reassign;
1470 ar_handle->src_fd = bb_xopen(filename, O_RDONLY); 1470 ar_handle->src_fd = bb_xopen(filename, O_RDONLY);
1471 1471
1472 return(ar_handle); 1472 return(ar_handle);
1473} 1473}
1474 1474
1475static void init_archive_deb_control(archive_handle_t *ar_handle) 1475static void init_archive_deb_control(archive_handle_t *ar_handle)
@@ -1491,7 +1491,7 @@ static void init_archive_deb_control(archive_handle_t *ar_handle)
1491 /* Assign the tar handle as a subarchive of the ar handle */ 1491 /* Assign the tar handle as a subarchive of the ar handle */
1492 ar_handle->sub_archive = tar_handle; 1492 ar_handle->sub_archive = tar_handle;
1493 1493
1494 return; 1494 return;
1495} 1495}
1496 1496
1497static void init_archive_deb_data(archive_handle_t *ar_handle) 1497static void init_archive_deb_data(archive_handle_t *ar_handle)
@@ -1513,7 +1513,7 @@ static void init_archive_deb_data(archive_handle_t *ar_handle)
1513 /* Assign the tar handle as a subarchive of the ar handle */ 1513 /* Assign the tar handle as a subarchive of the ar handle */
1514 ar_handle->sub_archive = tar_handle; 1514 ar_handle->sub_archive = tar_handle;
1515 1515
1516 return; 1516 return;
1517} 1517}
1518 1518
1519static char *deb_extract_control_file_to_buffer(archive_handle_t *ar_handle, llist_t *myaccept) 1519static char *deb_extract_control_file_to_buffer(archive_handle_t *ar_handle, llist_t *myaccept)
@@ -1586,7 +1586,7 @@ static void unpack_package(deb_file_t *deb_file)
1586 if (run_package_script(package_name, "preinst") != 0) { 1586 if (run_package_script(package_name, "preinst") != 0) {
1587 /* when preinst returns exit code != 0 then quit installation process */ 1587 /* when preinst returns exit code != 0 then quit installation process */
1588 bb_error_msg_and_die("subprocess pre-installation script returned error."); 1588 bb_error_msg_and_die("subprocess pre-installation script returned error.");
1589 } 1589 }
1590 1590
1591 /* Extract data.tar.gz to the root directory */ 1591 /* Extract data.tar.gz to the root directory */
1592 archive_handle = init_archive_deb_ar(deb_file->filename); 1592 archive_handle = init_archive_deb_ar(deb_file->filename);
@@ -1598,7 +1598,7 @@ static void unpack_package(deb_file_t *deb_file)
1598 1598
1599 /* Create the list file */ 1599 /* Create the list file */
1600 strcat(info_prefix, "list"); 1600 strcat(info_prefix, "list");
1601 out_stream = bb_xfopen(info_prefix, "w"); 1601 out_stream = bb_xfopen(info_prefix, "w");
1602 while (archive_handle->sub_archive->passed) { 1602 while (archive_handle->sub_archive->passed) {
1603 /* the leading . has been stripped by data_extract_all_prefix already */ 1603 /* the leading . has been stripped by data_extract_all_prefix already */
1604 fputs(archive_handle->sub_archive->passed->data, out_stream); 1604 fputs(archive_handle->sub_archive->passed->data, out_stream);
@@ -1653,7 +1653,7 @@ int dpkg_main(int argc, char **argv)
1653 case 'F': // equivalent to --force in official dpkg 1653 case 'F': // equivalent to --force in official dpkg
1654 if (strcmp(optarg, "depends") == 0) { 1654 if (strcmp(optarg, "depends") == 0) {
1655 dpkg_opt |= dpkg_opt_force_ignore_depends; 1655 dpkg_opt |= dpkg_opt_force_ignore_depends;
1656 } 1656 }
1657 break; 1657 break;
1658 case 'i': 1658 case 'i':
1659 dpkg_opt |= dpkg_opt_install; 1659 dpkg_opt |= dpkg_opt_install;
@@ -1691,7 +1691,7 @@ int dpkg_main(int argc, char **argv)
1691 list_packages(); 1691 list_packages();
1692 return(EXIT_SUCCESS); 1692 return(EXIT_SUCCESS);
1693 } 1693 }
1694 1694
1695 /* Read arguments and store relevant info in structs */ 1695 /* Read arguments and store relevant info in structs */
1696 while (optind < argc) { 1696 while (optind < argc) {
1697 /* deb_count = nb_elem - 1 and we need nb_elem + 1 to allocate terminal node [NULL pointer] */ 1697 /* deb_count = nb_elem - 1 and we need nb_elem + 1 to allocate terminal node [NULL pointer] */