1 /* pkg_extract.c - the opkg package management system
2 
3    Carl D. Worth
4 
5    Copyright (C) 2001 University of Southern California
6 
7    This program is free software; you can redistribute it and/or
8    modify it under the terms of the GNU General Public License as
9    published by the Free Software Foundation; either version 2, or (at
10    your option) any later version.
11 
12    This program is distributed in the hope that it will be useful, but
13    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 
18 #include <stdio.h>
19 
20 #include "pkg_extract.h"
21 #include "libbb/libbb.h"
22 #include "file_util.h"
23 #include "sprintf_alloc.h"
24 
pkg_extract_control_file_to_stream(pkg_t * pkg,FILE * stream)25 int pkg_extract_control_file_to_stream(pkg_t * pkg, FILE * stream)
26 {
27 	int err;
28 	deb_extract(pkg_get_string(pkg, PKG_LOCAL_FILENAME), stream,
29 		    extract_control_tar_gz
30 		    | extract_to_stream, NULL, "control", &err);
31 	return err;
32 }
33 
34 int
pkg_extract_control_files_to_dir_with_prefix(pkg_t * pkg,const char * dir,const char * prefix)35 pkg_extract_control_files_to_dir_with_prefix(pkg_t * pkg, const char *dir,
36 					     const char *prefix)
37 {
38 	int err;
39 	char *dir_with_prefix;
40 
41 	sprintf_alloc(&dir_with_prefix, "%s/%s", dir, prefix);
42 
43 	deb_extract(pkg_get_string(pkg, PKG_LOCAL_FILENAME), stderr,
44 		    extract_control_tar_gz
45 		    | extract_all_to_fs | extract_preserve_date
46 		    | extract_unconditional, dir_with_prefix, NULL, &err);
47 
48 	free(dir_with_prefix);
49 	return err;
50 }
51 
pkg_extract_control_files_to_dir(pkg_t * pkg,const char * dir)52 int pkg_extract_control_files_to_dir(pkg_t * pkg, const char *dir)
53 {
54 	return pkg_extract_control_files_to_dir_with_prefix(pkg, dir, "");
55 }
56 
pkg_extract_data_files_to_dir(pkg_t * pkg,const char * dir)57 int pkg_extract_data_files_to_dir(pkg_t * pkg, const char *dir)
58 {
59 	int err;
60 
61 	deb_extract(pkg_get_string(pkg, PKG_LOCAL_FILENAME), stderr,
62 		    extract_data_tar_gz
63 		    | extract_all_to_fs | extract_preserve_date
64 		    | extract_unconditional, dir, NULL, &err);
65 
66 	return err;
67 }
68 
pkg_extract_data_file_names_to_stream(pkg_t * pkg,FILE * stream)69 int pkg_extract_data_file_names_to_stream(pkg_t * pkg, FILE * stream)
70 {
71 	int err;
72 
73 	/* XXX: DPKG_INCOMPATIBILITY: deb_extract will extract all of the
74 	   data file names with a '.' as the first character. I've taught
75 	   opkg how to cope with the presence or absence of the '.', but
76 	   this may trip up dpkg.
77 
78 	   For all I know, this could actually be a bug in opkg-build. So,
79 	   I'll have to try installing some .debs and comparing the *.list
80 	   files.
81 
82 	   If we wanted to, we could workaround the deb_extract behavior
83 	   right here, by writing to a tmpfile, then munging things as we
84 	   wrote to the actual stream. */
85 
86 	deb_extract(pkg_get_string(pkg, PKG_LOCAL_FILENAME), stream,
87 		    extract_quiet | extract_data_tar_gz | extract_list,
88 		    NULL, NULL, &err);
89 
90 	return err;
91 }
92