dpkg: fix creation of .list files (were empty since b768aeb). Closes 5324
authorDenys Vlasenko <vda.linux@googlemail.com>
Fri, 22 Jun 2012 14:27:21 +0000 (16:27 +0200)
committerDenys Vlasenko <vda.linux@googlemail.com>
Fri, 22 Jun 2012 14:27:21 +0000 (16:27 +0200)
While at it, fix filename order and free the list of names.

function                                             old     new   delta
llist_rev                                              -      21     +21
get_header_tar                                      1733    1741      +8
unpack_package                                       587     585      -2
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 1/1 up/down: 29/-2)              Total: 27 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
archival/dpkg.c
archival/libarchive/get_header_tar.c
include/bb_archive.h

index bf9e9992c136a799444ce832c7161e3be65a378a..dae8a9747c5cc72565bd89a99756c8184a590e98 100644 (file)
@@ -1665,20 +1665,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);
 
index b168653d80da637749f747b6c4e24d6b181d3826..bc09756ba35c2fff3fcf13168109fb936c796473 100644 (file)
@@ -452,9 +452,11 @@ char FAST_FUNC get_header_tar(archive_handle_t *archive_handle)
                if (cp)
                        *cp = '\0';
                archive_handle->action_data(archive_handle);
-               if (archive_handle->accept || archive_handle->reject)
+               if (archive_handle->accept || archive_handle->reject
+                || (archive_handle->ah_flags & ARCHIVE_REMEMBER_NAMES)
+               ) {
                        llist_add_to(&archive_handle->passed, file_header->name);
-               else /* Caller isn't interested in list of unpacked files */
+               else /* Caller isn't interested in list of unpacked files */
                        free(file_header->name);
        } else {
                data_skip(archive_handle);
index 2043d8570d4a7bfebe7e1d2668518945bb6ae81c..7bb5615da47f0c0ce5af78d7ab449b9398da6331 100644 (file)
@@ -121,6 +121,7 @@ typedef struct archive_handle_t {
 #define ARCHIVE_DONT_RESTORE_PERM   (1 << 6)
 #define ARCHIVE_NUMERIC_OWNER       (1 << 7)
 #define ARCHIVE_O_TRUNC             (1 << 8)
+#define ARCHIVE_REMEMBER_NAMES      (1 << 9)
 
 
 /* POSIX tar Header Block, from POSIX 1003.1-1990  */