aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGlenn L McGrath <bug1@ihug.co.nz>2001-02-11 03:32:41 +0000
committerGlenn L McGrath <bug1@ihug.co.nz>2001-02-11 03:32:41 +0000
commitbc9afadecd96881567ea9b66c9c7d390592716fe (patch)
tree98d97554bd11083680f5dd6f81214df84d8774cb
parent728875f34033ed965c143f8a5dc9c4db77c176f9 (diff)
downloadbusybox-w32-bc9afadecd96881567ea9b66c9c7d390592716fe.tar.gz
busybox-w32-bc9afadecd96881567ea9b66c9c7d390592716fe.tar.bz2
busybox-w32-bc9afadecd96881567ea9b66c9c7d390592716fe.zip
New function, deb-extract to be used by dpkg, code cleanups. saves some bytes
-rw-r--r--archival/dpkg_deb.c171
-rw-r--r--dpkg_deb.c171
2 files changed, 172 insertions, 170 deletions
diff --git a/archival/dpkg_deb.c b/archival/dpkg_deb.c
index 3345c273f..32ef4ca75 100644
--- a/archival/dpkg_deb.c
+++ b/archival/dpkg_deb.c
@@ -14,6 +14,10 @@
14 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 14 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
15 */ 15 */
16 16
17/*
18 * Merge this applet into dpkg when dpkg becomes more stable
19 */
20
17#include <stdio.h> 21#include <stdio.h>
18#include <stdlib.h> 22#include <stdlib.h>
19#include <fcntl.h> 23#include <fcntl.h>
@@ -33,31 +37,82 @@ typedef struct ar_headers_s {
33 struct ar_headers_s *next; 37 struct ar_headers_s *next;
34} ar_headers_t; 38} ar_headers_t;
35 39
36extern ar_headers_t get_headers(int srcFd); 40extern ar_headers_t get_ar_headers(int srcFd);
37extern int tar_unzip_init(int tarFd); 41extern int tar_unzip_init(int tarFd);
38extern int readTarFile(int tarFd, int extractFlag, int listFlag, 42extern int readTarFile(int tarFd, int extractFlag, int listFlag,
39 int tostdoutFlag, int verboseFlag, char** extractList, 43 int tostdoutFlag, int verboseFlag, char** extractList, char** excludeList);
40 char** excludeList);
41 44
42extern int dpkg_deb_main(int argc, char **argv) 45const int dpkg_deb_contents = 1;
43{ 46const int dpkg_deb_control = 2;
44 const int dpkg_deb_contents = 1;
45 const int dpkg_deb_control = 2;
46// const int dpkg_deb_info = 4; 47// const int dpkg_deb_info = 4;
47 const int dpkg_deb_extract = 8; 48const int dpkg_deb_extract = 8;
48 const int dpkg_deb_verbose_extract = 16; 49const int dpkg_deb_verbose_extract = 16;
49 int opt=0; 50
50 int optflag=0; 51extern int deb_extract(int optflags, const char *dir_name, const char *deb_filename)
52{
53 char **extract_list = NULL;
54 ar_headers_t *ar_headers = NULL;
55 char ar_filename[15];
51 int extract_flag = FALSE; 56 int extract_flag = FALSE;
52 int list_flag = FALSE; 57 int list_flag = FALSE;
53 int verbose_flag = FALSE; 58 int verbose_flag = FALSE;
54 int extract_to_stdout = FALSE; 59 int extract_to_stdout = FALSE;
55 char ar_filename[15]; 60 int srcFd = 0;
56 int srcFd=0; 61 int status;
57 int status=0; 62
58 ar_headers_t *ar_headers = NULL; 63 if (dpkg_deb_contents == (dpkg_deb_contents & optflags)) {
59 char **extract_list=NULL; 64 strcpy(ar_filename, "data.tar.gz");
60 char *target_dir=NULL; 65 verbose_flag = TRUE;
66 list_flag = TRUE;
67 }
68 if (dpkg_deb_control == (dpkg_deb_control & optflags)) {
69 strcpy(ar_filename, "control.tar.gz");
70 extract_flag = TRUE;
71 }
72 if (dpkg_deb_extract == (dpkg_deb_extract & optflags)) {
73 strcpy(ar_filename, "data.tar.gz");
74 extract_flag = TRUE;
75 }
76 if (dpkg_deb_verbose_extract == (dpkg_deb_verbose_extract & optflags)) {
77 strcpy(ar_filename, "data.tar.gz");
78 extract_flag = TRUE;
79 list_flag = TRUE;
80 }
81
82 ar_headers = (ar_headers_t *) xmalloc(sizeof(ar_headers_t));
83 srcFd = open(deb_filename, O_RDONLY);
84
85 *ar_headers = get_ar_headers(srcFd);
86 if (ar_headers->next == NULL) {
87 error_msg_and_die("Couldnt find %s in %s", ar_filename, deb_filename);
88 }
89
90 while (ar_headers->next != NULL) {
91 if (strcmp(ar_headers->name, ar_filename) == 0) {
92 break;
93 }
94 ar_headers = ar_headers->next;
95 }
96 lseek(srcFd, ar_headers->offset, SEEK_SET);
97 srcFd = tar_unzip_init(srcFd);
98 if ( dir_name != NULL) {
99 if (is_directory(dir_name, TRUE, NULL)==FALSE) {
100 mkdir(dir_name, 0755);
101 }
102 if (chdir(dir_name)==-1) {
103 error_msg_and_die("Cannot change to dir %s", dir_name);
104 }
105 }
106 status = readTarFile(srcFd, extract_flag, list_flag, extract_to_stdout, verbose_flag, NULL, extract_list);
107
108 return status;
109}
110
111extern int dpkg_deb_main(int argc, char **argv)
112{
113 char *target_dir = NULL;
114 int opt = 0;
115 int optflag = 0;
61 116
62 while ((opt = getopt(argc, argv, "cexX")) != -1) { 117 while ((opt = getopt(argc, argv, "cexX")) != -1) {
63 switch (opt) { 118 switch (opt) {
@@ -67,16 +122,16 @@ extern int dpkg_deb_main(int argc, char **argv)
67 case 'e': 122 case 'e':
68 optflag |= dpkg_deb_control; 123 optflag |= dpkg_deb_control;
69 break; 124 break;
70/* case 'I': 125 case 'X':
71 optflag |= dpkg_deb_info; 126 optflag |= dpkg_deb_verbose_extract;
72 break; 127 break;
73*/
74 case 'x': 128 case 'x':
75 optflag |= dpkg_deb_extract; 129 optflag |= dpkg_deb_extract;
76 break; 130 break;
77 case 'X': 131/* case 'I':
78 optflag |= dpkg_deb_verbose_extract; 132 optflag |= dpkg_deb_info;
79 break; 133 break;
134*/
80 default: 135 default:
81 usage(dpkg_deb_usage); 136 usage(dpkg_deb_usage);
82 return EXIT_FAILURE; 137 return EXIT_FAILURE;
@@ -87,25 +142,16 @@ extern int dpkg_deb_main(int argc, char **argv)
87 usage(dpkg_deb_usage); 142 usage(dpkg_deb_usage);
88 return(EXIT_FAILURE); 143 return(EXIT_FAILURE);
89 } 144 }
90 145 if ((optflag & dpkg_deb_control) || (optflag & dpkg_deb_extract) || (optflag & dpkg_deb_verbose_extract)) {
91 if (optflag & dpkg_deb_contents) { 146 if ( (optind + 1) == argc ) {
92 list_flag = TRUE; 147 target_dir = (char *) xmalloc(7);
93 verbose_flag = TRUE; 148 strcpy(target_dir, "DEBIAN");
94 strcpy(ar_filename, "data.tar.gz"); 149 } else {
95 } 150 target_dir = (char *) xmalloc(strlen(argv[optind + 1]));
96 else if (optflag & dpkg_deb_control) { 151 strcpy(target_dir, argv[optind + 1]);
97 extract_flag = TRUE; 152 }
98 strcpy(ar_filename, "control.tar.gz");
99 if ( (optind + 1) == argc ) {
100 target_dir = (char *) xmalloc(7);
101 strcpy(target_dir, "DEBIAN");
102 }
103 else {
104 target_dir = (char *) xmalloc(strlen(argv[optind+1]));
105
106 strcpy(target_dir, argv[optind+1]);
107 }
108 } 153 }
154 deb_extract(optflag, target_dir, argv[optind]);
109/* else if (optflag & dpkg_deb_info) { 155/* else if (optflag & dpkg_deb_info) {
110 extract_flag = TRUE; 156 extract_flag = TRUE;
111 extract_to_stdout = TRUE; 157 extract_to_stdout = TRUE;
@@ -114,50 +160,5 @@ extern int dpkg_deb_main(int argc, char **argv)
114 printf("list one is [%s]\n",extract_list[0]); 160 printf("list one is [%s]\n",extract_list[0]);
115 } 161 }
116*/ 162*/
117 else if (optflag & dpkg_deb_extract) {
118 extract_flag = TRUE;
119 strcpy(ar_filename, "data.tar.gz");
120 if ( (optind + 2) > argc ) {
121 error_msg_and_die("No directory specified");
122 }
123 target_dir = (char *) xmalloc(strlen(argv[optind+1]));
124 strcpy(target_dir, argv[optind+1]);
125 }
126 else if (optflag & dpkg_deb_verbose_extract) {
127 extract_flag = TRUE;
128 list_flag = TRUE;
129 strcpy(ar_filename, "data.tar.gz");
130 if ( (optind + 2) > argc ) {
131 error_msg_and_die("No directory specified");
132 }
133 target_dir = (char *) xmalloc(strlen(argv[optind+1]));
134 strcpy(target_dir, argv[optind+1]);
135 }
136
137 ar_headers = (ar_headers_t *) xmalloc(sizeof(ar_headers_t));
138 srcFd = open(argv[optind], O_RDONLY);
139
140 *ar_headers = get_headers(srcFd);
141 if (ar_headers->next==NULL)
142 error_msg_and_die("Couldnt find %s in %s", ar_filename, argv[optind]);
143
144 while (ar_headers->next != NULL) {
145 if (strcmp(ar_headers->name, ar_filename)==0)
146 break;
147 ar_headers = ar_headers->next;
148 }
149
150 lseek(srcFd, ar_headers->offset, SEEK_SET);
151 srcFd = tar_unzip_init(srcFd);
152 if ( target_dir != NULL) {
153 if (is_directory(target_dir, TRUE, NULL)==FALSE) {
154 mkdir(target_dir, 0755);
155 }
156 if (chdir(target_dir)==-1) {
157 error_msg_and_die("Cannot change to dir %s", argv[optind+1]);
158 }
159 }
160 status = readTarFile(srcFd, extract_flag, list_flag, extract_to_stdout, verbose_flag, NULL, extract_list);
161 close (srcFd);
162 return(EXIT_SUCCESS); 163 return(EXIT_SUCCESS);
163} 164}
diff --git a/dpkg_deb.c b/dpkg_deb.c
index 3345c273f..32ef4ca75 100644
--- a/dpkg_deb.c
+++ b/dpkg_deb.c
@@ -14,6 +14,10 @@
14 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 14 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
15 */ 15 */
16 16
17/*
18 * Merge this applet into dpkg when dpkg becomes more stable
19 */
20
17#include <stdio.h> 21#include <stdio.h>
18#include <stdlib.h> 22#include <stdlib.h>
19#include <fcntl.h> 23#include <fcntl.h>
@@ -33,31 +37,82 @@ typedef struct ar_headers_s {
33 struct ar_headers_s *next; 37 struct ar_headers_s *next;
34} ar_headers_t; 38} ar_headers_t;
35 39
36extern ar_headers_t get_headers(int srcFd); 40extern ar_headers_t get_ar_headers(int srcFd);
37extern int tar_unzip_init(int tarFd); 41extern int tar_unzip_init(int tarFd);
38extern int readTarFile(int tarFd, int extractFlag, int listFlag, 42extern int readTarFile(int tarFd, int extractFlag, int listFlag,
39 int tostdoutFlag, int verboseFlag, char** extractList, 43 int tostdoutFlag, int verboseFlag, char** extractList, char** excludeList);
40 char** excludeList);
41 44
42extern int dpkg_deb_main(int argc, char **argv) 45const int dpkg_deb_contents = 1;
43{ 46const int dpkg_deb_control = 2;
44 const int dpkg_deb_contents = 1;
45 const int dpkg_deb_control = 2;
46// const int dpkg_deb_info = 4; 47// const int dpkg_deb_info = 4;
47 const int dpkg_deb_extract = 8; 48const int dpkg_deb_extract = 8;
48 const int dpkg_deb_verbose_extract = 16; 49const int dpkg_deb_verbose_extract = 16;
49 int opt=0; 50
50 int optflag=0; 51extern int deb_extract(int optflags, const char *dir_name, const char *deb_filename)
52{
53 char **extract_list = NULL;
54 ar_headers_t *ar_headers = NULL;
55 char ar_filename[15];
51 int extract_flag = FALSE; 56 int extract_flag = FALSE;
52 int list_flag = FALSE; 57 int list_flag = FALSE;
53 int verbose_flag = FALSE; 58 int verbose_flag = FALSE;
54 int extract_to_stdout = FALSE; 59 int extract_to_stdout = FALSE;
55 char ar_filename[15]; 60 int srcFd = 0;
56 int srcFd=0; 61 int status;
57 int status=0; 62
58 ar_headers_t *ar_headers = NULL; 63 if (dpkg_deb_contents == (dpkg_deb_contents & optflags)) {
59 char **extract_list=NULL; 64 strcpy(ar_filename, "data.tar.gz");
60 char *target_dir=NULL; 65 verbose_flag = TRUE;
66 list_flag = TRUE;
67 }
68 if (dpkg_deb_control == (dpkg_deb_control & optflags)) {
69 strcpy(ar_filename, "control.tar.gz");
70 extract_flag = TRUE;
71 }
72 if (dpkg_deb_extract == (dpkg_deb_extract & optflags)) {
73 strcpy(ar_filename, "data.tar.gz");
74 extract_flag = TRUE;
75 }
76 if (dpkg_deb_verbose_extract == (dpkg_deb_verbose_extract & optflags)) {
77 strcpy(ar_filename, "data.tar.gz");
78 extract_flag = TRUE;
79 list_flag = TRUE;
80 }
81
82 ar_headers = (ar_headers_t *) xmalloc(sizeof(ar_headers_t));
83 srcFd = open(deb_filename, O_RDONLY);
84
85 *ar_headers = get_ar_headers(srcFd);
86 if (ar_headers->next == NULL) {
87 error_msg_and_die("Couldnt find %s in %s", ar_filename, deb_filename);
88 }
89
90 while (ar_headers->next != NULL) {
91 if (strcmp(ar_headers->name, ar_filename) == 0) {
92 break;
93 }
94 ar_headers = ar_headers->next;
95 }
96 lseek(srcFd, ar_headers->offset, SEEK_SET);
97 srcFd = tar_unzip_init(srcFd);
98 if ( dir_name != NULL) {
99 if (is_directory(dir_name, TRUE, NULL)==FALSE) {
100 mkdir(dir_name, 0755);
101 }
102 if (chdir(dir_name)==-1) {
103 error_msg_and_die("Cannot change to dir %s", dir_name);
104 }
105 }
106 status = readTarFile(srcFd, extract_flag, list_flag, extract_to_stdout, verbose_flag, NULL, extract_list);
107
108 return status;
109}
110
111extern int dpkg_deb_main(int argc, char **argv)
112{
113 char *target_dir = NULL;
114 int opt = 0;
115 int optflag = 0;
61 116
62 while ((opt = getopt(argc, argv, "cexX")) != -1) { 117 while ((opt = getopt(argc, argv, "cexX")) != -1) {
63 switch (opt) { 118 switch (opt) {
@@ -67,16 +122,16 @@ extern int dpkg_deb_main(int argc, char **argv)
67 case 'e': 122 case 'e':
68 optflag |= dpkg_deb_control; 123 optflag |= dpkg_deb_control;
69 break; 124 break;
70/* case 'I': 125 case 'X':
71 optflag |= dpkg_deb_info; 126 optflag |= dpkg_deb_verbose_extract;
72 break; 127 break;
73*/
74 case 'x': 128 case 'x':
75 optflag |= dpkg_deb_extract; 129 optflag |= dpkg_deb_extract;
76 break; 130 break;
77 case 'X': 131/* case 'I':
78 optflag |= dpkg_deb_verbose_extract; 132 optflag |= dpkg_deb_info;
79 break; 133 break;
134*/
80 default: 135 default:
81 usage(dpkg_deb_usage); 136 usage(dpkg_deb_usage);
82 return EXIT_FAILURE; 137 return EXIT_FAILURE;
@@ -87,25 +142,16 @@ extern int dpkg_deb_main(int argc, char **argv)
87 usage(dpkg_deb_usage); 142 usage(dpkg_deb_usage);
88 return(EXIT_FAILURE); 143 return(EXIT_FAILURE);
89 } 144 }
90 145 if ((optflag & dpkg_deb_control) || (optflag & dpkg_deb_extract) || (optflag & dpkg_deb_verbose_extract)) {
91 if (optflag & dpkg_deb_contents) { 146 if ( (optind + 1) == argc ) {
92 list_flag = TRUE; 147 target_dir = (char *) xmalloc(7);
93 verbose_flag = TRUE; 148 strcpy(target_dir, "DEBIAN");
94 strcpy(ar_filename, "data.tar.gz"); 149 } else {
95 } 150 target_dir = (char *) xmalloc(strlen(argv[optind + 1]));
96 else if (optflag & dpkg_deb_control) { 151 strcpy(target_dir, argv[optind + 1]);
97 extract_flag = TRUE; 152 }
98 strcpy(ar_filename, "control.tar.gz");
99 if ( (optind + 1) == argc ) {
100 target_dir = (char *) xmalloc(7);
101 strcpy(target_dir, "DEBIAN");
102 }
103 else {
104 target_dir = (char *) xmalloc(strlen(argv[optind+1]));
105
106 strcpy(target_dir, argv[optind+1]);
107 }
108 } 153 }
154 deb_extract(optflag, target_dir, argv[optind]);
109/* else if (optflag & dpkg_deb_info) { 155/* else if (optflag & dpkg_deb_info) {
110 extract_flag = TRUE; 156 extract_flag = TRUE;
111 extract_to_stdout = TRUE; 157 extract_to_stdout = TRUE;
@@ -114,50 +160,5 @@ extern int dpkg_deb_main(int argc, char **argv)
114 printf("list one is [%s]\n",extract_list[0]); 160 printf("list one is [%s]\n",extract_list[0]);
115 } 161 }
116*/ 162*/
117 else if (optflag & dpkg_deb_extract) {
118 extract_flag = TRUE;
119 strcpy(ar_filename, "data.tar.gz");
120 if ( (optind + 2) > argc ) {
121 error_msg_and_die("No directory specified");
122 }
123 target_dir = (char *) xmalloc(strlen(argv[optind+1]));
124 strcpy(target_dir, argv[optind+1]);
125 }
126 else if (optflag & dpkg_deb_verbose_extract) {
127 extract_flag = TRUE;
128 list_flag = TRUE;
129 strcpy(ar_filename, "data.tar.gz");
130 if ( (optind + 2) > argc ) {
131 error_msg_and_die("No directory specified");
132 }
133 target_dir = (char *) xmalloc(strlen(argv[optind+1]));
134 strcpy(target_dir, argv[optind+1]);
135 }
136
137 ar_headers = (ar_headers_t *) xmalloc(sizeof(ar_headers_t));
138 srcFd = open(argv[optind], O_RDONLY);
139
140 *ar_headers = get_headers(srcFd);
141 if (ar_headers->next==NULL)
142 error_msg_and_die("Couldnt find %s in %s", ar_filename, argv[optind]);
143
144 while (ar_headers->next != NULL) {
145 if (strcmp(ar_headers->name, ar_filename)==0)
146 break;
147 ar_headers = ar_headers->next;
148 }
149
150 lseek(srcFd, ar_headers->offset, SEEK_SET);
151 srcFd = tar_unzip_init(srcFd);
152 if ( target_dir != NULL) {
153 if (is_directory(target_dir, TRUE, NULL)==FALSE) {
154 mkdir(target_dir, 0755);
155 }
156 if (chdir(target_dir)==-1) {
157 error_msg_and_die("Cannot change to dir %s", argv[optind+1]);
158 }
159 }
160 status = readTarFile(srcFd, extract_flag, list_flag, extract_to_stdout, verbose_flag, NULL, extract_list);
161 close (srcFd);
162 return(EXIT_SUCCESS); 163 return(EXIT_SUCCESS);
163} 164}