aboutsummaryrefslogtreecommitdiff
path: root/libbb
diff options
context:
space:
mode:
authorGlenn L McGrath <bug1@ihug.co.nz>2001-04-12 13:49:09 +0000
committerGlenn L McGrath <bug1@ihug.co.nz>2001-04-12 13:49:09 +0000
commit3e2ab88ee2e488df1b674655f0038729a635aa52 (patch)
tree40aecd08a39f0f1ad7074f2a1003ace79bb4c641 /libbb
parentc9cac5be236475e91af1865a2dae2c2af5f19fd6 (diff)
downloadbusybox-w32-3e2ab88ee2e488df1b674655f0038729a635aa52.tar.gz
busybox-w32-3e2ab88ee2e488df1b674655f0038729a635aa52.tar.bz2
busybox-w32-3e2ab88ee2e488df1b674655f0038729a635aa52.zip
New dpkg-deb function -t, stands for --fsys-tarfile
Diffstat (limited to 'libbb')
-rw-r--r--libbb/deb_extract.c16
-rw-r--r--libbb/untar.c21
2 files changed, 24 insertions, 13 deletions
diff --git a/libbb/deb_extract.c b/libbb/deb_extract.c
index e982c14bb..d3e615305 100644
--- a/libbb/deb_extract.c
+++ b/libbb/deb_extract.c
@@ -26,6 +26,7 @@
26#include <fcntl.h> 26#include <fcntl.h>
27#include <unistd.h> 27#include <unistd.h>
28#include <stdlib.h> 28#include <stdlib.h>
29#include <string.h>
29#include <signal.h> 30#include <signal.h>
30#include "libbb.h" 31#include "libbb.h"
31 32
@@ -42,14 +43,9 @@ extern int deb_extract(const char *package_filename, int function, char *target_
42 case (extract_control): 43 case (extract_control):
43 ared_file = xstrdup("control.tar.gz"); 44 ared_file = xstrdup("control.tar.gz");
44 break; 45 break;
45 case (extract_contents): 46 default:
46 case (extract_extract):
47 case (extract_verbose_extract):
48 case (extract_list):
49 ared_file = xstrdup("data.tar.gz"); 47 ared_file = xstrdup("data.tar.gz");
50 break; 48 break;
51 default:
52 error_msg("Unknown extraction function");
53 } 49 }
54 50
55 /* open the debian package to be worked on */ 51 /* open the debian package to be worked on */
@@ -71,9 +67,11 @@ extern int deb_extract(const char *package_filename, int function, char *target_
71 /* open a stream of decompressed data */ 67 /* open a stream of decompressed data */
72 uncompressed_file = fdopen(gz_open(deb_file, &gunzip_pid), "r"); 68 uncompressed_file = fdopen(gz_open(deb_file, &gunzip_pid), "r");
73 69
74 /* get a list of all tar headers inside the .gz file */ 70 if (function & extract_fsys_tarfile) {
75 untar(uncompressed_file, function, target_dir); 71 copy_file_chunk(uncompressed_file, stdout, -1);
76 72 } else {
73 untar(uncompressed_file, function, target_dir);
74 }
77 /* we are deliberately terminating the child so we can safely ignore this */ 75 /* we are deliberately terminating the child so we can safely ignore this */
78 gz_close(gunzip_pid); 76 gz_close(gunzip_pid);
79 77
diff --git a/libbb/untar.c b/libbb/untar.c
index 9f7bd303c..11c55df7c 100644
--- a/libbb/untar.c
+++ b/libbb/untar.c
@@ -55,13 +55,26 @@ extern int untar(FILE *src_tar_file, int untar_function, char *base_path)
55 while (fread((char *) &raw_tar_header, 1, 512, src_tar_file) == 512) { 55 while (fread((char *) &raw_tar_header, 1, 512, src_tar_file) == 512) {
56 long sum = 0; 56 long sum = 0;
57 char *dir = NULL; 57 char *dir = NULL;
58
59 if (ferror(src_tar_file) || feof(src_tar_file)) {
60 break;
61 }
58 62
59 uncompressed_count += 512; 63 uncompressed_count += 512;
60 64
61 /* Check header has valid magic */ 65 /* Check header has valid magic */
62 if (strncmp(raw_tar_header.magic, "ustar", 5) != 0) { 66 if (strncmp(raw_tar_header.magic, "ustar", 5) != 0) {
63 /* Put this pack after TODO (check child still alive) is done */ 67/*
64 error_msg("Invalid tar magic"); 68 * FIXME, Need HELP with this
69 *
70 * This has to fail silently or it incorrectly reports errors when called from
71 * deb_extract.
72 * The problem is deb_extract decompresses the .gz file in a child process and
73 * untar reads from the child proccess. The child process finishes and exits,
74 * but fread reads 0's from the src_tar_file even though the child
75 * closed its handle.
76 */
77// error_msg("Invalid tar magic");
65 break; 78 break;
66 } 79 }
67 80
@@ -109,7 +122,7 @@ extern int untar(FILE *src_tar_file, int untar_function, char *base_path)
109 122
110 } 123 }
111*/ 124*/
112 if (untar_function & (extract_verbose_extract | extract_contents)) { 125 if (untar_function & (extract_contents | extract_verbose_extract)) {
113 printf("%s\n", raw_tar_header.name); 126 printf("%s\n", raw_tar_header.name);
114 } 127 }
115 128
@@ -144,7 +157,7 @@ extern int untar(FILE *src_tar_file, int untar_function, char *base_path)
144 break; 157 break;
145 } 158 }
146 case '5': 159 case '5':
147 if (untar_function & (extract_extract | extract_verbose_extract)) { 160 if (untar_function & extract_extract) {
148 if (create_path(dir, mode) != TRUE) { 161 if (create_path(dir, mode) != TRUE) {
149 free(dir); 162 free(dir);
150 perror_msg("%s: Cannot mkdir", raw_tar_header.name); 163 perror_msg("%s: Cannot mkdir", raw_tar_header.name);