diff options
author | bug1 <bug1@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2001-04-16 04:52:19 +0000 |
---|---|---|
committer | bug1 <bug1@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2001-04-16 04:52:19 +0000 |
commit | 085a08c884513c3861201988e836e933afcc5b3a (patch) | |
tree | 514459eccbc4927b00c0493badb7f12575c9147d /libbb/untar.c | |
parent | 86f02ff6a829c21a8e32cad0ce46e51e94c679dd (diff) | |
download | busybox-w32-085a08c884513c3861201988e836e933afcc5b3a.tar.gz busybox-w32-085a08c884513c3861201988e836e933afcc5b3a.tar.bz2 busybox-w32-085a08c884513c3861201988e836e933afcc5b3a.zip |
dpkg improvements, use full package struct, avoid extracting to tmp dir, rename variable.
deb_extract, untar and dpkg_deb modified to make the above possible
git-svn-id: svn://busybox.net/trunk/busybox@2350 69ca8d6d-28ef-0310-b511-8ec308f3f277
Diffstat (limited to 'libbb/untar.c')
-rw-r--r-- | libbb/untar.c | 42 |
1 files changed, 38 insertions, 4 deletions
diff --git a/libbb/untar.c b/libbb/untar.c index e70032c60..a77d94f61 100644 --- a/libbb/untar.c +++ b/libbb/untar.c | |||
@@ -22,7 +22,8 @@ | |||
22 | #include <unistd.h> | 22 | #include <unistd.h> |
23 | #include "libbb.h" | 23 | #include "libbb.h" |
24 | 24 | ||
25 | extern char *untar(FILE *src_tar_file, FILE *output, const int untar_function, const char *argument) | 25 | extern char *untar(FILE *src_tar_file, FILE *output, const int untar_function, |
26 | const char *argument, const char *file_prefix) | ||
26 | { | 27 | { |
27 | typedef struct raw_tar_header { | 28 | typedef struct raw_tar_header { |
28 | char name[100]; /* 0-99 */ | 29 | char name[100]; /* 0-99 */ |
@@ -102,7 +103,21 @@ extern char *untar(FILE *src_tar_file, FILE *output, const int untar_function, c | |||
102 | next_header_offset += (512 - size % 512); | 103 | next_header_offset += (512 - size % 512); |
103 | } | 104 | } |
104 | 105 | ||
105 | if (untar_function & (extract_contents | extract_verbose_extract)) { | 106 | /* If an exclude list is specified check current file against list |
107 | if (*exclude_list != NULL) { | ||
108 | i = 0; | ||
109 | while (exclude_list[i] != 0) { | ||
110 | if (strncmp(exclude_list[i], raw_tar_header.name, strlen(raw_tar_header.name)) == 0) { | ||
111 | break; | ||
112 | } | ||
113 | i++; | ||
114 | } | ||
115 | if (exclude_list[i] != 0) { | ||
116 | continue; | ||
117 | } | ||
118 | } */ | ||
119 | |||
120 | if (untar_function & (extract_contents | extract_verbose_extract | extract_contents_to_file)) { | ||
106 | fprintf(output, "%s\n", raw_tar_header.name); | 121 | fprintf(output, "%s\n", raw_tar_header.name); |
107 | } | 122 | } |
108 | 123 | ||
@@ -123,10 +138,29 @@ extern char *untar(FILE *src_tar_file, FILE *output, const int untar_function, c | |||
123 | case (extract_extract): | 138 | case (extract_extract): |
124 | case (extract_verbose_extract): | 139 | case (extract_verbose_extract): |
125 | case (extract_control): { | 140 | case (extract_control): { |
126 | FILE *dst_file = wfopen(dir, "w"); | 141 | FILE *dst_file = NULL; |
142 | char *full_name; | ||
143 | |||
144 | if (file_prefix != NULL) { | ||
145 | char *file_name = NULL, *file_extension = NULL; | ||
146 | |||
147 | file_extension = xmalloc(strlen(raw_tar_header.name) + 1); | ||
148 | file_extension = strrchr(raw_tar_header.name, '/'); | ||
149 | file_extension++; | ||
150 | file_name = xmalloc(strlen(file_prefix) + strlen(file_extension) + 2); | ||
151 | strcpy(file_name, file_prefix); | ||
152 | strcat(file_name, "."); | ||
153 | strcat(file_name, file_extension); | ||
154 | |||
155 | full_name = concat_path_file(strndup(dir, strlen(dir) - strlen(strrchr(dir, '/'))), file_name); | ||
156 | } else { | ||
157 | full_name = xstrdup(dir); | ||
158 | } | ||
159 | dst_file = wfopen(full_name, "w"); | ||
127 | copy_file_chunk(src_tar_file, dst_file, (unsigned long long) size); | 160 | copy_file_chunk(src_tar_file, dst_file, (unsigned long long) size); |
128 | uncompressed_count += size; | 161 | uncompressed_count += size; |
129 | fclose(dst_file); | 162 | fclose(dst_file); |
163 | chmod(full_name, mode); | ||
130 | } | 164 | } |
131 | break; | 165 | break; |
132 | case (extract_info): | 166 | case (extract_info): |
@@ -136,7 +170,7 @@ extern char *untar(FILE *src_tar_file, FILE *output, const int untar_function, c | |||
136 | } | 170 | } |
137 | break; | 171 | break; |
138 | case (extract_field): | 172 | case (extract_field): |
139 | if (strstr(raw_tar_header.name, "control") != NULL) { | 173 | if (strstr(raw_tar_header.name, "./control") != NULL) { |
140 | return(read_text_file_to_buffer(src_tar_file)); | 174 | return(read_text_file_to_buffer(src_tar_file)); |
141 | } | 175 | } |
142 | break; | 176 | break; |