96ec7d410e93e83b8d503bb88ced061db3051bcd
[project/opkg-lede.git] / libopkg / opkg.c
1 /* opkg.c - the opkg package management system
2
3 Thomas Wood <thomas@openedhand.com>
4
5 Copyright (C) 2008 OpenMoko Inc
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 <config.h>
19 #include <fnmatch.h>
20
21 #include "opkg.h"
22 #include "opkg_conf.h"
23 #include "args.h"
24
25 #include "opkg_install.h"
26 #include "opkg_configure.h"
27
28 struct _opkg_t
29 {
30 args_t *args;
31 opkg_conf_t *conf;
32 };
33
34 /** Private Functions ***/
35
36
37 static int
38 opkg_configure_packages(opkg_conf_t *conf, char *pkg_name)
39 {
40 pkg_vec_t *all;
41 int i;
42 pkg_t *pkg;
43 int r, err = 0;
44
45 all = pkg_vec_alloc();
46 pkg_hash_fetch_available(&conf->pkg_hash, all);
47
48 for (i = 0; i < all->len; i++)
49 {
50 pkg = all->pkgs[i];
51
52 if (pkg_name && fnmatch(pkg_name, pkg->name, 0))
53 continue;
54
55 if (pkg->state_status == SS_UNPACKED)
56 {
57 r = opkg_configure(conf, pkg);
58 if (r == 0)
59 {
60 pkg->state_status = SS_INSTALLED;
61 pkg->parent->state_status = SS_INSTALLED;
62 pkg->state_flag &= ~SF_PREFER;
63 }
64 else
65 {
66 if (!err)
67 err = r;
68 }
69 }
70 }
71
72 pkg_vec_free(all);
73 return err;
74 }
75
76
77
78 /*** Public API ***/
79
80 opkg_t *
81 opkg_new ()
82 {
83 opkg_t *opkg;
84 opkg = malloc (sizeof (opkg_t));
85 args_init (opkg->args);
86 opkg_conf_init (opkg->conf, opkg->args);
87 return opkg;
88 }
89
90 void
91 opkg_free (opkg_t *opkg)
92 {
93 opkg_conf_deinit (opkg->conf);
94 args_deinit (opkg->args);
95 }
96
97 void
98 opkg_get_option (opkg_t *opkg, char *option, void **value)
99 {
100 }
101
102 void
103 opkg_set_option (opkg_t *opkg, char *option, void *value)
104 {
105 }
106
107 int
108 opkg_install_package (opkg_t *opkg, char *package_name)
109 {
110 int err;
111
112 pkg_info_preinstall_check(opkg->conf);
113
114 if (opkg->conf->multiple_providers)
115 {
116 err = opkg_install_multi_by_name (opkg->conf, package_name);
117 }
118 else
119 {
120 err = opkg_install_by_name (opkg->conf, package_name);
121 }
122
123 err = opkg_configure_packages (opkg->conf, NULL);
124
125 if (opkg->conf->noaction)
126 return err;
127
128 opkg_conf_write_status_files (opkg->conf);
129 pkg_write_changed_filelists (opkg->conf);
130
131 return err;
132 }
133
134 int
135 opkg_remove_package (opkg_t *opkg, char *package_name)
136 {
137 return 1;
138 }
139
140 int
141 opkg_upgrade_package (opkg_t *opkg, char *package_name)
142 {
143 return 1;
144 }
145
146 int
147 opkg_upgrade_all (opkg_t *opkg)
148 {
149 return 1;
150 }
151
152 int
153 opkg_update_package_lists (opkg_t *opkg)
154 {
155 return 1;
156 }