Skip to content
Newer
Older
100644 565 lines (485 sloc) 15.6 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
24 * @short_description: FilelistsXml metadata functionality
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
55 #include "zif-md.h"
56 #include "zif-md-filelists-xml.h"
fc63678 @hughsie Add the functionality to get the file lists for a remote package
authored
57 #include "zif-package-remote.h"
9673756 @hughsie Add ZifMdFilelistsXml so we can read filelists from rpmfusion-free
authored
58
59 #define ZIF_MD_FILELISTS_XML_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), ZIF_TYPE_MD_FILELISTS_XML, ZifMdFilelistsXmlPrivate))
60
61 /**
62 * ZifMdFilelistsXmlPrivate:
63 *
64 * Private #ZifMdFilelistsXml data
65 **/
66 struct _ZifMdFilelistsXmlPrivate
67 {
68 gboolean loaded;
69 ZifMdFilelistsXmlSection section;
70 ZifMdFilelistsXmlSectionList section_list;
71 ZifMdFilelistsXmlSectionListPackage section_list_package;
72 ZifPackage *package_temp;
73 GPtrArray *array;
74 GPtrArray *array_temp;
75 };
76
77 G_DEFINE_TYPE (ZifMdFilelistsXml, zif_md_filelists_xml, ZIF_TYPE_MD)
78
79 /**
80 * zif_md_filelists_xml_unload:
81 **/
82 static gboolean
45b3b5f @hughsie Smush a GCancellable into #ZifState to reduce the number of args in l…
authored
83 zif_md_filelists_xml_unload (ZifMd *md, ZifState *state, GError **error)
9673756 @hughsie Add ZifMdFilelistsXml so we can read filelists from rpmfusion-free
authored
84 {
85 gboolean ret = FALSE;
86 return ret;
87 }
88
89 /**
90 * zif_md_filelists_xml_parser_start_element:
91 **/
92 static void
93 zif_md_filelists_xml_parser_start_element (GMarkupParseContext *context, const gchar *element_name,
94 const gchar **attribute_names, const gchar **attribute_values,
95 gpointer user_data, GError **error)
96 {
97 guint i;
98 ZifMdFilelistsXml *filelists_xml = user_data;
99
100 g_return_if_fail (ZIF_IS_MD_FILELISTS_XML (filelists_xml));
101
102 /* group element */
103 if (filelists_xml->priv->section == ZIF_MD_FILELISTS_XML_SECTION_UNKNOWN) {
104
105 /* start of update */
106 if (g_strcmp0 (element_name, "filelists") == 0) {
107 filelists_xml->priv->section = ZIF_MD_FILELISTS_XML_SECTION_LIST;
108 goto out;
109 }
110
5ad0ab4 @hughsie Remove EggDebug and use the GLib logging system
authored
111 g_warning ("unhandled element: %s", element_name);
9673756 @hughsie Add ZifMdFilelistsXml so we can read filelists from rpmfusion-free
authored
112 goto out;
113 }
114
115 /* update element */
116 if (filelists_xml->priv->section == ZIF_MD_FILELISTS_XML_SECTION_LIST) {
117
118 if (filelists_xml->priv->section_list == ZIF_MD_FILELISTS_XML_SECTION_LIST_UNKNOWN) {
119
120 if (g_strcmp0 (element_name, "package") == 0) {
121 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
122 filelists_xml->priv->package_temp = ZIF_PACKAGE (zif_package_remote_new ());
9673756 @hughsie Add ZifMdFilelistsXml so we can read filelists from rpmfusion-free
authored
123 filelists_xml->priv->array_temp = g_ptr_array_new_with_free_func (g_free);
124 for (i=0; attribute_names[i] != NULL; i++) {
125 if (g_strcmp0 (attribute_names[i], "pkgid") == 0) {
fc63678 @hughsie Add the functionality to get the file lists for a remote package
authored
126 zif_package_remote_set_pkgid (ZIF_PACKAGE_REMOTE (filelists_xml->priv->package_temp),
127 attribute_values[i]);
9673756 @hughsie Add ZifMdFilelistsXml so we can read filelists from rpmfusion-free
authored
128 }
129 }
130 goto out;
131 }
132
5ad0ab4 @hughsie Remove EggDebug and use the GLib logging system
authored
133 g_warning ("unhandled update list tag: %s", element_name);
9673756 @hughsie Add ZifMdFilelistsXml so we can read filelists from rpmfusion-free
authored
134 goto out;
135
136 }
137 if (filelists_xml->priv->section_list == ZIF_MD_FILELISTS_XML_SECTION_LIST_PACKAGE) {
138
139 if (g_strcmp0 (element_name, "version") == 0) {
140 filelists_xml->priv->section_list_package = ZIF_MD_FILELISTS_XML_SECTION_LIST_UNKNOWN;
141 goto out;
142 }
143
144 if (g_strcmp0 (element_name, "file") == 0) {
145 filelists_xml->priv->section_list_package = ZIF_MD_FILELISTS_XML_SECTION_LIST_PACKAGE_FILE;
146 goto out;
147 }
5ad0ab4 @hughsie Remove EggDebug and use the GLib logging system
authored
148 g_warning ("unhandled update package tag: %s", element_name);
9673756 @hughsie Add ZifMdFilelistsXml so we can read filelists from rpmfusion-free
authored
149 goto out;
150 }
5ad0ab4 @hughsie Remove EggDebug and use the GLib logging system
authored
151 g_warning ("unhandled package tag: %s", element_name);
9673756 @hughsie Add ZifMdFilelistsXml so we can read filelists from rpmfusion-free
authored
152 }
153
5ad0ab4 @hughsie Remove EggDebug and use the GLib logging system
authored
154 g_warning ("unhandled base tag: %s", element_name);
9673756 @hughsie Add ZifMdFilelistsXml so we can read filelists from rpmfusion-free
authored
155
156 out:
157 return;
158 }
159
160 /**
161 * zif_md_filelists_xml_parser_end_element:
162 **/
163 static void
164 zif_md_filelists_xml_parser_end_element (GMarkupParseContext *context, const gchar *element_name,
165 gpointer user_data, GError **error)
166 {
167 ZifMdFilelistsXml *filelists_xml = user_data;
168
169 /* no element */
170 if (filelists_xml->priv->section == ZIF_MD_FILELISTS_XML_SECTION_UNKNOWN) {
5ad0ab4 @hughsie Remove EggDebug and use the GLib logging system
authored
171 g_warning ("unhandled base end tag: %s", element_name);
9673756 @hughsie Add ZifMdFilelistsXml so we can read filelists from rpmfusion-free
authored
172 goto out;
173 }
174
175 /* update element */
176 if (filelists_xml->priv->section == ZIF_MD_FILELISTS_XML_SECTION_LIST) {
177
178 /* update element */
179 if (filelists_xml->priv->section_list == ZIF_MD_FILELISTS_XML_SECTION_LIST_UNKNOWN) {
180
181 /* end of list */
182 if (g_strcmp0 (element_name, "filelists") == 0) {
183 filelists_xml->priv->section = ZIF_MD_FILELISTS_XML_SECTION_UNKNOWN;
184 goto out;
185 }
5ad0ab4 @hughsie Remove EggDebug and use the GLib logging system
authored
186 g_warning ("unhandled outside tag: %s", element_name);
9673756 @hughsie Add ZifMdFilelistsXml so we can read filelists from rpmfusion-free
authored
187 goto out;
188 }
189
190 /* update element */
191 if (filelists_xml->priv->section_list == ZIF_MD_FILELISTS_XML_SECTION_LIST_PACKAGE) {
192
193 if (filelists_xml->priv->section_list_package == ZIF_MD_FILELISTS_XML_SECTION_LIST_PACKAGE_UNKNOWN) {
194
195 if (g_strcmp0 (element_name, "version") == 0)
196 goto out;
197
198 /* end of list */
199 if (g_strcmp0 (element_name, "package") == 0) {
200 zif_package_set_files (filelists_xml->priv->package_temp, filelists_xml->priv->array_temp);
201 g_ptr_array_add (filelists_xml->priv->array, filelists_xml->priv->package_temp);
202 filelists_xml->priv->package_temp = NULL;
203 filelists_xml->priv->array_temp = NULL;
204 filelists_xml->priv->section_list = ZIF_MD_FILELISTS_XML_SECTION_LIST_UNKNOWN;
205 goto out;
206 }
5ad0ab4 @hughsie Remove EggDebug and use the GLib logging system
authored
207 g_warning ("unhandled package tag: %s", element_name);
9673756 @hughsie Add ZifMdFilelistsXml so we can read filelists from rpmfusion-free
authored
208 goto out;
209 }
210
211 if (filelists_xml->priv->section_list_package == ZIF_MD_FILELISTS_XML_SECTION_LIST_PACKAGE_FILE) {
212 if (g_strcmp0 (element_name, "file") == 0) {
213 filelists_xml->priv->section_list_package = ZIF_MD_FILELISTS_XML_SECTION_LIST_PACKAGE_UNKNOWN;
214 goto out;
215 }
5ad0ab4 @hughsie Remove EggDebug and use the GLib logging system
authored
216 g_warning ("unhandled end of file tag: %s", element_name);
9673756 @hughsie Add ZifMdFilelistsXml so we can read filelists from rpmfusion-free
authored
217 goto out;
218 }
5ad0ab4 @hughsie Remove EggDebug and use the GLib logging system
authored
219 g_warning ("unhandled end of package tag: %s", element_name);
9673756 @hughsie Add ZifMdFilelistsXml so we can read filelists from rpmfusion-free
authored
220 goto out;
221 }
222
5ad0ab4 @hughsie Remove EggDebug and use the GLib logging system
authored
223 g_warning ("unhandled update end tag: %s", element_name);
9673756 @hughsie Add ZifMdFilelistsXml so we can read filelists from rpmfusion-free
authored
224 goto out;
225 }
226
5ad0ab4 @hughsie Remove EggDebug and use the GLib logging system
authored
227 g_warning ("unhandled end tag: %s", element_name);
9673756 @hughsie Add ZifMdFilelistsXml so we can read filelists from rpmfusion-free
authored
228 out:
229 return;
230 }
231
232 /**
233 * zif_md_filelists_xml_parser_text:
234 **/
235 static void
236 zif_md_filelists_xml_parser_text (GMarkupParseContext *context, const gchar *text, gsize text_len,
237 gpointer user_data, GError **error)
238
239 {
240 ZifMdFilelistsXml *filelists_xml = user_data;
241
242 /* skip whitespace */
243 if (text_len < 1 || text[0] == ' ' || text[0] == '\t' || text[0] == '\n')
244 goto out;
245
246 /* group section */
247 if (filelists_xml->priv->section == ZIF_MD_FILELISTS_XML_SECTION_LIST) {
248 if (filelists_xml->priv->section_list == ZIF_MD_FILELISTS_XML_SECTION_LIST_UNKNOWN) {
5ad0ab4 @hughsie Remove EggDebug and use the GLib logging system
authored
249 g_warning ("not saving: %s", text);
9673756 @hughsie Add ZifMdFilelistsXml so we can read filelists from rpmfusion-free
authored
250 goto out;
251 }
252 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
253 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
254 g_ptr_array_add (filelists_xml->priv->array_temp, g_strdup (text));
255 goto out;
256 };
5ad0ab4 @hughsie Remove EggDebug and use the GLib logging system
authored
257 g_warning ("not saving: %s", text);
9673756 @hughsie Add ZifMdFilelistsXml so we can read filelists from rpmfusion-free
authored
258 goto out;
259 }
5ad0ab4 @hughsie Remove EggDebug and use the GLib logging system
authored
260 g_warning ("not saving: %s", text);
9673756 @hughsie Add ZifMdFilelistsXml so we can read filelists from rpmfusion-free
authored
261 goto out;
262 }
263 out:
264 return;
265 }
266
267 /**
268 * zif_md_filelists_xml_load:
269 **/
270 static gboolean
45b3b5f @hughsie Smush a GCancellable into #ZifState to reduce the number of args in l…
authored
271 zif_md_filelists_xml_load (ZifMd *md, ZifState *state, GError **error)
9673756 @hughsie Add ZifMdFilelistsXml so we can read filelists from rpmfusion-free
authored
272 {
273 const gchar *filename;
274 gboolean ret;
275 gchar *contents = NULL;
276 gsize size;
277 ZifMdFilelistsXml *filelists_xml = ZIF_MD_FILELISTS_XML (md);
278 GMarkupParseContext *context = NULL;
279 const GMarkupParser gpk_md_filelists_xml_markup_parser = {
280 zif_md_filelists_xml_parser_start_element,
281 zif_md_filelists_xml_parser_end_element,
282 zif_md_filelists_xml_parser_text,
283 NULL, /* passthrough */
284 NULL /* error */
285 };
286
287 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
288 g_return_val_if_fail (zif_state_valid (state), FALSE);
9673756 @hughsie Add ZifMdFilelistsXml so we can read filelists from rpmfusion-free
authored
289
290 /* already loaded */
291 if (filelists_xml->priv->loaded)
292 goto out;
293
294 /* get filename */
295 filename = zif_md_get_filename_uncompressed (md);
296 if (filename == NULL) {
297 g_set_error_literal (error, ZIF_MD_ERROR, ZIF_MD_ERROR_FAILED,
298 "failed to get filename for filelists_xml");
299 goto out;
300 }
301
302 /* open database */
5ad0ab4 @hughsie Remove EggDebug and use the GLib logging system
authored
303 g_debug ("filename = %s", filename);
d897d9c @hughsie Check for cancel in many, many more places
authored
304 zif_state_set_allow_cancel (state, FALSE);
9673756 @hughsie Add ZifMdFilelistsXml so we can read filelists from rpmfusion-free
authored
305 ret = g_file_get_contents (filename, &contents, &size, error);
306 if (!ret)
307 goto out;
308
309 /* create parser */
310 context = g_markup_parse_context_new (&gpk_md_filelists_xml_markup_parser, G_MARKUP_PREFIX_ERROR_POSITION, filelists_xml, NULL);
311
312 /* parse data */
d897d9c @hughsie Check for cancel in many, many more places
authored
313 zif_state_set_allow_cancel (state, FALSE);
9673756 @hughsie Add ZifMdFilelistsXml so we can read filelists from rpmfusion-free
authored
314 ret = g_markup_parse_context_parse (context, contents, (gssize) size, error);
315 if (!ret)
316 goto out;
317
318 /* we don't need to keep syncing */
319 filelists_xml->priv->loaded = TRUE;
320 out:
0c2ee4f @hughsie Fix up some memory leaks spotted by valgrind
authored
321 if (context != NULL)
322 g_markup_parse_context_free (context);
9673756 @hughsie Add ZifMdFilelistsXml so we can read filelists from rpmfusion-free
authored
323 g_free (contents);
324 return filelists_xml->priv->loaded;
325 }
326
327 /**
fc63678 @hughsie Add the functionality to get the file lists for a remote package
authored
328 * zif_md_filelists_xml_get_files:
329 **/
330 static GPtrArray *
331 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
332 ZifState *state, GError **error)
fc63678 @hughsie Add the functionality to get the file lists for a remote package
authored
333 {
334 GPtrArray *array = NULL;
335 GPtrArray *packages;
336 ZifPackage *package_tmp;
337 guint i;
338 gboolean ret;
339 const gchar *pkgid;
340 const gchar *pkgid_tmp;
341 GError *error_local = NULL;
65c90f0 @hughsie Rename ZifCompletion to ZifState
authored
342 ZifState *state_local;
343 ZifState *state_loop;
fc63678 @hughsie Add the functionality to get the file lists for a remote package
authored
344 ZifMdFilelistsXml *md_filelists = ZIF_MD_FILELISTS_XML (md);
345
346 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
347 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
348 g_return_val_if_fail (error == NULL || *error == NULL, NULL);
349
65c90f0 @hughsie Rename ZifCompletion to ZifState
authored
350 /* setup state */
fc63678 @hughsie Add the functionality to get the file lists for a remote package
authored
351 if (md_filelists->priv->loaded)
65c90f0 @hughsie Rename ZifCompletion to ZifState
authored
352 zif_state_set_number_steps (state, 1);
fc63678 @hughsie Add the functionality to get the file lists for a remote package
authored
353 else
65c90f0 @hughsie Rename ZifCompletion to ZifState
authored
354 zif_state_set_number_steps (state, 2);
fc63678 @hughsie Add the functionality to get the file lists for a remote package
authored
355
356 /* if not already loaded, load */
357 if (!md_filelists->priv->loaded) {
65c90f0 @hughsie Rename ZifCompletion to ZifState
authored
358 state_local = zif_state_get_child (state);
45b3b5f @hughsie Smush a GCancellable into #ZifState to reduce the number of args in l…
authored
359 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
360 if (!ret) {
361 g_set_error (error, ZIF_MD_ERROR, ZIF_MD_ERROR_FAILED_TO_LOAD,
362 "failed to load md_filelists_xml file: %s", error_local->message);
363 g_error_free (error_local);
364 goto out;
365 }
366
367 /* this section done */
d897d9c @hughsie Check for cancel in many, many more places
authored
368 ret = zif_state_done (state, error);
369 if (!ret)
370 goto out;
fc63678 @hughsie Add the functionality to get the file lists for a remote package
authored
371 }
372
8a8aed4 @hughsie Use completion and cancellation for actions that can block for some time
authored
373 /* setup steps */
65c90f0 @hughsie Rename ZifCompletion to ZifState
authored
374 state_local = zif_state_get_child (state);
375 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
376
fc63678 @hughsie Add the functionality to get the file lists for a remote package
authored
377 /* search array */
378 pkgid = zif_package_remote_get_pkgid (ZIF_PACKAGE_REMOTE (package));
379 packages = md_filelists->priv->array;
380 for (i=0; i<packages->len; i++) {
381 package_tmp = g_ptr_array_index (packages, i);
382 pkgid_tmp = zif_package_remote_get_pkgid (ZIF_PACKAGE_REMOTE (package_tmp));
383 if (g_strcmp0 (pkgid, pkgid_tmp) == 0) {
65c90f0 @hughsie Rename ZifCompletion to ZifState
authored
384 state_loop = zif_state_get_child (state_local);
45b3b5f @hughsie Smush a GCancellable into #ZifState to reduce the number of args in l…
authored
385 array = zif_package_get_files (package_tmp, state_loop, NULL);
fc63678 @hughsie Add the functionality to get the file lists for a remote package
authored
386 break;
387 }
8a8aed4 @hughsie Use completion and cancellation for actions that can block for some time
authored
388
389 /* this section done */
d897d9c @hughsie Check for cancel in many, many more places
authored
390 ret = zif_state_done (state_local, error);
391 if (!ret)
392 goto out;
fc63678 @hughsie Add the functionality to get the file lists for a remote package
authored
393 }
394
395 /* this section done */
d897d9c @hughsie Check for cancel in many, many more places
authored
396 ret = zif_state_done (state, error);
397 if (!ret)
398 goto out;
fc63678 @hughsie Add the functionality to get the file lists for a remote package
authored
399 out:
400 return array;
401 }
402
403 /**
9673756 @hughsie Add ZifMdFilelistsXml so we can read filelists from rpmfusion-free
authored
404 * zif_md_filelists_xml_search_file:
405 **/
406 static GPtrArray *
407 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
408 ZifState *state, GError **error)
9673756 @hughsie Add ZifMdFilelistsXml so we can read filelists from rpmfusion-free
authored
409 {
410 GPtrArray *array = NULL;
411 GPtrArray *packages;
412 ZifPackage *package;
413 GPtrArray *files = NULL;
414 const gchar *filename;
415 guint i, j, k;
416 gboolean ret;
417 const gchar *pkgid;
418 GError *error_local = NULL;
65c90f0 @hughsie Rename ZifCompletion to ZifState
authored
419 ZifState *state_local;
420 ZifState *state_loop;
9673756 @hughsie Add ZifMdFilelistsXml so we can read filelists from rpmfusion-free
authored
421 ZifMdFilelistsXml *md_filelists = ZIF_MD_FILELISTS_XML (md);
422
423 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
424 g_return_val_if_fail (zif_state_valid (state), NULL);
9673756 @hughsie Add ZifMdFilelistsXml so we can read filelists from rpmfusion-free
authored
425 g_return_val_if_fail (error == NULL || *error == NULL, NULL);
426
65c90f0 @hughsie Rename ZifCompletion to ZifState
authored
427 /* setup state */
9673756 @hughsie Add ZifMdFilelistsXml so we can read filelists from rpmfusion-free
authored
428 if (md_filelists->priv->loaded)
65c90f0 @hughsie Rename ZifCompletion to ZifState
authored
429 zif_state_set_number_steps (state, 1);
9673756 @hughsie Add ZifMdFilelistsXml so we can read filelists from rpmfusion-free
authored
430 else
65c90f0 @hughsie Rename ZifCompletion to ZifState
authored
431 zif_state_set_number_steps (state, 2);
9673756 @hughsie Add ZifMdFilelistsXml so we can read filelists from rpmfusion-free
authored
432
433 /* if not already loaded, load */
434 if (!md_filelists->priv->loaded) {
65c90f0 @hughsie Rename ZifCompletion to ZifState
authored
435 state_local = zif_state_get_child (state);
45b3b5f @hughsie Smush a GCancellable into #ZifState to reduce the number of args in l…
authored
436 ret = zif_md_load (ZIF_MD (md), state_local, &error_local);
9673756 @hughsie Add ZifMdFilelistsXml so we can read filelists from rpmfusion-free
authored
437 if (!ret) {
438 g_set_error (error, ZIF_MD_ERROR, ZIF_MD_ERROR_FAILED_TO_LOAD,
439 "failed to load md_filelists_xml file: %s", error_local->message);
440 g_error_free (error_local);
441 goto out;
442 }
443
444 /* this section done */
d897d9c @hughsie Check for cancel in many, many more places
authored
445 ret = zif_state_done (state, error);
446 if (!ret)
447 goto out;
9673756 @hughsie Add ZifMdFilelistsXml so we can read filelists from rpmfusion-free
authored
448 }
449
b2c0b12 @hughsie trivial: fix up two runtime critical warnings
authored
450 /* create results array */
451 array = g_ptr_array_new_with_free_func (g_free);
452
453 /* no entries, so shortcut */
454 if (md_filelists->priv->array->len == 0) {
d897d9c @hughsie Check for cancel in many, many more places
authored
455 ret = zif_state_done (state, error);
456 if (!ret)
457 goto out;
b2c0b12 @hughsie trivial: fix up two runtime critical warnings
authored
458 goto out;
459 }
460
8a8aed4 @hughsie Use completion and cancellation for actions that can block for some time
authored
461 /* setup steps */
65c90f0 @hughsie Rename ZifCompletion to ZifState
authored
462 state_local = zif_state_get_child (state);
463 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
464
9673756 @hughsie Add ZifMdFilelistsXml so we can read filelists from rpmfusion-free
authored
465 /* search array */
466 packages = md_filelists->priv->array;
467 for (i=0; i<packages->len; i++) {
468 package = g_ptr_array_index (packages, i);
8a8aed4 @hughsie Use completion and cancellation for actions that can block for some time
authored
469 pkgid = zif_package_remote_get_pkgid (ZIF_PACKAGE_REMOTE (package));
65c90f0 @hughsie Rename ZifCompletion to ZifState
authored
470 state_loop = zif_state_get_child (state_local);
45b3b5f @hughsie Smush a GCancellable into #ZifState to reduce the number of args in l…
authored
471 files = zif_package_get_files (package, state_loop, NULL);
9673756 @hughsie Add ZifMdFilelistsXml so we can read filelists from rpmfusion-free
authored
472 for (k=0; k<files->len; k++) {
473 filename = g_ptr_array_index (files, k);
474 for (j=0; search[j] != NULL; j++) {
475 if (g_strcmp0 (filename, search[j]) == 0) {
476 g_ptr_array_add (array, g_strdup (pkgid));
477 break;
478 }
479 }
480 }
8a8aed4 @hughsie Use completion and cancellation for actions that can block for some time
authored
481
482 /* this section done */
d897d9c @hughsie Check for cancel in many, many more places
authored
483 ret = zif_state_done (state_local, error);
484 if (!ret)
485 goto out;
9673756 @hughsie Add ZifMdFilelistsXml so we can read filelists from rpmfusion-free
authored
486 }
487
488 /* this section done */
d897d9c @hughsie Check for cancel in many, many more places
authored
489 ret = zif_state_done (state, error);
490 if (!ret)
491 goto out;
9673756 @hughsie Add ZifMdFilelistsXml so we can read filelists from rpmfusion-free
authored
492 out:
493 if (files != NULL)
494 g_ptr_array_unref (files);
495 return array;
496 }
497
498 /**
499 * zif_md_filelists_xml_finalize:
500 **/
501 static void
502 zif_md_filelists_xml_finalize (GObject *object)
503 {
504 ZifMdFilelistsXml *md;
505
506 g_return_if_fail (object != NULL);
507 g_return_if_fail (ZIF_IS_MD_FILELISTS_XML (object));
508 md = ZIF_MD_FILELISTS_XML (object);
509
510 g_ptr_array_unref (md->priv->array);
511
512 G_OBJECT_CLASS (zif_md_filelists_xml_parent_class)->finalize (object);
513 }
514
515 /**
516 * zif_md_filelists_xml_class_init:
517 **/
518 static void
519 zif_md_filelists_xml_class_init (ZifMdFilelistsXmlClass *klass)
520 {
521 GObjectClass *object_class = G_OBJECT_CLASS (klass);
522 ZifMdClass *md_class = ZIF_MD_CLASS (klass);
523 object_class->finalize = zif_md_filelists_xml_finalize;
524
525 /* map */
526 md_class->load = zif_md_filelists_xml_load;
527 md_class->unload = zif_md_filelists_xml_unload;
528 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
529 md_class->get_files = zif_md_filelists_xml_get_files;
9673756 @hughsie Add ZifMdFilelistsXml so we can read filelists from rpmfusion-free
authored
530
531 g_type_class_add_private (klass, sizeof (ZifMdFilelistsXmlPrivate));
532 }
533
534 /**
535 * zif_md_filelists_xml_init:
536 **/
537 static void
538 zif_md_filelists_xml_init (ZifMdFilelistsXml *md)
539 {
540 md->priv = ZIF_MD_FILELISTS_XML_GET_PRIVATE (md);
541 md->priv->array = g_ptr_array_new_with_free_func ((GDestroyNotify) g_object_unref);
542 md->priv->loaded = FALSE;
543 md->priv->section = ZIF_MD_FILELISTS_XML_SECTION_UNKNOWN;
544 md->priv->section_list = ZIF_MD_FILELISTS_XML_SECTION_LIST_UNKNOWN;
545 md->priv->section_list_package = ZIF_MD_FILELISTS_XML_SECTION_LIST_PACKAGE_UNKNOWN;
546 md->priv->package_temp = NULL;
547 md->priv->array_temp = NULL;
548 }
549
550 /**
551 * zif_md_filelists_xml_new:
552 *
553 * Return value: A new #ZifMdFilelistsXml class instance.
554 *
61330b1 @hughsie Bump version ready for release
authored
555 * Since: 0.1.0
9673756 @hughsie Add ZifMdFilelistsXml so we can read filelists from rpmfusion-free
authored
556 **/
557 ZifMdFilelistsXml *
558 zif_md_filelists_xml_new (void)
559 {
560 ZifMdFilelistsXml *md;
561 md = g_object_new (ZIF_TYPE_MD_FILELISTS_XML, NULL);
562 return ZIF_MD_FILELISTS_XML (md);
563 }
564
Something went wrong with that request. Please try again.