aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGlenn L McGrath <bug1@ihug.co.nz>2001-04-11 02:12:08 +0000
committerGlenn L McGrath <bug1@ihug.co.nz>2001-04-11 02:12:08 +0000
commitd22e560ad6a3fe8bfbd23519935a1942cd510758 (patch)
treeed446649c33a8564e6a21236232be3873aea2c22
parent9d53c8ab74ecb2be62ebf4c61350b842787cc6b9 (diff)
downloadbusybox-w32-d22e560ad6a3fe8bfbd23519935a1942cd510758.tar.gz
busybox-w32-d22e560ad6a3fe8bfbd23519935a1942cd510758.tar.bz2
busybox-w32-d22e560ad6a3fe8bfbd23519935a1942cd510758.zip
Move deb_extract() to libbb, dpkg now independent of dpkg-deb
-rw-r--r--Makefile14
-rw-r--r--archival/dpkg.c2
-rw-r--r--archival/dpkg_deb.c109
-rw-r--r--dpkg.c2
-rw-r--r--dpkg_deb.c109
-rw-r--r--include/libbb.h2
-rw-r--r--libbb/deb_extract.c122
-rw-r--r--libbb/libbb.h2
8 files changed, 147 insertions, 215 deletions
diff --git a/Makefile b/Makefile
index 3b6b910ed..84337ba52 100644
--- a/Makefile
+++ b/Makefile
@@ -237,13 +237,13 @@ LIBBB = libbb
237LIBBB_LIB = libbb.a 237LIBBB_LIB = libbb.a
238LIBBB_CSRC= ask_confirmation.c check_wildcard_match.c chomp.c \ 238LIBBB_CSRC= ask_confirmation.c check_wildcard_match.c chomp.c \
239concat_path_file.c copy_file.c copy_file_chunk.c create_path.c daemon.c \ 239concat_path_file.c copy_file.c copy_file_chunk.c create_path.c daemon.c \
240device_open.c error_msg.c error_msg_and_die.c find_mount_point.c \ 240deb_extract.c device_open.c error_msg.c error_msg_and_die.c \
241find_pid_by_name.c find_root_device.c full_read.c full_write.c \ 241find_mount_point.c find_pid_by_name.c find_root_device.c full_read.c \
242get_ar_headers.c get_console.c get_last_path_component.c get_line_from_file.c \ 242full_write.c get_ar_headers.c get_console.c get_last_path_component.c \
243human_readable.c inode_hash.c isdirectory.c kernel_version.c loop.c \ 243get_line_from_file.c human_readable.c inode_hash.c isdirectory.c \
244mode_string.c module_syscalls.c mtab.c mtab_file.c my_getgrnam.c \ 244kernel_version.c loop.c mode_string.c module_syscalls.c mtab.c mtab_file.c \
245my_getgrgid.c my_getpwnam.c my_getpwnamegid.c my_getpwuid.c parse_mode.c \ 245my_getgrnam.c my_getgrgid.c my_getpwnam.c my_getpwnamegid.c my_getpwuid.c \
246parse_number.c perror_msg.c perror_msg_and_die.c print_file.c \ 246parse_mode.c parse_number.c perror_msg.c perror_msg_and_die.c print_file.c \
247process_escape_sequence.c recursive_action.c safe_read.c safe_strncpy.c \ 247process_escape_sequence.c recursive_action.c safe_read.c safe_strncpy.c \
248syscalls.c syslog_msg_with_name.c time_string.c trim.c vdprintf.c verror_msg.c \ 248syscalls.c syslog_msg_with_name.c time_string.c trim.c vdprintf.c verror_msg.c \
249vperror_msg.c wfopen.c xfuncs.c xgetcwd.c xregcomp.c 249vperror_msg.c wfopen.c xfuncs.c xgetcwd.c xregcomp.c
diff --git a/archival/dpkg.c b/archival/dpkg.c
index 5687e00be..55d97adda 100644
--- a/archival/dpkg.c
+++ b/archival/dpkg.c
@@ -31,7 +31,7 @@
31#endif 31#endif
32 32
33/* from dpkg-deb.c */ 33/* from dpkg-deb.c */
34extern int deb_extract(int optflags, const char *dir_name, const char *deb_filename); 34
35static const int dpkg_deb_contents = 1; 35static const int dpkg_deb_contents = 1;
36static const int dpkg_deb_control = 2; 36static const int dpkg_deb_control = 2;
37// const int dpkg_deb_info = 4; 37// const int dpkg_deb_info = 4;
diff --git a/archival/dpkg_deb.c b/archival/dpkg_deb.c
index 9f78e642c..450b04b8e 100644
--- a/archival/dpkg_deb.c
+++ b/archival/dpkg_deb.c
@@ -14,113 +14,18 @@
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
21#include <stdio.h>
22#include <stdlib.h> 17#include <stdlib.h>
23#include <fcntl.h> 18#include <getopt.h>
24#include <unistd.h>
25#include <string.h>
26#include <stdlib.h>
27#include <signal.h>
28#include "busybox.h" 19#include "busybox.h"
29 20
30/* From gunzip.c */
31extern int gz_open(FILE *compressed_file, int *pid);
32extern void gz_close(int gunzip_pid);
33
34extern int tar_unzip_init(int tarFd);
35extern int readTarFile(int tarFd, int extractFlag, int listFlag,
36 int tostdoutFlag, int verboseFlag, char** extractList, char** excludeList);
37
38static const int dpkg_deb_contents = 1;
39static const int dpkg_deb_control = 2;
40// const int dpkg_deb_info = 4;
41static const int dpkg_deb_extract = 8;
42static const int dpkg_deb_verbose_extract = 16;
43static const int dpkg_deb_list = 32;
44
45extern int deb_extract(int optflags, const char *dir_name, const char *deb_filename)
46{
47 char **extract_list = NULL;
48 ar_headers_t *ar_headers = NULL;
49 char ar_filename[15];
50 int extract_flag = FALSE;
51 int list_flag = FALSE;
52 int verbose_flag = FALSE;
53 int extract_to_stdout = FALSE;
54 int srcFd = 0;
55 int status;
56 pid_t pid;
57 FILE *comp_file = NULL;
58
59 if (dpkg_deb_contents == (dpkg_deb_contents & optflags)) {
60 strcpy(ar_filename, "data.tar.gz");
61 verbose_flag = TRUE;
62 list_flag = TRUE;
63 }
64 if (dpkg_deb_list == (dpkg_deb_list & optflags)) {
65 strcpy(ar_filename, "data.tar.gz");
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 /* Uncompress the file */
98 comp_file = fdopen(srcFd, "r");
99 if ((srcFd = gz_open(comp_file, &pid)) == EXIT_FAILURE) {
100 error_msg_and_die("Couldnt unzip file");
101 }
102 if ( dir_name != NULL) {
103 if (is_directory(dir_name, TRUE, NULL)==FALSE) {
104 mkdir(dir_name, 0755);
105 }
106 if (chdir(dir_name)==-1) {
107 error_msg_and_die("Cannot change to dir %s", dir_name);
108 }
109 }
110 status = readTarFile(srcFd, extract_flag, list_flag,
111 extract_to_stdout, verbose_flag, NULL, extract_list);
112
113 /* we are deliberately terminating the child so we can safely ignore this */
114 signal(SIGTERM, SIG_IGN);
115 gz_close(pid);
116 close(srcFd);
117 fclose(comp_file);
118
119 return status;
120}
121
122extern int dpkg_deb_main(int argc, char **argv) 21extern int dpkg_deb_main(int argc, char **argv)
123{ 22{
23 const int dpkg_deb_contents = 1;
24 const int dpkg_deb_control = 2;
25// const int dpkg_deb_info = 4;
26 const int dpkg_deb_extract = 8;
27 const int dpkg_deb_verbose_extract = 16;
28 const int dpkg_deb_list = 32;
124 char *target_dir = NULL; 29 char *target_dir = NULL;
125 int opt = 0; 30 int opt = 0;
126 int optflag = 0; 31 int optflag = 0;
diff --git a/dpkg.c b/dpkg.c
index 5687e00be..55d97adda 100644
--- a/dpkg.c
+++ b/dpkg.c
@@ -31,7 +31,7 @@
31#endif 31#endif
32 32
33/* from dpkg-deb.c */ 33/* from dpkg-deb.c */
34extern int deb_extract(int optflags, const char *dir_name, const char *deb_filename); 34
35static const int dpkg_deb_contents = 1; 35static const int dpkg_deb_contents = 1;
36static const int dpkg_deb_control = 2; 36static const int dpkg_deb_control = 2;
37// const int dpkg_deb_info = 4; 37// const int dpkg_deb_info = 4;
diff --git a/dpkg_deb.c b/dpkg_deb.c
index 9f78e642c..450b04b8e 100644
--- a/dpkg_deb.c
+++ b/dpkg_deb.c
@@ -14,113 +14,18 @@
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
21#include <stdio.h>
22#include <stdlib.h> 17#include <stdlib.h>
23#include <fcntl.h> 18#include <getopt.h>
24#include <unistd.h>
25#include <string.h>
26#include <stdlib.h>
27#include <signal.h>
28#include "busybox.h" 19#include "busybox.h"
29 20
30/* From gunzip.c */
31extern int gz_open(FILE *compressed_file, int *pid);
32extern void gz_close(int gunzip_pid);
33
34extern int tar_unzip_init(int tarFd);
35extern int readTarFile(int tarFd, int extractFlag, int listFlag,
36 int tostdoutFlag, int verboseFlag, char** extractList, char** excludeList);
37
38static const int dpkg_deb_contents = 1;
39static const int dpkg_deb_control = 2;
40// const int dpkg_deb_info = 4;
41static const int dpkg_deb_extract = 8;
42static const int dpkg_deb_verbose_extract = 16;
43static const int dpkg_deb_list = 32;
44
45extern int deb_extract(int optflags, const char *dir_name, const char *deb_filename)
46{
47 char **extract_list = NULL;
48 ar_headers_t *ar_headers = NULL;
49 char ar_filename[15];
50 int extract_flag = FALSE;
51 int list_flag = FALSE;
52 int verbose_flag = FALSE;
53 int extract_to_stdout = FALSE;
54 int srcFd = 0;
55 int status;
56 pid_t pid;
57 FILE *comp_file = NULL;
58
59 if (dpkg_deb_contents == (dpkg_deb_contents & optflags)) {
60 strcpy(ar_filename, "data.tar.gz");
61 verbose_flag = TRUE;
62 list_flag = TRUE;
63 }
64 if (dpkg_deb_list == (dpkg_deb_list & optflags)) {
65 strcpy(ar_filename, "data.tar.gz");
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 /* Uncompress the file */
98 comp_file = fdopen(srcFd, "r");
99 if ((srcFd = gz_open(comp_file, &pid)) == EXIT_FAILURE) {
100 error_msg_and_die("Couldnt unzip file");
101 }
102 if ( dir_name != NULL) {
103 if (is_directory(dir_name, TRUE, NULL)==FALSE) {
104 mkdir(dir_name, 0755);
105 }
106 if (chdir(dir_name)==-1) {
107 error_msg_and_die("Cannot change to dir %s", dir_name);
108 }
109 }
110 status = readTarFile(srcFd, extract_flag, list_flag,
111 extract_to_stdout, verbose_flag, NULL, extract_list);
112
113 /* we are deliberately terminating the child so we can safely ignore this */
114 signal(SIGTERM, SIG_IGN);
115 gz_close(pid);
116 close(srcFd);
117 fclose(comp_file);
118
119 return status;
120}
121
122extern int dpkg_deb_main(int argc, char **argv) 21extern int dpkg_deb_main(int argc, char **argv)
123{ 22{
23 const int dpkg_deb_contents = 1;
24 const int dpkg_deb_control = 2;
25// const int dpkg_deb_info = 4;
26 const int dpkg_deb_extract = 8;
27 const int dpkg_deb_verbose_extract = 16;
28 const int dpkg_deb_list = 32;
124 char *target_dir = NULL; 29 char *target_dir = NULL;
125 int opt = 0; 30 int opt = 0;
126 int optflag = 0; 31 int optflag = 0;
diff --git a/include/libbb.h b/include/libbb.h
index 649fe11c1..06215d12b 100644
--- a/include/libbb.h
+++ b/include/libbb.h
@@ -226,5 +226,5 @@ typedef struct ar_headers_s {
226 struct ar_headers_s *next; 226 struct ar_headers_s *next;
227} ar_headers_t; 227} ar_headers_t;
228extern ar_headers_t get_ar_headers(int srcFd); 228extern ar_headers_t get_ar_headers(int srcFd);
229 229extern int deb_extract(int optflags, const char *dir_name, const char *deb_filename);
230#endif /* __LIBBB_H__ */ 230#endif /* __LIBBB_H__ */
diff --git a/libbb/deb_extract.c b/libbb/deb_extract.c
new file mode 100644
index 000000000..358c4d0a8
--- /dev/null
+++ b/libbb/deb_extract.c
@@ -0,0 +1,122 @@
1/* vi: set sw=4 ts=4: */
2/*
3 * Copyright (C) tons of folks. Tracking down who wrote what
4 * isn't something I'm going to worry about... If you wrote something
5 * here, please feel free to acknowledge your work.
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 *
21 * Based in part on code from sash, Copyright (c) 1999 by David I. Bell
22 * Permission has been granted to redistribute this code under the GPL.
23 *
24 */
25
26#include <fcntl.h>
27#include <unistd.h>
28#include <stdlib.h>
29#include <signal.h>
30#include "libbb.h"
31
32/* From gunzip.c */
33extern int gz_open(FILE *compressed_file, int *pid);
34extern void gz_close(int gunzip_pid);
35
36extern int tar_unzip_init(int tarFd);
37extern int readTarFile(int tarFd, int extractFlag, int listFlag,
38 int tostdoutFlag, int verboseFlag, char** extractList, char** excludeList);
39
40extern int deb_extract(int optflags, const char *dir_name, const char *deb_filename)
41{
42 const int dpkg_deb_contents = 1;
43 const int dpkg_deb_control = 2;
44// const int dpkg_deb_info = 4;
45 const int dpkg_deb_extract = 8;
46 const int dpkg_deb_verbose_extract = 16;
47 const int dpkg_deb_list = 32;
48
49 char **extract_list = NULL;
50 ar_headers_t *ar_headers = NULL;
51 char ar_filename[15];
52 int extract_flag = FALSE;
53 int list_flag = FALSE;
54 int verbose_flag = FALSE;
55 int extract_to_stdout = FALSE;
56 int srcFd = 0;
57 int status;
58 pid_t pid;
59 FILE *comp_file = NULL;
60
61 if (dpkg_deb_contents == (dpkg_deb_contents & optflags)) {
62 strcpy(ar_filename, "data.tar.gz");
63 verbose_flag = TRUE;
64 list_flag = TRUE;
65 }
66 if (dpkg_deb_list == (dpkg_deb_list & optflags)) {
67 strcpy(ar_filename, "data.tar.gz");
68 list_flag = TRUE;
69 }
70 if (dpkg_deb_control == (dpkg_deb_control & optflags)) {
71 strcpy(ar_filename, "control.tar.gz");
72 extract_flag = TRUE;
73 }
74 if (dpkg_deb_extract == (dpkg_deb_extract & optflags)) {
75 strcpy(ar_filename, "data.tar.gz");
76 extract_flag = TRUE;
77 }
78 if (dpkg_deb_verbose_extract == (dpkg_deb_verbose_extract & optflags)) {
79 strcpy(ar_filename, "data.tar.gz");
80 extract_flag = TRUE;
81 list_flag = TRUE;
82 }
83
84 ar_headers = (ar_headers_t *) xmalloc(sizeof(ar_headers_t));
85 srcFd = open(deb_filename, O_RDONLY);
86
87 *ar_headers = get_ar_headers(srcFd);
88 if (ar_headers->next == NULL) {
89 error_msg_and_die("Couldnt find %s in %s", ar_filename, deb_filename);
90 }
91
92 while (ar_headers->next != NULL) {
93 if (strcmp(ar_headers->name, ar_filename) == 0) {
94 break;
95 }
96 ar_headers = ar_headers->next;
97 }
98 lseek(srcFd, ar_headers->offset, SEEK_SET);
99 /* Uncompress the file */
100 comp_file = fdopen(srcFd, "r");
101 if ((srcFd = gz_open(comp_file, &pid)) == EXIT_FAILURE) {
102 error_msg_and_die("Couldnt unzip file");
103 }
104 if ( dir_name != NULL) {
105 if (is_directory(dir_name, TRUE, NULL)==FALSE) {
106 mkdir(dir_name, 0755);
107 }
108 if (chdir(dir_name)==-1) {
109 error_msg_and_die("Cannot change to dir %s", dir_name);
110 }
111 }
112 status = readTarFile(srcFd, extract_flag, list_flag,
113 extract_to_stdout, verbose_flag, NULL, extract_list);
114
115 /* we are deliberately terminating the child so we can safely ignore this */
116 signal(SIGTERM, SIG_IGN);
117 gz_close(pid);
118 close(srcFd);
119 fclose(comp_file);
120
121 return status;
122} \ No newline at end of file
diff --git a/libbb/libbb.h b/libbb/libbb.h
index 649fe11c1..06215d12b 100644
--- a/libbb/libbb.h
+++ b/libbb/libbb.h
@@ -226,5 +226,5 @@ typedef struct ar_headers_s {
226 struct ar_headers_s *next; 226 struct ar_headers_s *next;
227} ar_headers_t; 227} ar_headers_t;
228extern ar_headers_t get_ar_headers(int srcFd); 228extern ar_headers_t get_ar_headers(int srcFd);
229 229extern int deb_extract(int optflags, const char *dir_name, const char *deb_filename);
230#endif /* __LIBBB_H__ */ 230#endif /* __LIBBB_H__ */