Add error checking to deb_extract(), unarchive(), extract_archive(). et al.
[project/opkg-lede.git] / libopkg / pkg_extract.c
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 "includes.h"
19 #include <errno.h>
20
21 #include "pkg_extract.h"
22
23 #include "libbb/libbb.h"
24 #include "file_util.h"
25 #include "sprintf_alloc.h"
26
27 /* assuage libb functions */
28 const char *applet_name = "opkg";
29
30 int
31 pkg_extract_control_file_to_stream(pkg_t *pkg, FILE *stream)
32 {
33 int err;
34 deb_extract(pkg->local_filename, stream,
35 extract_control_tar_gz
36 | extract_to_stream,
37 NULL, "./control", &err);
38
39 return err;
40 }
41
42 int
43 pkg_extract_control_files_to_dir_with_prefix(pkg_t *pkg, const char *dir,
44 const char *prefix)
45 {
46 int err;
47 char *dir_with_prefix;
48
49 sprintf_alloc(&dir_with_prefix, "%s/%s", dir, prefix);
50
51 deb_extract(pkg->local_filename, stderr,
52 extract_control_tar_gz
53 | extract_all_to_fs| extract_preserve_date
54 | extract_unconditional,
55 dir_with_prefix, NULL, &err);
56
57 free(dir_with_prefix);
58 return err;
59 }
60
61 int
62 pkg_extract_control_files_to_dir(pkg_t *pkg, const char *dir)
63 {
64 return pkg_extract_control_files_to_dir_with_prefix(pkg, dir, "");
65 }
66
67
68 int
69 pkg_extract_data_files_to_dir(pkg_t *pkg, const char *dir)
70 {
71 int err;
72
73 deb_extract(pkg->local_filename, stderr,
74 extract_data_tar_gz
75 | extract_all_to_fs| extract_preserve_date
76 | extract_unconditional,
77 dir, NULL, &err);
78
79 return err;
80 }
81
82 int
83 pkg_extract_data_file_names_to_stream(pkg_t *pkg, FILE *stream)
84 {
85 int err;
86
87 /* XXX: DPKG_INCOMPATIBILITY: deb_extract will extract all of the
88 data file names with a '.' as the first character. I've taught
89 opkg how to cope with the presence or absence of the '.', but
90 this may trip up dpkg.
91
92 For all I know, this could actually be a bug in opkg-build. So,
93 I'll have to try installing some .debs and comparing the *.list
94 files.
95
96 If we wanted to, we could workaround the deb_extract behavior
97 right here, by writing to a tmpfile, then munging things as we
98 wrote to the actual stream. */
99
100 deb_extract(pkg->local_filename, stream,
101 extract_quiet | extract_data_tar_gz | extract_list,
102 NULL, NULL, &err);
103
104 return err;
105 }