Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 692 lines (592 sloc) 19.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
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 #include "egg-debug.h"
60
61 #define ZIF_MD_FILELISTS_XML_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), ZIF_TYPE_MD_FILELISTS_XML, ZifMdFilelistsXmlPrivate))
62
63 /**
64 * ZifMdFilelistsXmlPrivate:
65 *
66 * Private #ZifMdFilelistsXml data
67 **/
68 struct _ZifMdFilelistsXmlPrivate
69 {
70 gboolean loaded;
71 ZifMdFilelistsXmlSection section;
72 ZifMdFilelistsXmlSectionList section_list;
73 ZifMdFilelistsXmlSectionListPackage section_list_package;
74 ZifPackage *package_temp;
75 GPtrArray *array;
76 GPtrArray *array_temp;
77 };
78
79 G_DEFINE_TYPE (ZifMdFilelistsXml, zif_md_filelists_xml, ZIF_TYPE_MD)
80
81 /**
82 * zif_md_filelists_xml_unload:
83 **/
84 static gboolean
45b3b5f @hughsie Smush a GCancellable into #ZifState to reduce the number of args in load...
authored
85 zif_md_filelists_xml_unload (ZifMd *md, ZifState *state, GError **error)
9673756 @hughsie Add ZifMdFilelistsXml so we can read filelists from rpmfusion-free
authored
86 {
87 gboolean ret = FALSE;
88 return ret;
89 }
90
91 /**
92 * zif_md_filelists_xml_parser_start_element:
93 **/
94 static void
95 zif_md_filelists_xml_parser_start_element (GMarkupParseContext *context, const gchar *element_name,
96 const gchar **attribute_names, const gchar **attribute_values,
97 gpointer user_data, GError **error)
98 {
99 guint i;
100 ZifMdFilelistsXml *filelists_xml = user_data;
101
102 g_return_if_fail (ZIF_IS_MD_FILELISTS_XML (filelists_xml));
103
104 /* group element */
105 if (filelists_xml->priv->section == ZIF_MD_FILELISTS_XML_SECTION_UNKNOWN) {
106
107 /* start of update */
108 if (g_strcmp0 (element_name, "filelists") == 0) {
109 filelists_xml->priv->section = ZIF_MD_FILELISTS_XML_SECTION_LIST;
110 goto out;
111 }
112
113 egg_warning ("unhandled element: %s", element_name);
114 goto out;
115 }
116
117 /* update element */
118 if (filelists_xml->priv->section == ZIF_MD_FILELISTS_XML_SECTION_LIST) {
119
120 if (filelists_xml->priv->section_list == ZIF_MD_FILELISTS_XML_SECTION_LIST_UNKNOWN) {
121
122 if (g_strcmp0 (element_name, "package") == 0) {
123 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
124 filelists_xml->priv->package_temp = ZIF_PACKAGE (zif_package_remote_new ());
9673756 @hughsie Add ZifMdFilelistsXml so we can read filelists from rpmfusion-free
authored
125 filelists_xml->priv->array_temp = g_ptr_array_new_with_free_func (g_free);
126 for (i=0; attribute_names[i] != NULL; i++) {
127 if (g_strcmp0 (attribute_names[i], "pkgid") == 0) {
fc63678 @hughsie Add the functionality to get the file lists for a remote package
authored
128 zif_package_remote_set_pkgid (ZIF_PACKAGE_REMOTE (filelists_xml->priv->package_temp),
129 attribute_values[i]);
9673756 @hughsie Add ZifMdFilelistsXml so we can read filelists from rpmfusion-free
authored
130 }
131 }
132 goto out;
133 }
134
135 egg_warning ("unhandled update list tag: %s", element_name);
136 goto out;
137
138 }
139 if (filelists_xml->priv->section_list == ZIF_MD_FILELISTS_XML_SECTION_LIST_PACKAGE) {
140
141 if (g_strcmp0 (element_name, "version") == 0) {
142 filelists_xml->priv->section_list_package = ZIF_MD_FILELISTS_XML_SECTION_LIST_UNKNOWN;
143 goto out;
144 }
145
146 if (g_strcmp0 (element_name, "file") == 0) {
147 filelists_xml->priv->section_list_package = ZIF_MD_FILELISTS_XML_SECTION_LIST_PACKAGE_FILE;
148 goto out;
149 }
150 egg_warning ("unhandled update package tag: %s", element_name);
151 goto out;
152 }
153 egg_warning ("unhandled package tag: %s", element_name);
154 }
155
156 egg_warning ("unhandled base tag: %s", element_name);
157
158 out:
159 return;
160 }
161
162 /**
163 * zif_md_filelists_xml_parser_end_element:
164 **/
165 static void
166 zif_md_filelists_xml_parser_end_element (GMarkupParseContext *context, const gchar *element_name,
167 gpointer user_data, GError **error)
168 {
169 ZifMdFilelistsXml *filelists_xml = user_data;
170
171 /* no element */
172 if (filelists_xml->priv->section == ZIF_MD_FILELISTS_XML_SECTION_UNKNOWN) {
173 egg_warning ("unhandled base end tag: %s", element_name);
174 goto out;
175 }
176
177 /* update element */
178 if (filelists_xml->priv->section == ZIF_MD_FILELISTS_XML_SECTION_LIST) {
179
180 /* update element */
181 if (filelists_xml->priv->section_list == ZIF_MD_FILELISTS_XML_SECTION_LIST_UNKNOWN) {
182
183 /* end of list */
184 if (g_strcmp0 (element_name, "filelists") == 0) {
185 filelists_xml->priv->section = ZIF_MD_FILELISTS_XML_SECTION_UNKNOWN;
186 goto out;
187 }
188 egg_warning ("unhandled outside tag: %s", element_name);
189 goto out;
190 }
191
192 /* update element */
193 if (filelists_xml->priv->section_list == ZIF_MD_FILELISTS_XML_SECTION_LIST_PACKAGE) {
194
195 if (filelists_xml->priv->section_list_package == ZIF_MD_FILELISTS_XML_SECTION_LIST_PACKAGE_UNKNOWN) {
196
197 if (g_strcmp0 (element_name, "version") == 0)
198 goto out;
199
200 /* end of list */
201 if (g_strcmp0 (element_name, "package") == 0) {
202 zif_package_set_files (filelists_xml->priv->package_temp, filelists_xml->priv->array_temp);
203 g_ptr_array_add (filelists_xml->priv->array, filelists_xml->priv->package_temp);
204 filelists_xml->priv->package_temp = NULL;
205 filelists_xml->priv->array_temp = NULL;
206 filelists_xml->priv->section_list = ZIF_MD_FILELISTS_XML_SECTION_LIST_UNKNOWN;
207 goto out;
208 }
209 egg_warning ("unhandled package tag: %s", element_name);
210 goto out;
211 }
212
213 if (filelists_xml->priv->section_list_package == ZIF_MD_FILELISTS_XML_SECTION_LIST_PACKAGE_FILE) {
214 if (g_strcmp0 (element_name, "file") == 0) {
215 filelists_xml->priv->section_list_package = ZIF_MD_FILELISTS_XML_SECTION_LIST_PACKAGE_UNKNOWN;
216 goto out;
217 }
218 egg_warning ("unhandled end of file tag: %s", element_name);
219 goto out;
220 }
221 egg_warning ("unhandled end of package tag: %s", element_name);
222 goto out;
223 }
224
225 egg_warning ("unhandled update end tag: %s", element_name);
226 goto out;
227 }
228
229 egg_warning ("unhandled end tag: %s", element_name);
230 out:
231 return;
232 }
233
234 /**
235 * zif_md_filelists_xml_parser_text:
236 **/
237 static void
238 zif_md_filelists_xml_parser_text (GMarkupParseContext *context, const gchar *text, gsize text_len,
239 gpointer user_data, GError **error)
240
241 {
242 ZifMdFilelistsXml *filelists_xml = user_data;
243
244 /* skip whitespace */
245 if (text_len < 1 || text[0] == ' ' || text[0] == '\t' || text[0] == '\n')
246 goto out;
247
248 /* group section */
249 if (filelists_xml->priv->section == ZIF_MD_FILELISTS_XML_SECTION_LIST) {
250 if (filelists_xml->priv->section_list == ZIF_MD_FILELISTS_XML_SECTION_LIST_UNKNOWN) {
251 egg_warning ("not saving: %s", text);
252 goto out;
253 }
254 if (filelists_xml->priv->section_list == ZIF_MD_FILELISTS_XML_SECTION_LIST_PACKAGE) {
255 if (filelists_xml->priv->section_list == ZIF_MD_FILELISTS_XML_SECTION_LIST_PACKAGE_FILE) {
256 g_ptr_array_add (filelists_xml->priv->array_temp, g_strdup (text));
257 goto out;
258 };
259 egg_warning ("not saving: %s", text);
260 goto out;
261 }
262 egg_warning ("not saving: %s", text);
263 goto out;
264 }
265 out:
266 return;
267 }
268
269 /**
270 * zif_md_filelists_xml_load:
271 **/
272 static gboolean
45b3b5f @hughsie Smush a GCancellable into #ZifState to reduce the number of args in load...
authored
273 zif_md_filelists_xml_load (ZifMd *md, ZifState *state, GError **error)
9673756 @hughsie Add ZifMdFilelistsXml so we can read filelists from rpmfusion-free
authored
274 {
275 const gchar *filename;
276 gboolean ret;
277 gchar *contents = NULL;
278 gsize size;
279 ZifMdFilelistsXml *filelists_xml = ZIF_MD_FILELISTS_XML (md);
280 GMarkupParseContext *context = NULL;
281 const GMarkupParser gpk_md_filelists_xml_markup_parser = {
282 zif_md_filelists_xml_parser_start_element,
283 zif_md_filelists_xml_parser_end_element,
284 zif_md_filelists_xml_parser_text,
285 NULL, /* passthrough */
286 NULL /* error */
287 };
288
289 g_return_val_if_fail (ZIF_IS_MD_FILELISTS_XML (md), FALSE);
290
291 /* already loaded */
292 if (filelists_xml->priv->loaded)
293 goto out;
294
295 /* get filename */
296 filename = zif_md_get_filename_uncompressed (md);
297 if (filename == NULL) {
298 g_set_error_literal (error, ZIF_MD_ERROR, ZIF_MD_ERROR_FAILED,
299 "failed to get filename for filelists_xml");
300 goto out;
301 }
302
303 /* open database */
304 egg_debug ("filename = %s", filename);
d897d9c @hughsie Check for cancel in many, many more places
authored
305 zif_state_set_allow_cancel (state, FALSE);
9673756 @hughsie Add ZifMdFilelistsXml so we can read filelists from rpmfusion-free
authored
306 ret = g_file_get_contents (filename, &contents, &size, error);
307 if (!ret)
308 goto out;
309
310 /* create parser */
311 context = g_markup_parse_context_new (&gpk_md_filelists_xml_markup_parser, G_MARKUP_PREFIX_ERROR_POSITION, filelists_xml, NULL);
312
313 /* parse data */
d897d9c @hughsie Check for cancel in many, many more places
authored
314 zif_state_set_allow_cancel (state, FALSE);
9673756 @hughsie Add ZifMdFilelistsXml so we can read filelists from rpmfusion-free
authored
315 ret = g_markup_parse_context_parse (context, contents, (gssize) size, error);
316 if (!ret)
317 goto out;
318
319 /* we don't need to keep syncing */
320 filelists_xml->priv->loaded = TRUE;
321 out:
322 g_free (contents);
323 return filelists_xml->priv->loaded;
324 }
325
326 /**
fc63678 @hughsie Add the functionality to get the file lists for a remote package
authored
327 * zif_md_filelists_xml_get_files:
328 **/
329 static GPtrArray *
330 zif_md_filelists_xml_get_files (ZifMd *md, ZifPackage *package,
45b3b5f @hughsie Smush a GCancellable into #ZifState to reduce the number of args in load...
authored
331 ZifState *state, GError **error)
fc63678 @hughsie Add the functionality to get the file lists for a remote package
authored
332 {
333 GPtrArray *array = NULL;
334 GPtrArray *packages;
335 ZifPackage *package_tmp;
336 guint i;
337 gboolean ret;
338 const gchar *pkgid;
339 const gchar *pkgid_tmp;
340 GError *error_local = NULL;
65c90f0 @hughsie Rename ZifCompletion to ZifState
authored
341 ZifState *state_local;
342 ZifState *state_loop;
fc63678 @hughsie Add the functionality to get the file lists for a remote package
authored
343 ZifMdFilelistsXml *md_filelists = ZIF_MD_FILELISTS_XML (md);
344
345 g_return_val_if_fail (ZIF_IS_MD_FILELISTS_XML (md), NULL);
346 g_return_val_if_fail (error == NULL || *error == NULL, NULL);
347
65c90f0 @hughsie Rename ZifCompletion to ZifState
authored
348 /* setup state */
fc63678 @hughsie Add the functionality to get the file lists for a remote package
authored
349 if (md_filelists->priv->loaded)
65c90f0 @hughsie Rename ZifCompletion to ZifState
authored
350 zif_state_set_number_steps (state, 1);
fc63678 @hughsie Add the functionality to get the file lists for a remote package
authored
351 else
65c90f0 @hughsie Rename ZifCompletion to ZifState
authored
352 zif_state_set_number_steps (state, 2);
fc63678 @hughsie Add the functionality to get the file lists for a remote package
authored
353
354 /* if not already loaded, load */
355 if (!md_filelists->priv->loaded) {
65c90f0 @hughsie Rename ZifCompletion to ZifState
authored
356 state_local = zif_state_get_child (state);
45b3b5f @hughsie Smush a GCancellable into #ZifState to reduce the number of args in load...
authored
357 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
358 if (!ret) {
359 g_set_error (error, ZIF_MD_ERROR, ZIF_MD_ERROR_FAILED_TO_LOAD,
360 "failed to load md_filelists_xml file: %s", error_local->message);
361 g_error_free (error_local);
362 goto out;
363 }
364
365 /* this section done */
d897d9c @hughsie Check for cancel in many, many more places
authored
366 ret = zif_state_done (state, error);
367 if (!ret)
368 goto out;
fc63678 @hughsie Add the functionality to get the file lists for a remote package
authored
369 }
370
8a8aed4 @hughsie Use completion and cancellation for actions that can block for some time
authored
371 /* setup steps */
65c90f0 @hughsie Rename ZifCompletion to ZifState
authored
372 state_local = zif_state_get_child (state);
373 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
374
fc63678 @hughsie Add the functionality to get the file lists for a remote package
authored
375 /* search array */
376 pkgid = zif_package_remote_get_pkgid (ZIF_PACKAGE_REMOTE (package));
377 packages = md_filelists->priv->array;
378 for (i=0; i<packages->len; i++) {
379 package_tmp = g_ptr_array_index (packages, i);
380 pkgid_tmp = zif_package_remote_get_pkgid (ZIF_PACKAGE_REMOTE (package_tmp));
381 if (g_strcmp0 (pkgid, pkgid_tmp) == 0) {
65c90f0 @hughsie Rename ZifCompletion to ZifState
authored
382 state_loop = zif_state_get_child (state_local);
45b3b5f @hughsie Smush a GCancellable into #ZifState to reduce the number of args in load...
authored
383 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
384 break;
385 }
8a8aed4 @hughsie Use completion and cancellation for actions that can block for some time
authored
386
387 /* this section done */
d897d9c @hughsie Check for cancel in many, many more places
authored
388 ret = zif_state_done (state_local, error);
389 if (!ret)
390 goto out;
fc63678 @hughsie Add the functionality to get the file lists for a remote package
authored
391 }
392
393 /* this section done */
d897d9c @hughsie Check for cancel in many, many more places
authored
394 ret = zif_state_done (state, error);
395 if (!ret)
396 goto out;
fc63678 @hughsie Add the functionality to get the file lists for a remote package
authored
397 out:
398 return array;
399 }
400
401 /**
9673756 @hughsie Add ZifMdFilelistsXml so we can read filelists from rpmfusion-free
authored
402 * zif_md_filelists_xml_search_file:
403 **/
404 static GPtrArray *
405 zif_md_filelists_xml_search_file (ZifMd *md, gchar **search,
45b3b5f @hughsie Smush a GCancellable into #ZifState to reduce the number of args in load...
authored
406 ZifState *state, GError **error)
9673756 @hughsie Add ZifMdFilelistsXml so we can read filelists from rpmfusion-free
authored
407 {
408 GPtrArray *array = NULL;
409 GPtrArray *packages;
410 ZifPackage *package;
411 GPtrArray *files = NULL;
412 const gchar *filename;
413 guint i, j, k;
414 gboolean ret;
415 const gchar *pkgid;
416 GError *error_local = NULL;
65c90f0 @hughsie Rename ZifCompletion to ZifState
authored
417 ZifState *state_local;
418 ZifState *state_loop;
9673756 @hughsie Add ZifMdFilelistsXml so we can read filelists from rpmfusion-free
authored
419 ZifMdFilelistsXml *md_filelists = ZIF_MD_FILELISTS_XML (md);
420
421 g_return_val_if_fail (ZIF_IS_MD_FILELISTS_XML (md), NULL);
422 g_return_val_if_fail (error == NULL || *error == NULL, NULL);
423
65c90f0 @hughsie Rename ZifCompletion to ZifState
authored
424 /* setup state */
9673756 @hughsie Add ZifMdFilelistsXml so we can read filelists from rpmfusion-free
authored
425 if (md_filelists->priv->loaded)
65c90f0 @hughsie Rename ZifCompletion to ZifState
authored
426 zif_state_set_number_steps (state, 1);
9673756 @hughsie Add ZifMdFilelistsXml so we can read filelists from rpmfusion-free
authored
427 else
65c90f0 @hughsie Rename ZifCompletion to ZifState
authored
428 zif_state_set_number_steps (state, 2);
9673756 @hughsie Add ZifMdFilelistsXml so we can read filelists from rpmfusion-free
authored
429
430 /* if not already loaded, load */
431 if (!md_filelists->priv->loaded) {
65c90f0 @hughsie Rename ZifCompletion to ZifState
authored
432 state_local = zif_state_get_child (state);
45b3b5f @hughsie Smush a GCancellable into #ZifState to reduce the number of args in load...
authored
433 ret = zif_md_load (ZIF_MD (md), state_local, &error_local);
9673756 @hughsie Add ZifMdFilelistsXml so we can read filelists from rpmfusion-free
authored
434 if (!ret) {
435 g_set_error (error, ZIF_MD_ERROR, ZIF_MD_ERROR_FAILED_TO_LOAD,
436 "failed to load md_filelists_xml file: %s", error_local->message);
437 g_error_free (error_local);
438 goto out;
439 }
440
441 /* this section done */
d897d9c @hughsie Check for cancel in many, many more places
authored
442 ret = zif_state_done (state, error);
443 if (!ret)
444 goto out;
9673756 @hughsie Add ZifMdFilelistsXml so we can read filelists from rpmfusion-free
authored
445 }
446
b2c0b12 @hughsie trivial: fix up two runtime critical warnings
authored
447 /* create results array */
448 array = g_ptr_array_new_with_free_func (g_free);
449
450 /* no entries, so shortcut */
451 if (md_filelists->priv->array->len == 0) {
d897d9c @hughsie Check for cancel in many, many more places
authored
452 ret = zif_state_done (state, error);
453 if (!ret)
454 goto out;
b2c0b12 @hughsie trivial: fix up two runtime critical warnings
authored
455 goto out;
456 }
457
8a8aed4 @hughsie Use completion and cancellation for actions that can block for some time
authored
458 /* setup steps */
65c90f0 @hughsie Rename ZifCompletion to ZifState
authored
459 state_local = zif_state_get_child (state);
460 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
461
9673756 @hughsie Add ZifMdFilelistsXml so we can read filelists from rpmfusion-free
authored
462 /* search array */
463 packages = md_filelists->priv->array;
464 for (i=0; i<packages->len; i++) {
465 package = g_ptr_array_index (packages, i);
8a8aed4 @hughsie Use completion and cancellation for actions that can block for some time
authored
466 pkgid = zif_package_remote_get_pkgid (ZIF_PACKAGE_REMOTE (package));
65c90f0 @hughsie Rename ZifCompletion to ZifState
authored
467 state_loop = zif_state_get_child (state_local);
45b3b5f @hughsie Smush a GCancellable into #ZifState to reduce the number of args in load...
authored
468 files = zif_package_get_files (package, state_loop, NULL);
9673756 @hughsie Add ZifMdFilelistsXml so we can read filelists from rpmfusion-free
authored
469 for (k=0; k<files->len; k++) {
470 filename = g_ptr_array_index (files, k);
471 for (j=0; search[j] != NULL; j++) {
472 if (g_strcmp0 (filename, search[j]) == 0) {
473 g_ptr_array_add (array, g_strdup (pkgid));
474 break;
475 }
476 }
477 }
8a8aed4 @hughsie Use completion and cancellation for actions that can block for some time
authored
478
479 /* this section done */
d897d9c @hughsie Check for cancel in many, many more places
authored
480 ret = zif_state_done (state_local, error);
481 if (!ret)
482 goto out;
9673756 @hughsie Add ZifMdFilelistsXml so we can read filelists from rpmfusion-free
authored
483 }
484
485 /* this section done */
d897d9c @hughsie Check for cancel in many, many more places
authored
486 ret = zif_state_done (state, error);
487 if (!ret)
488 goto out;
9673756 @hughsie Add ZifMdFilelistsXml so we can read filelists from rpmfusion-free
authored
489 out:
490 if (files != NULL)
491 g_ptr_array_unref (files);
492 return array;
493 }
494
495 /**
496 * zif_md_filelists_xml_finalize:
497 **/
498 static void
499 zif_md_filelists_xml_finalize (GObject *object)
500 {
501 ZifMdFilelistsXml *md;
502
503 g_return_if_fail (object != NULL);
504 g_return_if_fail (ZIF_IS_MD_FILELISTS_XML (object));
505 md = ZIF_MD_FILELISTS_XML (object);
506
507 g_ptr_array_unref (md->priv->array);
508
509 G_OBJECT_CLASS (zif_md_filelists_xml_parent_class)->finalize (object);
510 }
511
512 /**
513 * zif_md_filelists_xml_class_init:
514 **/
515 static void
516 zif_md_filelists_xml_class_init (ZifMdFilelistsXmlClass *klass)
517 {
518 GObjectClass *object_class = G_OBJECT_CLASS (klass);
519 ZifMdClass *md_class = ZIF_MD_CLASS (klass);
520 object_class->finalize = zif_md_filelists_xml_finalize;
521
522 /* map */
523 md_class->load = zif_md_filelists_xml_load;
524 md_class->unload = zif_md_filelists_xml_unload;
525 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
526 md_class->get_files = zif_md_filelists_xml_get_files;
9673756 @hughsie Add ZifMdFilelistsXml so we can read filelists from rpmfusion-free
authored
527
528 g_type_class_add_private (klass, sizeof (ZifMdFilelistsXmlPrivate));
529 }
530
531 /**
532 * zif_md_filelists_xml_init:
533 **/
534 static void
535 zif_md_filelists_xml_init (ZifMdFilelistsXml *md)
536 {
537 md->priv = ZIF_MD_FILELISTS_XML_GET_PRIVATE (md);
538 md->priv->array = g_ptr_array_new_with_free_func ((GDestroyNotify) g_object_unref);
539 md->priv->loaded = FALSE;
540 md->priv->section = ZIF_MD_FILELISTS_XML_SECTION_UNKNOWN;
541 md->priv->section_list = ZIF_MD_FILELISTS_XML_SECTION_LIST_UNKNOWN;
542 md->priv->section_list_package = ZIF_MD_FILELISTS_XML_SECTION_LIST_PACKAGE_UNKNOWN;
543 md->priv->package_temp = NULL;
544 md->priv->array_temp = NULL;
545 }
546
547 /**
548 * zif_md_filelists_xml_new:
549 *
550 * Return value: A new #ZifMdFilelistsXml class instance.
551 *
61330b1 @hughsie Bump version ready for release
authored
552 * Since: 0.1.0
9673756 @hughsie Add ZifMdFilelistsXml so we can read filelists from rpmfusion-free
authored
553 **/
554 ZifMdFilelistsXml *
555 zif_md_filelists_xml_new (void)
556 {
557 ZifMdFilelistsXml *md;
558 md = g_object_new (ZIF_TYPE_MD_FILELISTS_XML, NULL);
559 return ZIF_MD_FILELISTS_XML (md);
560 }
561
562 /***************************************************************************
563 *** MAKE CHECK TESTS ***
564 ***************************************************************************/
565 #ifdef EGG_TEST
566 #include "egg-test.h"
567
568 void
569 zif_md_filelists_xml_test (EggTest *test)
570 {
571 ZifMdFilelistsXml *md;
572 gboolean ret;
573 GError *error = NULL;
574 GPtrArray *array;
575 ZifPackage *package;
576 ZifString *summary;
577 GCancellable *cancellable;
65c90f0 @hughsie Rename ZifCompletion to ZifState
authored
578 ZifState *state;
9673756 @hughsie Add ZifMdFilelistsXml so we can read filelists from rpmfusion-free
authored
579 gchar *pkgid;
580 gchar *data[] = { "/usr/lib/debug/usr/bin/gpk-prefs.debug", NULL };
581
582 if (!egg_test_start (test, "ZifMdFilelistsXml"))
583 return;
584
585 /* use */
586 cancellable = g_cancellable_new ();
65c90f0 @hughsie Rename ZifCompletion to ZifState
authored
587 state = zif_state_new ();
9673756 @hughsie Add ZifMdFilelistsXml so we can read filelists from rpmfusion-free
authored
588
589 /************************************************************/
590 egg_test_title (test, "get md_filelists_xml md");
591 md = zif_md_filelists_xml_new ();
592 egg_test_assert (test, md != NULL);
593
594 /************************************************************/
595 egg_test_title (test, "loaded");
596 egg_test_assert (test, !md->priv->loaded);
597
598 /************************************************************/
599 egg_test_title (test, "set id");
600 ret = zif_md_set_id (ZIF_MD (md), "fedora");
601 if (ret)
602 egg_test_success (test, NULL);
603 else
604 egg_test_failed (test, "failed to set");
605
606 /************************************************************/
607 egg_test_title (test, "set type");
608 ret = zif_md_set_mdtype (ZIF_MD (md), ZIF_MD_TYPE_FILELISTS_XML);
609 if (ret)
610 egg_test_success (test, NULL);
611 else
612 egg_test_failed (test, "failed to set");
613
614 /************************************************************/
615 egg_test_title (test, "set checksum type");
616 ret = zif_md_set_checksum_type (ZIF_MD (md), G_CHECKSUM_SHA256);
617 if (ret)
618 egg_test_success (test, NULL);
619 else
620 egg_test_failed (test, "failed to set");
621
622 /************************************************************/
623 egg_test_title (test, "set checksum compressed");
624 ret = zif_md_set_checksum (ZIF_MD (md), "cadb324b10d395058ed22c9d984038927a3ea4ff9e0e798116be44b0233eaa49");
625 if (ret)
626 egg_test_success (test, NULL);
627 else
628 egg_test_failed (test, "failed to set");
629
630 /************************************************************/
631 egg_test_title (test, "set checksum uncompressed");
632 ret = zif_md_set_checksum_uncompressed (ZIF_MD (md), "8018e177379ada1d380b4ebf800e7caa95ff8cf90fdd6899528266719bbfdeab");
633 if (ret)
634 egg_test_success (test, NULL);
635 else
636 egg_test_failed (test, "failed to set");
637
638 /************************************************************/
639 egg_test_title (test, "set filename");
640 ret = zif_md_set_filename (ZIF_MD (md), "../test/cache/fedora/filelists.xml.gz");
641 if (ret)
642 egg_test_success (test, NULL);
643 else
644 egg_test_failed (test, "failed to set");
645
646 /************************************************************/
647 egg_test_title (test, "load");
45b3b5f @hughsie Smush a GCancellable into #ZifState to reduce the number of args in load...
authored
648 ret = zif_md_load (ZIF_MD (md), state, &error);
9673756 @hughsie Add ZifMdFilelistsXml so we can read filelists from rpmfusion-free
authored
649 if (ret)
650 egg_test_success (test, NULL);
651 else
652 egg_test_failed (test, "failed to load '%s'", error->message);
653
654 /************************************************************/
655 egg_test_title (test, "loaded");
656 egg_test_assert (test, md->priv->loaded);
657
658 /************************************************************/
659 egg_test_title (test, "search for files");
65c90f0 @hughsie Rename ZifCompletion to ZifState
authored
660 zif_state_reset (state);
45b3b5f @hughsie Smush a GCancellable into #ZifState to reduce the number of args in load...
authored
661 array = zif_md_filelists_xml_search_file (ZIF_MD (md), (gchar**)data, state, &error);
9673756 @hughsie Add ZifMdFilelistsXml so we can read filelists from rpmfusion-free
authored
662 if (array != NULL)
663 egg_test_success (test, NULL);
664 else
665 egg_test_failed (test, "failed to search '%s'", error->message);
666
667 /************************************************************/
668 egg_test_title (test, "correct number");
669 if (array->len != 1)
670 egg_test_failed (test, "got %i", array->len);
671 egg_test_success (test, NULL);
672
673 /************************************************************/
674 egg_test_title (test, "correct value");
675 pkgid = g_ptr_array_index (array, 0);
8a8aed4 @hughsie Use completion and cancellation for actions that can block for some time
authored
676 if (pkgid == NULL)
677 egg_test_failed (test, "failed to get a pkgId");
678 else if (pkgid[0] != '\0' && strlen (pkgid) == 64)
9673756 @hughsie Add ZifMdFilelistsXml so we can read filelists from rpmfusion-free
authored
679 egg_test_success (test, NULL);
680 else
681 egg_test_failed (test, "failed to get a correct pkgId '%s' (%i)", pkgid, strlen (pkgid));
682 g_ptr_array_unref (array);
683
684 g_object_unref (cancellable);
65c90f0 @hughsie Rename ZifCompletion to ZifState
authored
685 g_object_unref (state);
9673756 @hughsie Add ZifMdFilelistsXml so we can read filelists from rpmfusion-free
authored
686 g_object_unref (md);
687
688 egg_test_end (test);
689 }
690 #endif
691
Something went wrong with that request. Please try again.