Bump to version 1.22.1
[platform/upstream/busybox.git] / archival / dpkg.c
index 2a6a7b3..2893cfc 100644 (file)
@@ -14,7 +14,6 @@
  *
  * Licensed under GPLv2 or later, see file LICENSE in this source tree.
  */
-
 /*
  * known difference between busybox dpkg and the official dpkg that i don't
  * consider important, its worth keeping a note of differences anyway, just to
  *
  * bugs that need to be fixed
  *  - (unknown, please let me know when you find any)
- *
  */
 
+//config:config DPKG
+//config:      bool "dpkg"
+//config:      default n
+//config:      select FEATURE_SEAMLESS_GZ
+//config:      help
+//config:        dpkg is a medium-level tool to install, build, remove and manage
+//config:        Debian packages.
+//config:
+//config:        This implementation of dpkg has a number of limitations,
+//config:        you should use the official dpkg if possible.
+
+//applet:IF_DPKG(APPLET(dpkg, BB_DIR_USR_BIN, BB_SUID_DROP))
+//kbuild:lib-$(CONFIG_DPKG) += dpkg.o
+
 //usage:#define dpkg_trivial_usage
 //usage:       "[-ilCPru] [-F OPT] PACKAGE"
 //usage:#define dpkg_full_usage "\n\n"
@@ -57,7 +69,7 @@
 
 #include "libbb.h"
 #include <fnmatch.h>
-#include "archive.h"
+#include "bb_archive.h"
 
 /* note: if you vary hash_prime sizes be aware,
  * 1) tweaking these will have a big effect on how much memory this program uses.
@@ -1026,8 +1038,8 @@ static int check_deps(deb_file_t **deb_file, int deb_start /*, int dep_max_count
                        if (package_edge->type == EDGE_CONFLICTS) {
                                const unsigned package_num =
                                        search_package_hashtable(package_edge->name,
-                                                                package_edge->version,
-                                                                package_edge->operator);
+                                                               package_edge->version,
+                                                               package_edge->operator);
                                int result = 0;
                                if (package_hashtable[package_num] != NULL) {
                                        status_num = search_status_hashtable(name_hashtable[package_hashtable[package_num]->name]);
@@ -1114,7 +1126,7 @@ static int check_deps(deb_file_t **deb_file, int deb_start /*, int dep_max_count
                                 */
                                if (root_of_alternatives && package_edge->type != root_of_alternatives->type - 1)
                                        bb_error_msg_and_die("fatal error, package dependencies corrupt: %d != %d - 1",
-                                                            package_edge->type, root_of_alternatives->type);
+                                                       package_edge->type, root_of_alternatives->type);
 
                                if (package_hashtable[package_num] != NULL)
                                        result = !package_satisfies_dependency(package_num, package_edge->type);
@@ -1665,20 +1677,25 @@ static void unpack_package(deb_file_t *deb_file)
        archive_handle = init_archive_deb_ar(deb_file->filename);
        init_archive_deb_data(archive_handle);
        archive_handle->dpkg__sub_archive->accept = conffile_list;
+       /* Why ARCHIVE_REMEMBER_NAMES?
+        * We want names collected in ->passed list even if conffile_list
+        * is NULL (otherwise get_header_tar may optimize name saving out):
+        */
+       archive_handle->dpkg__sub_archive->ah_flags |= ARCHIVE_REMEMBER_NAMES | ARCHIVE_UNLINK_OLD;
        archive_handle->dpkg__sub_archive->filter = filter_rename_config;
        archive_handle->dpkg__sub_archive->action_data = data_extract_all_prefix;
        archive_handle->dpkg__sub_archive->dpkg__buffer = (char*)"/"; /* huh? */
-       archive_handle->dpkg__sub_archive->ah_flags |= ARCHIVE_UNLINK_OLD;
        unpack_ar_archive(archive_handle);
 
        /* Create the list file */
        list_filename = xasprintf("/var/lib/dpkg/info/%s.%s", package_name, "list");
        out_stream = xfopen_for_write(list_filename);
+       archive_handle->dpkg__sub_archive->passed = llist_rev(archive_handle->dpkg__sub_archive->passed);
        while (archive_handle->dpkg__sub_archive->passed) {
+               char *filename = llist_pop(&archive_handle->dpkg__sub_archive->passed);
                /* the leading . has been stripped by data_extract_all_prefix already */
-               fputs(archive_handle->dpkg__sub_archive->passed->data, out_stream);
-               fputc('\n', out_stream);
-               archive_handle->dpkg__sub_archive->passed = archive_handle->dpkg__sub_archive->passed->link;
+               fprintf(out_stream, "%s\n", filename);
+               free(filename);
        }
        fclose(out_stream);