Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 618 lines (536 sloc) 16.997 kb
9673756 @hughsie Add ZifMdFilelistsXml so we can read filelists from rpmfusion-free
authored
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
2 *
3 * Copyright (C) 2010 Richard Hughes <richard@hughsie.com>
4 *
5 * Licensed under the GNU General Public License Version 2
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
15 * GNU 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 */
21
22 /**
23 * SECTION:zif-md-filelists-xml
f396d3b @hughsie trivial: make a metric ton of GTK-DOC cleanups
authored
24 * @short_description: FilelistsXml metadata
9673756 @hughsie Add ZifMdFilelistsXml so we can read filelists from rpmfusion-free
authored
25 *
26 * Provide access to the filelists_xml repo metadata.
27 * This object is a subclass of #ZifMd
28 */
29
30 typedef enum {
31 ZIF_MD_FILELISTS_XML_SECTION_LIST,
32 ZIF_MD_FILELISTS_XML_SECTION_UNKNOWN
33 } ZifMdFilelistsXmlSection;
34
35 typedef enum {
36 ZIF_MD_FILELISTS_XML_SECTION_LIST_PACKAGE,
37 ZIF_MD_FILELISTS_XML_SECTION_LIST_UNKNOWN
38 } ZifMdFilelistsXmlSectionList;
39
40 typedef enum {
41 ZIF_MD_FILELISTS_XML_SECTION_LIST_PACKAGE_FILE,
42 ZIF_MD_FILELISTS_XML_SECTION_LIST_PACKAGE_UNKNOWN
43 } ZifMdFilelistsXmlSectionListPackage;
44
45 #ifdef HAVE_CONFIG_H
46 # include <config.h>
47 #endif
48
49 #include <glib.h>
50 #include <string.h>
51 #include <stdlib.h>
52 #include <sqlite3.h>
53 #include <gio/gio.h>
54
6817d97 @hughsie Set the correct version compare mode for new packages
authored
55 #include "zif-config.h"
9673756 @hughsie Add ZifMdFilelistsXml so we can read filelists from rpmfusion-free
authored
56 #include "zif-md-filelists-xml.h"
dcebd37 @hughsie Don't add includes in zif.h that are not supposed to be exported
authored
57 #include "zif-md.h"
58 #include "zif-package-private.h"
fc63678 @hughsie Add the functionality to get the file lists for a remote package
authored
59 #include "zif-package-remote.h"
d8e4323 @hughsie trivial: unexport some ZifState stuff from <zif.h>
authored
60 #include "zif-state-private.h"
dcebd37 @hughsie Don't add includes in zif.h that are not supposed to be exported
authored
61 #include "zif-string.h"
9673756 @hughsie Add ZifMdFilelistsXml so we can read filelists from rpmfusion-free
authored
62
63 #define ZIF_MD_FILELISTS_XML_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), ZIF_TYPE_MD_FILELISTS_XML, ZifMdFilelistsXmlPrivate))
64
65 /**
66 * ZifMdFilelistsXmlPrivate:
67 *
68 * Private #ZifMdFilelistsXml data
69 **/
70 struct _ZifMdFilelistsXmlPrivate
71 {
72 gboolean loaded;
73 ZifMdFilelistsXmlSection section;
74 ZifMdFilelistsXmlSectionList section_list;
75 ZifMdFilelistsXmlSectionListPackage section_list_package;
76 ZifPackage *package_temp;
77 GPtrArray *array;
78 GPtrArray *array_temp;
6817d97 @hughsie Set the correct version compare mode for new packages
authored
79 ZifConfig *config;
80 ZifPackageCompareMode compare_mode;
9673756 @hughsie Add ZifMdFilelistsXml so we can read filelists from rpmfusion-free
authored
81 };
82
83 G_DEFINE_TYPE (ZifMdFilelistsXml, zif_md_filelists_xml, ZIF_TYPE_MD)
84
85 /**
86 * zif_md_filelists_xml_unload:
87 **/
88 static gboolean
45b3b5f @hughsie Smush a GCancellable into #ZifState to reduce the number of args in l…
authored
89 zif_md_filelists_xml_unload (ZifMd *md, ZifState *state, GError **error)
9673756 @hughsie Add ZifMdFilelistsXml so we can read filelists from rpmfusion-free
authored
90 {
91 gboolean ret = FALSE;
92 return ret;
93 }
94
95 /**
96 * zif_md_filelists_xml_parser_start_element:
97 **/
98 static void
6817d97 @hughsie Set the correct version compare mode for new packages
authored
99 zif_md_filelists_xml_parser_start_element (GMarkupParseContext *context,
100 const gchar *element_name,
101 const gchar **attribute_names,
102 const gchar **attribute_values,
103 gpointer user_data,
104 GError **error)
9673756 @hughsie Add ZifMdFilelistsXml so we can read filelists from rpmfusion-free
authored
105 {
106 guint i;
107 ZifMdFilelistsXml *filelists_xml = user_data;
6817d97 @hughsie Set the correct version compare mode for new packages
authored
108 ZifString *tmp;
9673756 @hughsie Add ZifMdFilelistsXml so we can read filelists from rpmfusion-free
authored
109
110 g_return_if_fail (ZIF_IS_MD_FILELISTS_XML (filelists_xml));
111
112 /* group element */
113 if (filelists_xml->priv->section == ZIF_MD_FILELISTS_XML_SECTION_UNKNOWN) {
114
115 /* start of update */
116 if (g_strcmp0 (element_name, "filelists") == 0) {
117 filelists_xml->priv->section = ZIF_MD_FILELISTS_XML_SECTION_LIST;
118 goto out;
119 }
120
5ad0ab4 @hughsie Remove EggDebug and use the GLib logging system
authored
121 g_warning ("unhandled element: %s", element_name);
9673756 @hughsie Add ZifMdFilelistsXml so we can read filelists from rpmfusion-free
authored
122 goto out;
123 }
124
125 /* update element */
126 if (filelists_xml->priv->section == ZIF_MD_FILELISTS_XML_SECTION_LIST) {
127
128 if (filelists_xml->priv->section_list == ZIF_MD_FILELISTS_XML_SECTION_LIST_UNKNOWN) {
129
130 if (g_strcmp0 (element_name, "package") == 0) {
131 filelists_xml->priv->section_list = ZIF_MD_FILELISTS_XML_SECTION_LIST_PACKAGE;
fc63678 @hughsie Add the functionality to get the file lists for a remote package
authored
132 filelists_xml->priv->package_temp = ZIF_PACKAGE (zif_package_remote_new ());
6817d97 @hughsie Set the correct version compare mode for new packages
authored
133 zif_package_set_compare_mode (filelists_xml->priv->package_temp,
134 filelists_xml->priv->compare_mode);
9673756 @hughsie Add ZifMdFilelistsXml so we can read filelists from rpmfusion-free
authored
135 filelists_xml->priv->array_temp = g_ptr_array_new_with_free_func (g_free);
136 for (i=0; attribute_names[i] != NULL; i++) {
137 if (g_strcmp0 (attribute_names[i], "pkgid") == 0) {
8b93a5d @hughsie Move the pkgid state from ZifPackageRemote to ZifPackage as a local p…
authored
138 tmp = zif_string_new (attribute_values[i]);
139 zif_package_set_pkgid (filelists_xml->priv->package_temp,
140 tmp);
141 zif_string_unref (tmp);
9673756 @hughsie Add ZifMdFilelistsXml so we can read filelists from rpmfusion-free
authored
142 }
143 }
144 goto out;
145 }
146
5ad0ab4 @hughsie Remove EggDebug and use the GLib logging system
authored
147 g_warning ("unhandled update list tag: %s", element_name);
9673756 @hughsie Add ZifMdFilelistsXml so we can read filelists from rpmfusion-free
authored
148 goto out;
149
150 }
151 if (filelists_xml->priv->section_list == ZIF_MD_FILELISTS_XML_SECTION_LIST_PACKAGE) {
152
153 if (g_strcmp0 (element_name, "version") == 0) {
154 filelists_xml->priv->section_list_package = ZIF_MD_FILELISTS_XML_SECTION_LIST_UNKNOWN;
155 goto out;
156 }
157
158 if (g_strcmp0 (element_name, "file") == 0) {
159 filelists_xml->priv->section_list_package = ZIF_MD_FILELISTS_XML_SECTION_LIST_PACKAGE_FILE;
160 goto out;
161 }
5ad0ab4 @hughsie Remove EggDebug and use the GLib logging system
authored
162 g_warning ("unhandled update package tag: %s", element_name);
9673756 @hughsie Add ZifMdFilelistsXml so we can read filelists from rpmfusion-free
authored
163 goto out;
164 }
5ad0ab4 @hughsie Remove EggDebug and use the GLib logging system
authored
165 g_warning ("unhandled package tag: %s", element_name);
9673756 @hughsie Add ZifMdFilelistsXml so we can read filelists from rpmfusion-free
authored
166 }
167
5ad0ab4 @hughsie Remove EggDebug and use the GLib logging system
authored
168 g_warning ("unhandled base tag: %s", element_name);
9673756 @hughsie Add ZifMdFilelistsXml so we can read filelists from rpmfusion-free
authored
169
170 out:
171 return;
172 }
173
174 /**
175 * zif_md_filelists_xml_parser_end_element:
176 **/
177 static void
178 zif_md_filelists_xml_parser_end_element (GMarkupParseContext *context, const gchar *element_name,
179 gpointer user_data, GError **error)
180 {
181 ZifMdFilelistsXml *filelists_xml = user_data;
182
183 /* no element */
184 if (filelists_xml->priv->section == ZIF_MD_FILELISTS_XML_SECTION_UNKNOWN) {
5ad0ab4 @hughsie Remove EggDebug and use the GLib logging system
authored
185 g_warning ("unhandled base end tag: %s", element_name);
9673756 @hughsie Add ZifMdFilelistsXml so we can read filelists from rpmfusion-free
authored
186 goto out;
187 }
188
189 /* update element */
190 if (filelists_xml->priv->section == ZIF_MD_FILELISTS_XML_SECTION_LIST) {
191
192 /* update element */
193 if (filelists_xml->priv->section_list == ZIF_MD_FILELISTS_XML_SECTION_LIST_UNKNOWN) {
194
195 /* end of list */
196 if (g_strcmp0 (element_name, "filelists") == 0) {
197 filelists_xml->priv->section = ZIF_MD_FILELISTS_XML_SECTION_UNKNOWN;
198 goto out;
199 }
5ad0ab4 @hughsie Remove EggDebug and use the GLib logging system
authored
200 g_warning ("unhandled outside tag: %s", element_name);
9673756 @hughsie Add ZifMdFilelistsXml so we can read filelists from rpmfusion-free
authored
201 goto out;
202 }
203
204 /* update element */
205 if (filelists_xml->priv->section_list == ZIF_MD_FILELISTS_XML_SECTION_LIST_PACKAGE) {
206
207 if (filelists_xml->priv->section_list_package == ZIF_MD_FILELISTS_XML_SECTION_LIST_PACKAGE_UNKNOWN) {
208
209 if (g_strcmp0 (element_name, "version") == 0)
210 goto out;
211
212 /* end of list */
213 if (g_strcmp0 (element_name, "package") == 0) {
214 zif_package_set_files (filelists_xml->priv->package_temp, filelists_xml->priv->array_temp);
fb4f338 @hughsie Add zif_package_set_provides_files() so the file provides can be set …
authored
215 zif_package_set_provides_files (filelists_xml->priv->package_temp, filelists_xml->priv->array_temp);
9673756 @hughsie Add ZifMdFilelistsXml so we can read filelists from rpmfusion-free
authored
216 g_ptr_array_add (filelists_xml->priv->array, filelists_xml->priv->package_temp);
217 filelists_xml->priv->package_temp = NULL;
218 filelists_xml->priv->array_temp = NULL;
219 filelists_xml->priv->section_list = ZIF_MD_FILELISTS_XML_SECTION_LIST_UNKNOWN;
220 goto out;
221 }
5ad0ab4 @hughsie Remove EggDebug and use the GLib logging system
authored
222 g_warning ("unhandled package tag: %s", element_name);
9673756 @hughsie Add ZifMdFilelistsXml so we can read filelists from rpmfusion-free
authored
223 goto out;
224 }
225
226 if (filelists_xml->priv->section_list_package == ZIF_MD_FILELISTS_XML_SECTION_LIST_PACKAGE_FILE) {
227 if (g_strcmp0 (element_name, "file") == 0) {
228 filelists_xml->priv->section_list_package = ZIF_MD_FILELISTS_XML_SECTION_LIST_PACKAGE_UNKNOWN;
229 goto out;
230 }
5ad0ab4 @hughsie Remove EggDebug and use the GLib logging system
authored
231 g_warning ("unhandled end of file tag: %s", element_name);
9673756 @hughsie Add ZifMdFilelistsXml so we can read filelists from rpmfusion-free
authored
232 goto out;
233 }
5ad0ab4 @hughsie Remove EggDebug and use the GLib logging system
authored
234 g_warning ("unhandled end of package tag: %s", element_name);
9673756 @hughsie Add ZifMdFilelistsXml so we can read filelists from rpmfusion-free
authored
235 goto out;
236 }
237
5ad0ab4 @hughsie Remove EggDebug and use the GLib logging system
authored
238 g_warning ("unhandled update end tag: %s", element_name);
9673756 @hughsie Add ZifMdFilelistsXml so we can read filelists from rpmfusion-free
authored
239 goto out;
240 }
241
5ad0ab4 @hughsie Remove EggDebug and use the GLib logging system
authored
242 g_warning ("unhandled end tag: %s", element_name);
9673756 @hughsie Add ZifMdFilelistsXml so we can read filelists from rpmfusion-free
authored
243 out:
244 return;
245 }
246
247 /**
248 * zif_md_filelists_xml_parser_text:
249 **/
250 static void
251 zif_md_filelists_xml_parser_text (GMarkupParseContext *context, const gchar *text, gsize text_len,
252 gpointer user_data, GError **error)
253
254 {
255 ZifMdFilelistsXml *filelists_xml = user_data;
256
257 /* skip whitespace */
258 if (text_len < 1 || text[0] == ' ' || text[0] == '\t' || text[0] == '\n')
259 goto out;
260
261 /* group section */
262 if (filelists_xml->priv->section == ZIF_MD_FILELISTS_XML_SECTION_LIST) {
263 if (filelists_xml->priv->section_list == ZIF_MD_FILELISTS_XML_SECTION_LIST_UNKNOWN) {
5ad0ab4 @hughsie Remove EggDebug and use the GLib logging system
authored
264 g_warning ("not saving: %s", text);
9673756 @hughsie Add ZifMdFilelistsXml so we can read filelists from rpmfusion-free
authored
265 goto out;
266 }
267 if (filelists_xml->priv->section_list == ZIF_MD_FILELISTS_XML_SECTION_LIST_PACKAGE) {
706e45e @hughsie Fix up a couple of enum types that caused a compile warning
authored
268 if (filelists_xml->priv->section_list_package == ZIF_MD_FILELISTS_XML_SECTION_LIST_PACKAGE_FILE) {
9673756 @hughsie Add ZifMdFilelistsXml so we can read filelists from rpmfusion-free
authored
269 g_ptr_array_add (filelists_xml->priv->array_temp, g_strdup (text));
270 goto out;
271 };
5ad0ab4 @hughsie Remove EggDebug and use the GLib logging system
authored
272 g_warning ("not saving: %s", text);
9673756 @hughsie Add ZifMdFilelistsXml so we can read filelists from rpmfusion-free
authored
273 goto out;
274 }
5ad0ab4 @hughsie Remove EggDebug and use the GLib logging system
authored
275 g_warning ("not saving: %s", text);
9673756 @hughsie Add ZifMdFilelistsXml so we can read filelists from rpmfusion-free
authored
276 goto out;
277 }
278 out:
279 return;
280 }
281
282 /**
283 * zif_md_filelists_xml_load:
284 **/
285 static gboolean
45b3b5f @hughsie Smush a GCancellable into #ZifState to reduce the number of args in l…
authored
286 zif_md_filelists_xml_load (ZifMd *md, ZifState *state, GError **error)
9673756 @hughsie Add ZifMdFilelistsXml so we can read filelists from rpmfusion-free
authored
287 {
288 const gchar *filename;
289 gboolean ret;
290 gchar *contents = NULL;
291 gsize size;
292 ZifMdFilelistsXml *filelists_xml = ZIF_MD_FILELISTS_XML (md);
293 GMarkupParseContext *context = NULL;
294 const GMarkupParser gpk_md_filelists_xml_markup_parser = {
295 zif_md_filelists_xml_parser_start_element,
296 zif_md_filelists_xml_parser_end_element,
297 zif_md_filelists_xml_parser_text,
298 NULL, /* passthrough */
299 NULL /* error */
300 };
301
302 g_return_val_if_fail (ZIF_IS_MD_FILELISTS_XML (md), FALSE);
971563d @hughsie Add zif_state_valid() and get a lot more strict for ZifState problems
authored
303 g_return_val_if_fail (zif_state_valid (state), FALSE);
9673756 @hughsie Add ZifMdFilelistsXml so we can read filelists from rpmfusion-free
authored
304
305 /* already loaded */
306 if (filelists_xml->priv->loaded)
307 goto out;
308
6817d97 @hughsie Set the correct version compare mode for new packages
authored
309 /* get the compare mode */
0d6fc7a @hughsie Use zif_config_get_enum() to avoid leaking pkg_compare_mode each time
authored
310 filelists_xml->priv->compare_mode = zif_config_get_enum (filelists_xml->priv->config,
311 "pkg_compare_mode",
312 zif_package_compare_mode_from_string,
313 error);
314 if (filelists_xml->priv->compare_mode == G_MAXUINT)
6817d97 @hughsie Set the correct version compare mode for new packages
authored
315 goto out;
316
9673756 @hughsie Add ZifMdFilelistsXml so we can read filelists from rpmfusion-free
authored
317 /* get filename */
318 filename = zif_md_get_filename_uncompressed (md);
319 if (filename == NULL) {
320 g_set_error_literal (error, ZIF_MD_ERROR, ZIF_MD_ERROR_FAILED,
321 "failed to get filename for filelists_xml");
322 goto out;
323 }
324
325 /* open database */
5ad0ab4 @hughsie Remove EggDebug and use the GLib logging system
authored
326 g_debug ("filename = %s", filename);
d897d9c @hughsie Check for cancel in many, many more places
authored
327 zif_state_set_allow_cancel (state, FALSE);
9673756 @hughsie Add ZifMdFilelistsXml so we can read filelists from rpmfusion-free
authored
328 ret = g_file_get_contents (filename, &contents, &size, error);
329 if (!ret)
330 goto out;
331
332 /* create parser */
333 context = g_markup_parse_context_new (&gpk_md_filelists_xml_markup_parser, G_MARKUP_PREFIX_ERROR_POSITION, filelists_xml, NULL);
334
335 /* parse data */
d897d9c @hughsie Check for cancel in many, many more places
authored
336 zif_state_set_allow_cancel (state, FALSE);
9673756 @hughsie Add ZifMdFilelistsXml so we can read filelists from rpmfusion-free
authored
337 ret = g_markup_parse_context_parse (context, contents, (gssize) size, error);
338 if (!ret)
339 goto out;
340
341 /* we don't need to keep syncing */
342 filelists_xml->priv->loaded = TRUE;
343 out:
0c2ee4f @hughsie Fix up some memory leaks spotted by valgrind
authored
344 if (context != NULL)
345 g_markup_parse_context_free (context);
9673756 @hughsie Add ZifMdFilelistsXml so we can read filelists from rpmfusion-free
authored
346 g_free (contents);
347 return filelists_xml->priv->loaded;
348 }
349
350 /**
fc63678 @hughsie Add the functionality to get the file lists for a remote package
authored
351 * zif_md_filelists_xml_get_files:
352 **/
353 static GPtrArray *
354 zif_md_filelists_xml_get_files (ZifMd *md, ZifPackage *package,
45b3b5f @hughsie Smush a GCancellable into #ZifState to reduce the number of args in l…
authored
355 ZifState *state, GError **error)
fc63678 @hughsie Add the functionality to get the file lists for a remote package
authored
356 {
357 GPtrArray *array = NULL;
358 GPtrArray *packages;
359 ZifPackage *package_tmp;
c9c089e @hughsie Fix the error handling when getting filelists from XML metadata
authored
360 ZifPackage *package_found = NULL;
fc63678 @hughsie Add the functionality to get the file lists for a remote package
authored
361 guint i;
362 gboolean ret;
363 const gchar *pkgid;
364 const gchar *pkgid_tmp;
365 GError *error_local = NULL;
65c90f0 @hughsie Rename ZifCompletion to ZifState
authored
366 ZifState *state_local;
fc63678 @hughsie Add the functionality to get the file lists for a remote package
authored
367 ZifMdFilelistsXml *md_filelists = ZIF_MD_FILELISTS_XML (md);
368
369 g_return_val_if_fail (ZIF_IS_MD_FILELISTS_XML (md), NULL);
971563d @hughsie Add zif_state_valid() and get a lot more strict for ZifState problems
authored
370 g_return_val_if_fail (zif_state_valid (state), NULL);
fc63678 @hughsie Add the functionality to get the file lists for a remote package
authored
371 g_return_val_if_fail (error == NULL || *error == NULL, NULL);
372
65c90f0 @hughsie Rename ZifCompletion to ZifState
authored
373 /* setup state */
b2e3181 @hughsie trivial: Use zif_state_set_steps() setting some guessed values to mak…
authored
374 if (md_filelists->priv->loaded) {
65c90f0 @hughsie Rename ZifCompletion to ZifState
authored
375 zif_state_set_number_steps (state, 1);
b2e3181 @hughsie trivial: Use zif_state_set_steps() setting some guessed values to mak…
authored
376 } else {
377 ret = zif_state_set_steps (state,
378 error,
379 80, /* load */
c9c089e @hughsie Fix the error handling when getting filelists from XML metadata
authored
380 20, /* get files */
b2e3181 @hughsie trivial: Use zif_state_set_steps() setting some guessed values to mak…
authored
381 -1);
382 if (!ret)
383 goto out;
384 }
fc63678 @hughsie Add the functionality to get the file lists for a remote package
authored
385
386 /* if not already loaded, load */
387 if (!md_filelists->priv->loaded) {
65c90f0 @hughsie Rename ZifCompletion to ZifState
authored
388 state_local = zif_state_get_child (state);
45b3b5f @hughsie Smush a GCancellable into #ZifState to reduce the number of args in l…
authored
389 ret = zif_md_load (ZIF_MD (md), state_local, &error_local);
fc63678 @hughsie Add the functionality to get the file lists for a remote package
authored
390 if (!ret) {
c9c089e @hughsie Fix the error handling when getting filelists from XML metadata
authored
391 g_set_error (error,
392 ZIF_MD_ERROR,
393 ZIF_MD_ERROR_FAILED_TO_LOAD,
394 "failed to load md_filelists_xml file: %s",
395 error_local->message);
fc63678 @hughsie Add the functionality to get the file lists for a remote package
authored
396 g_error_free (error_local);
397 goto out;
398 }
399
400 /* this section done */
d897d9c @hughsie Check for cancel in many, many more places
authored
401 ret = zif_state_done (state, error);
402 if (!ret)
403 goto out;
fc63678 @hughsie Add the functionality to get the file lists for a remote package
authored
404 }
405
406 /* search array */
8b93a5d @hughsie Move the pkgid state from ZifPackageRemote to ZifPackage as a local p…
authored
407 pkgid = zif_package_get_pkgid (package);
fc63678 @hughsie Add the functionality to get the file lists for a remote package
authored
408 packages = md_filelists->priv->array;
409 for (i=0; i<packages->len; i++) {
410 package_tmp = g_ptr_array_index (packages, i);
8b93a5d @hughsie Move the pkgid state from ZifPackageRemote to ZifPackage as a local p…
authored
411 pkgid_tmp = zif_package_get_pkgid (package_tmp);
fc63678 @hughsie Add the functionality to get the file lists for a remote package
authored
412 if (g_strcmp0 (pkgid, pkgid_tmp) == 0) {
c9c089e @hughsie Fix the error handling when getting filelists from XML metadata
authored
413 package_found = package_tmp;
fc63678 @hughsie Add the functionality to get the file lists for a remote package
authored
414 break;
415 }
c9c089e @hughsie Fix the error handling when getting filelists from XML metadata
authored
416 }
8a8aed4 @hughsie Use completion and cancellation for actions that can block for some time
authored
417
c9c089e @hughsie Fix the error handling when getting filelists from XML metadata
authored
418 /* nothing found */
419 if (package_found == NULL) {
420 g_set_error (error,
421 ZIF_MD_ERROR,
422 ZIF_MD_ERROR_FAILED,
423 "failed to find package %s",
424 pkgid);
425 goto out;
fc63678 @hughsie Add the functionality to get the file lists for a remote package
authored
426 }
427
c9c089e @hughsie Fix the error handling when getting filelists from XML metadata
authored
428 /* get files */
429 state_local = zif_state_get_child (state);
430 array = zif_package_get_files (package_found,
431 state_local,
432 error);
433 if (array == NULL)
434 goto out;
435
fc63678 @hughsie Add the functionality to get the file lists for a remote package
authored
436 /* this section done */
d897d9c @hughsie Check for cancel in many, many more places
authored
437 ret = zif_state_done (state, error);
438 if (!ret)
439 goto out;
c9c089e @hughsie Fix the error handling when getting filelists from XML metadata
authored
440
fc63678 @hughsie Add the functionality to get the file lists for a remote package
authored
441 out:
442 return array;
443 }
444
445 /**
9673756 @hughsie Add ZifMdFilelistsXml so we can read filelists from rpmfusion-free
authored
446 * zif_md_filelists_xml_search_file:
447 **/
448 static GPtrArray *
449 zif_md_filelists_xml_search_file (ZifMd *md, gchar **search,
45b3b5f @hughsie Smush a GCancellable into #ZifState to reduce the number of args in l…
authored
450 ZifState *state, GError **error)
9673756 @hughsie Add ZifMdFilelistsXml so we can read filelists from rpmfusion-free
authored
451 {
452 GPtrArray *array = NULL;
453 GPtrArray *packages;
454 ZifPackage *package;
455 GPtrArray *files = NULL;
456 const gchar *filename;
457 guint i, j, k;
458 gboolean ret;
459 const gchar *pkgid;
460 GError *error_local = NULL;
65c90f0 @hughsie Rename ZifCompletion to ZifState
authored
461 ZifState *state_local;
462 ZifState *state_loop;
9673756 @hughsie Add ZifMdFilelistsXml so we can read filelists from rpmfusion-free
authored
463 ZifMdFilelistsXml *md_filelists = ZIF_MD_FILELISTS_XML (md);
464
465 g_return_val_if_fail (ZIF_IS_MD_FILELISTS_XML (md), NULL);
971563d @hughsie Add zif_state_valid() and get a lot more strict for ZifState problems
authored
466 g_return_val_if_fail (zif_state_valid (state), NULL);
9673756 @hughsie Add ZifMdFilelistsXml so we can read filelists from rpmfusion-free
authored
467 g_return_val_if_fail (error == NULL || *error == NULL, NULL);
468
65c90f0 @hughsie Rename ZifCompletion to ZifState
authored
469 /* setup state */
b2e3181 @hughsie trivial: Use zif_state_set_steps() setting some guessed values to mak…
authored
470 if (md_filelists->priv->loaded) {
65c90f0 @hughsie Rename ZifCompletion to ZifState
authored
471 zif_state_set_number_steps (state, 1);
b2e3181 @hughsie trivial: Use zif_state_set_steps() setting some guessed values to mak…
authored
472 } else {
473 ret = zif_state_set_steps (state,
474 error,
475 80, /* load */
476 20, /* search */
477 -1);
478 if (!ret)
479 goto out;
480 }
9673756 @hughsie Add ZifMdFilelistsXml so we can read filelists from rpmfusion-free
authored
481
482 /* if not already loaded, load */
483 if (!md_filelists->priv->loaded) {
65c90f0 @hughsie Rename ZifCompletion to ZifState
authored
484 state_local = zif_state_get_child (state);
45b3b5f @hughsie Smush a GCancellable into #ZifState to reduce the number of args in l…
authored
485 ret = zif_md_load (ZIF_MD (md), state_local, &error_local);
9673756 @hughsie Add ZifMdFilelistsXml so we can read filelists from rpmfusion-free
authored
486 if (!ret) {
487 g_set_error (error, ZIF_MD_ERROR, ZIF_MD_ERROR_FAILED_TO_LOAD,
488 "failed to load md_filelists_xml file: %s", error_local->message);
489 g_error_free (error_local);
490 goto out;
491 }
492
493 /* this section done */
d897d9c @hughsie Check for cancel in many, many more places
authored
494 ret = zif_state_done (state, error);
495 if (!ret)
496 goto out;
9673756 @hughsie Add ZifMdFilelistsXml so we can read filelists from rpmfusion-free
authored
497 }
498
b2c0b12 @hughsie trivial: fix up two runtime critical warnings
authored
499 /* create results array */
500 array = g_ptr_array_new_with_free_func (g_free);
501
502 /* no entries, so shortcut */
503 if (md_filelists->priv->array->len == 0) {
d897d9c @hughsie Check for cancel in many, many more places
authored
504 ret = zif_state_done (state, error);
505 if (!ret)
506 goto out;
b2c0b12 @hughsie trivial: fix up two runtime critical warnings
authored
507 goto out;
508 }
509
8a8aed4 @hughsie Use completion and cancellation for actions that can block for some time
authored
510 /* setup steps */
65c90f0 @hughsie Rename ZifCompletion to ZifState
authored
511 state_local = zif_state_get_child (state);
512 zif_state_set_number_steps (state_local, md_filelists->priv->array->len);
8a8aed4 @hughsie Use completion and cancellation for actions that can block for some time
authored
513
9673756 @hughsie Add ZifMdFilelistsXml so we can read filelists from rpmfusion-free
authored
514 /* search array */
515 packages = md_filelists->priv->array;
516 for (i=0; i<packages->len; i++) {
517 package = g_ptr_array_index (packages, i);
8b93a5d @hughsie Move the pkgid state from ZifPackageRemote to ZifPackage as a local p…
authored
518 pkgid = zif_package_get_pkgid (package);
65c90f0 @hughsie Rename ZifCompletion to ZifState
authored
519 state_loop = zif_state_get_child (state_local);
45b3b5f @hughsie Smush a GCancellable into #ZifState to reduce the number of args in l…
authored
520 files = zif_package_get_files (package, state_loop, NULL);
9673756 @hughsie Add ZifMdFilelistsXml so we can read filelists from rpmfusion-free
authored
521 for (k=0; k<files->len; k++) {
522 filename = g_ptr_array_index (files, k);
523 for (j=0; search[j] != NULL; j++) {
524 if (g_strcmp0 (filename, search[j]) == 0) {
525 g_ptr_array_add (array, g_strdup (pkgid));
526 break;
527 }
528 }
529 }
8a8aed4 @hughsie Use completion and cancellation for actions that can block for some time
authored
530
531 /* this section done */
d897d9c @hughsie Check for cancel in many, many more places
authored
532 ret = zif_state_done (state_local, error);
533 if (!ret)
534 goto out;
9673756 @hughsie Add ZifMdFilelistsXml so we can read filelists from rpmfusion-free
authored
535 }
536
537 /* this section done */
d897d9c @hughsie Check for cancel in many, many more places
authored
538 ret = zif_state_done (state, error);
539 if (!ret)
540 goto out;
9673756 @hughsie Add ZifMdFilelistsXml so we can read filelists from rpmfusion-free
authored
541 out:
542 if (files != NULL)
543 g_ptr_array_unref (files);
544 return array;
545 }
546
547 /**
548 * zif_md_filelists_xml_finalize:
549 **/
550 static void
551 zif_md_filelists_xml_finalize (GObject *object)
552 {
553 ZifMdFilelistsXml *md;
554
555 g_return_if_fail (object != NULL);
556 g_return_if_fail (ZIF_IS_MD_FILELISTS_XML (object));
557 md = ZIF_MD_FILELISTS_XML (object);
558
559 g_ptr_array_unref (md->priv->array);
6817d97 @hughsie Set the correct version compare mode for new packages
authored
560 g_object_unref (md->priv->config);
9673756 @hughsie Add ZifMdFilelistsXml so we can read filelists from rpmfusion-free
authored
561
562 G_OBJECT_CLASS (zif_md_filelists_xml_parent_class)->finalize (object);
563 }
564
565 /**
566 * zif_md_filelists_xml_class_init:
567 **/
568 static void
569 zif_md_filelists_xml_class_init (ZifMdFilelistsXmlClass *klass)
570 {
571 GObjectClass *object_class = G_OBJECT_CLASS (klass);
572 ZifMdClass *md_class = ZIF_MD_CLASS (klass);
573 object_class->finalize = zif_md_filelists_xml_finalize;
574
575 /* map */
576 md_class->load = zif_md_filelists_xml_load;
577 md_class->unload = zif_md_filelists_xml_unload;
578 md_class->search_file = zif_md_filelists_xml_search_file;
fc63678 @hughsie Add the functionality to get the file lists for a remote package
authored
579 md_class->get_files = zif_md_filelists_xml_get_files;
9673756 @hughsie Add ZifMdFilelistsXml so we can read filelists from rpmfusion-free
authored
580
581 g_type_class_add_private (klass, sizeof (ZifMdFilelistsXmlPrivate));
582 }
583
584 /**
585 * zif_md_filelists_xml_init:
586 **/
587 static void
588 zif_md_filelists_xml_init (ZifMdFilelistsXml *md)
589 {
590 md->priv = ZIF_MD_FILELISTS_XML_GET_PRIVATE (md);
591 md->priv->array = g_ptr_array_new_with_free_func ((GDestroyNotify) g_object_unref);
592 md->priv->loaded = FALSE;
593 md->priv->section = ZIF_MD_FILELISTS_XML_SECTION_UNKNOWN;
594 md->priv->section_list = ZIF_MD_FILELISTS_XML_SECTION_LIST_UNKNOWN;
595 md->priv->section_list_package = ZIF_MD_FILELISTS_XML_SECTION_LIST_PACKAGE_UNKNOWN;
596 md->priv->package_temp = NULL;
597 md->priv->array_temp = NULL;
6817d97 @hughsie Set the correct version compare mode for new packages
authored
598 md->priv->config = zif_config_new ();
9673756 @hughsie Add ZifMdFilelistsXml so we can read filelists from rpmfusion-free
authored
599 }
600
601 /**
602 * zif_md_filelists_xml_new:
603 *
e2a86f0 @hughsie Improve a truckload of gtk-doc comments
authored
604 * Return value: A new #ZifMdFilelistsXml instance.
9673756 @hughsie Add ZifMdFilelistsXml so we can read filelists from rpmfusion-free
authored
605 *
61330b1 @hughsie Bump version ready for release
authored
606 * Since: 0.1.0
9673756 @hughsie Add ZifMdFilelistsXml so we can read filelists from rpmfusion-free
authored
607 **/
e93e43a @hughsie trivial: return a base type from the ZifMd new functions
authored
608 ZifMd *
9673756 @hughsie Add ZifMdFilelistsXml so we can read filelists from rpmfusion-free
authored
609 zif_md_filelists_xml_new (void)
610 {
611 ZifMdFilelistsXml *md;
411fb3a @hughsie Remove zif_md_set_mdtype() as the kind should only be set at object c…
authored
612 md = g_object_new (ZIF_TYPE_MD_FILELISTS_XML,
712892a @hughsie Rename ZifMdType to ZifMdKind to avoid name conflicts
authored
613 "kind", ZIF_MD_KIND_FILELISTS_XML,
411fb3a @hughsie Remove zif_md_set_mdtype() as the kind should only be set at object c…
authored
614 NULL);
e93e43a @hughsie trivial: return a base type from the ZifMd new functions
authored
615 return ZIF_MD (md);
9673756 @hughsie Add ZifMdFilelistsXml so we can read filelists from rpmfusion-free
authored
616 }
617
Something went wrong with that request. Please try again.