diff options
author | Glenn L McGrath <bug1@ihug.co.nz> | 2001-04-12 11:48:02 +0000 |
---|---|---|
committer | Glenn L McGrath <bug1@ihug.co.nz> | 2001-04-12 11:48:02 +0000 |
commit | 6785b51280d6b0c00e964e1e9b24ff05d92f5bcc (patch) | |
tree | c9fbaf8bd615cb7871e16a5525f3223543fe69f5 /libbb | |
parent | 359c1068719c295b25b2d8b81a6aded5aeb6e23d (diff) | |
download | busybox-w32-6785b51280d6b0c00e964e1e9b24ff05d92f5bcc.tar.gz busybox-w32-6785b51280d6b0c00e964e1e9b24ff05d92f5bcc.tar.bz2 busybox-w32-6785b51280d6b0c00e964e1e9b24ff05d92f5bcc.zip |
dpkg-deb -c works now
Diffstat (limited to 'libbb')
-rw-r--r-- | libbb/untar.c | 40 |
1 files changed, 18 insertions, 22 deletions
diff --git a/libbb/untar.c b/libbb/untar.c index cb312d597..9f7bd303c 100644 --- a/libbb/untar.c +++ b/libbb/untar.c | |||
@@ -52,18 +52,16 @@ extern int untar(FILE *src_tar_file, int untar_function, char *base_path) | |||
52 | size_t size; | 52 | size_t size; |
53 | mode_t mode; | 53 | mode_t mode; |
54 | 54 | ||
55 | // signal(SIGCHLD, child_died); | ||
56 | |||
57 | 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) { |
58 | long sum = 0; | 56 | long sum = 0; |
59 | char *dir; | 57 | char *dir = NULL; |
60 | 58 | ||
61 | uncompressed_count += 512; | 59 | uncompressed_count += 512; |
62 | 60 | ||
63 | /* Check header has valid magic */ | 61 | /* Check header has valid magic */ |
64 | if (strncmp(raw_tar_header.magic, "ustar", 5) != 0) { | 62 | if (strncmp(raw_tar_header.magic, "ustar", 5) != 0) { |
65 | /* Put this pack after TODO (check child still alive) is done */ | 63 | /* Put this pack after TODO (check child still alive) is done */ |
66 | // error_msg("Invalid tar magic"); | 64 | error_msg("Invalid tar magic"); |
67 | break; | 65 | break; |
68 | } | 66 | } |
69 | 67 | ||
@@ -111,11 +109,16 @@ extern int untar(FILE *src_tar_file, int untar_function, char *base_path) | |||
111 | 109 | ||
112 | } | 110 | } |
113 | */ | 111 | */ |
114 | /* extract files */ | 112 | if (untar_function & (extract_verbose_extract | extract_contents)) { |
115 | dir = xmalloc(strlen(raw_tar_header.name) + strlen(base_path) + 2); | 113 | printf("%s\n", raw_tar_header.name); |
114 | } | ||
116 | 115 | ||
117 | sprintf(dir, "%s/%s", base_path, raw_tar_header.name); | 116 | /* extract files */ |
118 | create_path(dir, 0777); | 117 | if (base_path != NULL) { |
118 | dir = xmalloc(strlen(raw_tar_header.name) + strlen(base_path) + 2); | ||
119 | sprintf(dir, "%s/%s", base_path, raw_tar_header.name); | ||
120 | create_path(dir, 0777); | ||
121 | } | ||
119 | switch (raw_tar_header.typeflag ) { | 122 | switch (raw_tar_header.typeflag ) { |
120 | case '0': | 123 | case '0': |
121 | case '\0': | 124 | case '\0': |
@@ -124,8 +127,6 @@ extern int untar(FILE *src_tar_file, int untar_function, char *base_path) | |||
124 | */ | 127 | */ |
125 | if (raw_tar_header.name[strlen(raw_tar_header.name)-1] != '/') { | 128 | if (raw_tar_header.name[strlen(raw_tar_header.name)-1] != '/') { |
126 | switch (untar_function) { | 129 | switch (untar_function) { |
127 | case (extract_verbose_extract): | ||
128 | printf("%s\n", raw_tar_header.name); | ||
129 | case (extract_extract): { | 130 | case (extract_extract): { |
130 | FILE *dst_file = wfopen(dir, "w"); | 131 | FILE *dst_file = wfopen(dir, "w"); |
131 | copy_file_chunk(src_tar_file, dst_file, size); | 132 | copy_file_chunk(src_tar_file, dst_file, size); |
@@ -143,17 +144,12 @@ extern int untar(FILE *src_tar_file, int untar_function, char *base_path) | |||
143 | break; | 144 | break; |
144 | } | 145 | } |
145 | case '5': | 146 | case '5': |
146 | switch (untar_function) { | 147 | if (untar_function & (extract_extract | extract_verbose_extract)) { |
147 | case (extract_verbose_extract): | 148 | if (create_path(dir, mode) != TRUE) { |
148 | printf("%s\n", raw_tar_header.name); | 149 | free(dir); |
149 | case (extract_extract): | 150 | perror_msg("%s: Cannot mkdir", raw_tar_header.name); |
150 | if (create_path(dir, mode) != TRUE) { | 151 | return(EXIT_FAILURE); |
151 | free(dir); | 152 | } |
152 | perror_msg("%s: Cannot mkdir", raw_tar_header.name); | ||
153 | return(EXIT_FAILURE); | ||
154 | } | ||
155 | break; | ||
156 | default: | ||
157 | } | 153 | } |
158 | break; | 154 | break; |
159 | case '1': | 155 | case '1': |
@@ -185,7 +181,7 @@ extern int untar(FILE *src_tar_file, int untar_function, char *base_path) | |||
185 | free(dir); | 181 | free(dir); |
186 | return(EXIT_FAILURE); | 182 | return(EXIT_FAILURE); |
187 | } | 183 | } |
188 | free(dir); | 184 | // free(dir); |
189 | } | 185 | } |
190 | return(EXIT_SUCCESS); | 186 | return(EXIT_SUCCESS); |
191 | } | 187 | } |