diff options
author | Glenn L McGrath <bug1@ihug.co.nz> | 2002-11-06 22:54:41 +0000 |
---|---|---|
committer | Glenn L McGrath <bug1@ihug.co.nz> | 2002-11-06 22:54:41 +0000 |
commit | 747381c602bac435cedcf782bce52123d827324d (patch) | |
tree | 0ff43ea173e16c81efb61f1d9e27d250ddc43490 | |
parent | ea12202288be762db38f4178d36fddfc30c3226a (diff) | |
download | busybox-w32-747381c602bac435cedcf782bce52123d827324d.tar.gz busybox-w32-747381c602bac435cedcf782bce52123d827324d.tar.bz2 busybox-w32-747381c602bac435cedcf782bce52123d827324d.zip |
Split deb_extract() into more generic functions
-rw-r--r-- | archival/dpkg.c | 119 |
1 files changed, 76 insertions, 43 deletions
diff --git a/archival/dpkg.c b/archival/dpkg.c index 937726a0c..b1aeebf80 100644 --- a/archival/dpkg.c +++ b/archival/dpkg.c | |||
@@ -1311,32 +1311,73 @@ void purge_package(const unsigned int package_num) | |||
1311 | set_status(status_num, "not-installed", 3); | 1311 | set_status(status_num, "not-installed", 3); |
1312 | } | 1312 | } |
1313 | 1313 | ||
1314 | static archive_handle_t *deb_extract(const char *filename, const llist_t *accept_list, | 1314 | static archive_handle_t *init_archive_deb_ar(const char *filename) |
1315 | const char *tar_gz_name, char *prefix, void (*deb_action_data)(struct archive_handle_s *)) | ||
1316 | { | 1315 | { |
1317 | archive_handle_t *ar_archive; | 1316 | archive_handle_t *ar_handle; |
1318 | archive_handle_t *tar_archive; | 1317 | |
1318 | /* Setup an ar archive handle that refers to the gzip sub archive */ | ||
1319 | ar_handle = init_handle(); | ||
1320 | ar_handle->filter = filter_accept_list_reassign; | ||
1321 | ar_handle->src_fd = xopen(filename, O_RDONLY); | ||
1322 | |||
1323 | return(ar_handle); | ||
1324 | } | ||
1325 | |||
1326 | static void init_archive_deb_control(archive_handle_t *ar_handle) | ||
1327 | { | ||
1328 | archive_handle_t *tar_handle; | ||
1319 | 1329 | ||
1320 | /* Setup the tar archive handle */ | 1330 | /* Setup the tar archive handle */ |
1321 | tar_archive = init_handle(); | 1331 | tar_handle = init_handle(); |
1322 | tar_archive->filter = filter_accept_reject_list; | 1332 | tar_handle->filter = filter_accept_list; |
1323 | tar_archive->action_data = deb_action_data; | 1333 | tar_handle->src_fd = ar_handle->src_fd; |
1324 | tar_archive->buffer = prefix; | ||
1325 | if (tar_gz_name) { | ||
1326 | tar_archive->accept = add_to_list(NULL, tar_gz_name); | ||
1327 | } | ||
1328 | 1334 | ||
1329 | /* Setup an ar archive handle that refers to the gzip sub archive */ | 1335 | /* We dont care about data.tar.* or debian-binary, just control.tar.* */ |
1330 | ar_archive = init_handle(); | 1336 | #ifdef CONFIG_FEATURE_DEB_TAR_GZ |
1331 | ar_archive->sub_archive = tar_archive; | 1337 | ar_handle->accept = add_to_list(NULL, "control.tar.gz"); |
1332 | ar_archive->filter = filter_accept_list_reassign; | 1338 | #endif |
1333 | ar_archive->accept = accept_list; | 1339 | #ifdef CONFIG_FEATURE_DEB_TAR_BZ2 |
1340 | ar_handle->accept = add_to_list(ar_handle->accept, "control.tar.bz2"); | ||
1341 | #endif | ||
1342 | |||
1343 | /* Assign the tar handle as a subarchive of the ar handle */ | ||
1344 | ar_handle->sub_archive = tar_handle; | ||
1345 | |||
1346 | return; | ||
1347 | } | ||
1348 | |||
1349 | static void init_archive_deb_data(archive_handle_t *ar_handle) | ||
1350 | { | ||
1351 | archive_handle_t *tar_handle; | ||
1352 | |||
1353 | /* Setup the tar archive handle */ | ||
1354 | tar_handle = init_handle(); | ||
1355 | tar_handle->filter = filter_accept_all; | ||
1356 | tar_handle->src_fd = ar_handle->src_fd; | ||
1357 | |||
1358 | /* We dont care about data.tar.* or debian-binary, just control.tar.* */ | ||
1359 | #ifdef CONFIG_FEATURE_DEB_TAR_GZ | ||
1360 | tar_handle->accept = add_to_list(NULL, "data.tar.gz"); | ||
1361 | #endif | ||
1362 | #ifdef CONFIG_FEATURE_DEB_TAR_BZ2 | ||
1363 | tar_handle->accept = add_to_list(ar_handle->accept, "data.tar.bz2"); | ||
1364 | #endif | ||
1334 | 1365 | ||
1335 | tar_archive->src_fd = ar_archive->src_fd = xopen(filename, O_RDONLY); | 1366 | /* Assign the tar handle as a subarchive of the ar handle */ |
1336 | unpack_ar_archive(ar_archive); | 1367 | ar_handle->sub_archive = tar_handle; |
1337 | close(ar_archive->src_fd); | ||
1338 | 1368 | ||
1339 | return(ar_archive->sub_archive); | 1369 | return; |
1370 | } | ||
1371 | |||
1372 | static char *deb_extract_control_file_to_buffer(archive_handle_t *ar_handle, const llist_t *accept) | ||
1373 | { | ||
1374 | ar_handle->sub_archive->action_data = data_extract_to_buffer; | ||
1375 | ar_handle->sub_archive->accept = accept; | ||
1376 | |||
1377 | unpack_ar_archive(ar_handle); | ||
1378 | close(ar_handle->src_fd); | ||
1379 | |||
1380 | return(ar_handle->sub_archive->buffer); | ||
1340 | } | 1381 | } |
1341 | 1382 | ||
1342 | static void data_extract_all_prefix(archive_handle_t *archive_handle) | 1383 | static void data_extract_all_prefix(archive_handle_t *archive_handle) |
@@ -1361,18 +1402,6 @@ static void unpack_package(deb_file_t *deb_file) | |||
1361 | char *info_prefix; | 1402 | char *info_prefix; |
1362 | archive_handle_t *archive_handle; | 1403 | archive_handle_t *archive_handle; |
1363 | FILE *out_stream; | 1404 | FILE *out_stream; |
1364 | const llist_t *control_list = NULL; | ||
1365 | const llist_t *data_list = NULL; | ||
1366 | |||
1367 | #ifdef CONFIG_FEATURE_DEB_TAR_GZ | ||
1368 | data_list = add_to_list(NULL, "data.tar.gz"); | ||
1369 | control_list = add_to_list(NULL, "control.tar.gz"); | ||
1370 | #endif | ||
1371 | |||
1372 | #ifdef CONFIG_FEATURE_DEB_TAR_BZ2 | ||
1373 | data_list = add_to_list(data_list, "data.tar.bz2"); | ||
1374 | control_list = add_to_list(control_list, "control.tar.bz2"); | ||
1375 | #endif | ||
1376 | 1405 | ||
1377 | /* If existing version, remove it first */ | 1406 | /* If existing version, remove it first */ |
1378 | if (strcmp(name_hashtable[get_status(status_num, 3)], "installed") == 0) { | 1407 | if (strcmp(name_hashtable[get_status(status_num, 3)], "installed") == 0) { |
@@ -1388,8 +1417,12 @@ static void unpack_package(deb_file_t *deb_file) | |||
1388 | /* Extract control.tar.gz to /var/lib/dpkg/info/<package>.filename */ | 1417 | /* Extract control.tar.gz to /var/lib/dpkg/info/<package>.filename */ |
1389 | info_prefix = (char *) xmalloc(strlen(package_name) + 20 + 4 + 2); | 1418 | info_prefix = (char *) xmalloc(strlen(package_name) + 20 + 4 + 2); |
1390 | sprintf(info_prefix, "/var/lib/dpkg/info/%s.", package_name); | 1419 | sprintf(info_prefix, "/var/lib/dpkg/info/%s.", package_name); |
1420 | archive_handle = init_archive_deb_ar(deb_file->filename); | ||
1421 | init_archive_deb_control(archive_handle); | ||
1422 | archive_handle->sub_archive->action_data = data_extract_all_prefix; | ||
1423 | archive_handle->sub_archive->buffer = info_prefix; | ||
1424 | unpack_ar_archive(archive_handle); | ||
1391 | 1425 | ||
1392 | deb_extract(deb_file->filename, control_list, NULL, info_prefix, data_extract_all_prefix); | ||
1393 | /* Run the preinst prior to extracting */ | 1426 | /* Run the preinst prior to extracting */ |
1394 | if (run_package_script(package_name, "preinst") != 0) { | 1427 | if (run_package_script(package_name, "preinst") != 0) { |
1395 | /* when preinst returns exit code != 0 then quit installation process */ | 1428 | /* when preinst returns exit code != 0 then quit installation process */ |
@@ -1397,7 +1430,9 @@ static void unpack_package(deb_file_t *deb_file) | |||
1397 | } | 1430 | } |
1398 | 1431 | ||
1399 | /* Extract data.tar.gz to the root directory */ | 1432 | /* Extract data.tar.gz to the root directory */ |
1400 | archive_handle = deb_extract(deb_file->filename, data_list, NULL, NULL, data_extract_all); | 1433 | archive_handle = init_archive_deb_ar(deb_file->filename); |
1434 | init_archive_deb_data(archive_handle); | ||
1435 | unpack_ar_archive(archive_handle); | ||
1401 | 1436 | ||
1402 | /* Create the list file */ | 1437 | /* Create the list file */ |
1403 | strcat(info_prefix, "list"); | 1438 | strcat(info_prefix, "list"); |
@@ -1503,18 +1538,15 @@ int dpkg_main(int argc, char **argv) | |||
1503 | archive_handle_t *archive_handle; | 1538 | archive_handle_t *archive_handle; |
1504 | const llist_t *control_list = NULL; | 1539 | const llist_t *control_list = NULL; |
1505 | 1540 | ||
1506 | #ifdef CONFIG_FEATURE_DEB_TAR_GZ | 1541 | /* Extract the control file */ |
1507 | control_list = add_to_list(NULL, "control.tar.gz"); | 1542 | control_list = add_to_list(NULL, "./control"); |
1508 | #endif | 1543 | archive_handle = init_archive_deb_ar(argv[optind]); |
1509 | #ifdef CONFIG_FEATURE_DEB_TAR_BZ2 | 1544 | init_archive_deb_control(archive_handle); |
1510 | control_list = add_to_list(control_list, "control.tar.bz2"); | 1545 | deb_file[deb_count]->control_file = deb_extract_control_file_to_buffer(archive_handle, control_list); |
1511 | #endif | ||
1512 | deb_file[deb_count]->filename = xstrdup(argv[optind]); | ||
1513 | archive_handle = deb_extract(argv[optind], control_list, "./control", NULL, data_extract_to_buffer); | ||
1514 | deb_file[deb_count]->control_file = archive_handle->buffer; | ||
1515 | if (deb_file[deb_count]->control_file == NULL) { | 1546 | if (deb_file[deb_count]->control_file == NULL) { |
1516 | error_msg_and_die("Couldnt extract control file"); | 1547 | error_msg_and_die("Couldnt extract control file"); |
1517 | } | 1548 | } |
1549 | deb_file[deb_count]->filename = xstrdup(argv[optind]); | ||
1518 | package_num = fill_package_struct(deb_file[deb_count]->control_file); | 1550 | package_num = fill_package_struct(deb_file[deb_count]->control_file); |
1519 | 1551 | ||
1520 | if (package_num == -1) { | 1552 | if (package_num == -1) { |
@@ -1522,6 +1554,7 @@ int dpkg_main(int argc, char **argv) | |||
1522 | continue; | 1554 | continue; |
1523 | } | 1555 | } |
1524 | deb_file[deb_count]->package = (unsigned int) package_num; | 1556 | deb_file[deb_count]->package = (unsigned int) package_num; |
1557 | |||
1525 | /* Add the package to the status hashtable */ | 1558 | /* Add the package to the status hashtable */ |
1526 | if ((dpkg_opt & dpkg_opt_unpack) || (dpkg_opt & dpkg_opt_install)) { | 1559 | if ((dpkg_opt & dpkg_opt_unpack) || (dpkg_opt & dpkg_opt_install)) { |
1527 | status_node = (status_node_t *) xmalloc(sizeof(status_node_t)); | 1560 | status_node = (status_node_t *) xmalloc(sizeof(status_node_t)); |