~ubuntu-branches/ubuntu/trusty/packagekit/trusty

« back to all changes in this revision

Viewing changes to backends/zif/pk-backend-zif.c

  • Committer: Package Import Robot
  • Author(s): Robert Ancell
  • Date: 2012-07-09 12:18:58 UTC
  • mfrom: (76.1.1 quantal) (56.1.19 sid)
  • Revision ID: package-import@ubuntu.com-20120709121858-h6wkjbgs1gfb6cik
Tags: 0.7.5-2ubuntu1
* Merge with Debian, remaining Ubuntu changes:
* debian/control:
  - Recommend packagekit-system-interface instead of
    python-aptdaemon.pkcompat: we care about the dbus interface, now provided
    by the python3 package, not the python module.
  - Have the libraries recommend python-aptdaemon.pkcompat over packagekit as
    we don't want the latter to be installed by default. 

Show diffs side-by-side

added added

removed removed

Lines of Context:
45
45
        ZifState        *state;
46
46
        ZifStore        *store_local;
47
47
        ZifTransaction  *transaction;
48
 
} PkBackendYumPrivate;
 
48
} PkBackendZifPrivate;
49
49
 
50
 
static PkBackendYumPrivate *priv;
 
50
static PkBackendZifPrivate *priv;
51
51
 
52
52
/**
53
53
 * pk_backend_get_description:
418
418
}
419
419
 
420
420
/**
 
421
 * pk_backend_package_is_application:
 
422
 **/
 
423
static gboolean
 
424
pk_backend_package_is_application (ZifPackage *package,
 
425
                                   gboolean *is_application,
 
426
                                   ZifState *state,
 
427
                                   GError **error)
 
428
{
 
429
        const gchar *filename;
 
430
        gboolean ret = TRUE;
 
431
        GPtrArray *files;
 
432
        guint i;
 
433
 
 
434
        /* get file lists and see if it installs a desktop file */
 
435
        files = zif_package_get_files (package, state, error);
 
436
        if (files == NULL) {
 
437
                ret = FALSE;
 
438
                goto out;
 
439
        }
 
440
        for (i = 0; i < files->len; i++) {
 
441
                filename = g_ptr_array_index (files, i);
 
442
                if (g_str_has_prefix (filename, "/usr/share/applications/") &&
 
443
                    g_str_has_suffix (filename, ".desktop")) {
 
444
                        *is_application = TRUE;
 
445
                        goto out;
 
446
                }
 
447
        }
 
448
 
 
449
        /* not an application */
 
450
        *is_application = FALSE;
 
451
out:
 
452
        if (files != NULL)
 
453
                g_ptr_array_unref (files);
 
454
        return ret;
 
455
}
 
456
 
 
457
/**
421
458
 * pk_backend_filter_package_array:
422
459
 **/
423
460
static GPtrArray *
424
 
pk_backend_filter_package_array (GPtrArray *array, PkBitfield filters)
 
461
pk_backend_filter_package_array (GPtrArray *array,
 
462
                                 PkBitfield filters,
 
463
                                 ZifState *state,
 
464
                                 GError **error)
425
465
{
426
 
        GHashTable *hash_installed;
 
466
        gboolean is_application;
 
467
        gboolean ret;
 
468
        GHashTable *hash_application = NULL;
 
469
        GHashTable *hash_installed = NULL;
427
470
        gpointer found;
428
471
        GPtrArray *result = NULL;
429
472
        guint i;
430
473
        ZifPackage *package;
 
474
        ZifState *state_local;
 
475
        ZifState *state_loop;
 
476
 
 
477
        /* get the filelists if the application filter is used */
 
478
        if (pk_bitfield_contain (filters, PK_FILTER_ENUM_APPLICATION) ||
 
479
            pk_bitfield_contain (filters, PK_FILTER_ENUM_NOT_APPLICATION)) {
 
480
                hash_application = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, NULL);
 
481
                state_local = zif_state_get_child (state);
 
482
                zif_state_set_number_steps (state_local, array->len);
 
483
                for (i = 0; i < array->len; i++) {
 
484
                        package = g_ptr_array_index (array, i);
 
485
                        state_loop = zif_state_get_child (state_local);
 
486
                        ret = pk_backend_package_is_application (package,
 
487
                                                                 &is_application,
 
488
                                                                 state_loop,
 
489
                                                                 error);
 
490
                        if (!ret)
 
491
                                goto out;
 
492
                        if (is_application) {
 
493
                                g_hash_table_insert (hash_application,
 
494
                                                     (gpointer) zif_package_get_name_version_arch (package),
 
495
                                                     GINT_TO_POINTER (1));
 
496
                        }
 
497
                }
 
498
        }
431
499
 
432
500
        hash_installed = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, NULL);
433
501
        result = g_ptr_array_new_with_free_func ((GDestroyNotify) g_object_unref);
465
533
                                continue;
466
534
                }
467
535
 
 
536
                /* application */
 
537
                if (pk_bitfield_contain (filters,
 
538
                                         PK_FILTER_ENUM_APPLICATION)) {
 
539
                        found = g_hash_table_lookup (hash_application,
 
540
                                                     zif_package_get_name_version_arch (package));
 
541
                        if (found == NULL)
 
542
                                continue;
 
543
                }
 
544
 
468
545
                /* development */
469
546
                if (pk_bitfield_contain (filters,
470
547
                                         PK_FILTER_ENUM_DEVELOPMENT)) {
517
594
        if (pk_bitfield_contain (filters, PK_FILTER_ENUM_NEWEST))
518
595
                zif_package_array_filter_newest (result);
519
596
 
520
 
        g_hash_table_destroy (hash_installed);
 
597
out:
 
598
        if (hash_application != NULL)
 
599
                g_hash_table_destroy (hash_application);
 
600
        if (hash_installed != NULL)
 
601
                g_hash_table_destroy (hash_installed);
521
602
        return result;
522
603
}
523
604
 
1305
1386
        }
1306
1387
 
1307
1388
        /* filter */
1308
 
        result = pk_backend_filter_package_array (array, filters);
 
1389
        state_local = zif_state_get_child (priv->state);
 
1390
        result = pk_backend_filter_package_array (array,
 
1391
                                                  filters,
 
1392
                                                  state_local,
 
1393
                                                  &error);
 
1394
        if (result == NULL) {
 
1395
                pk_backend_error_code (backend,
 
1396
                                       PK_ERROR_ENUM_CANNOT_GET_FILELIST,
 
1397
                                       "failed to filters: %s",
 
1398
                                       error->message);
 
1399
                g_error_free (error);
 
1400
                goto out;
 
1401
        }
1309
1402
 
1310
1403
        /* this section done */
1311
1404
        ret = zif_state_done (priv->state, &error);
1586
1679
        pk_debug_add_log_domain ("Zif");
1587
1680
 
1588
1681
        /* create private area */
1589
 
        priv = g_new0 (PkBackendYumPrivate, 1);
 
1682
        priv = g_new0 (PkBackendZifPrivate, 1);
1590
1683
 
1591
1684
        /* connect to finished, so we can clean up */
1592
1685
        priv->signal_finished =
1788
1881
                PK_FILTER_ENUM_FREE,
1789
1882
                PK_FILTER_ENUM_NEWEST,
1790
1883
                PK_FILTER_ENUM_ARCH,
 
1884
                PK_FILTER_ENUM_APPLICATION,
1791
1885
                -1);
1792
1886
}
1793
1887
 
2203
2297
        }
2204
2298
 
2205
2299
        /* filter */
2206
 
        result = pk_backend_filter_package_array (array, filters);
 
2300
        state_local = zif_state_get_child (priv->state);
 
2301
        result = pk_backend_filter_package_array (array,
 
2302
                                                  filters,
 
2303
                                                  state_local,
 
2304
                                                  &error);
 
2305
        if (result == NULL) {
 
2306
                pk_backend_error_code (backend,
 
2307
                                       PK_ERROR_ENUM_CANNOT_GET_FILELIST,
 
2308
                                       "failed to filter: %s",
 
2309
                                       error->message);
 
2310
                g_error_free (error);
 
2311
                goto out;
 
2312
        }
2207
2313
 
2208
2314
        /* this section done */
2209
2315
        ret = zif_state_done (priv->state, &error);
2416
2522
        }
2417
2523
 
2418
2524
        /* filter */
2419
 
        result = pk_backend_filter_package_array (array, filters);
 
2525
        state_local = zif_state_get_child (priv->state);
 
2526
        result = pk_backend_filter_package_array (array,
 
2527
                                                  filters,
 
2528
                                                  state_local,
 
2529
                                                  &error);
 
2530
        if (result == NULL) {
 
2531
                pk_backend_error_code (backend,
 
2532
                                       PK_ERROR_ENUM_CANNOT_GET_FILELIST,
 
2533
                                       "failed to filter: %s",
 
2534
                                       error->message);
 
2535
                g_error_free (error);
 
2536
                goto out;
 
2537
        }
2420
2538
 
2421
2539
        /* this section done */
2422
2540
        ret = zif_state_done (priv->state, &error);
3188
3306
        }
3189
3307
 
3190
3308
        /* filter */
3191
 
        result = pk_backend_filter_package_array (updates_available, filters);
 
3309
        state_local = zif_state_get_child (priv->state);
 
3310
        result = pk_backend_filter_package_array (updates_available,
 
3311
                                                  filters,
 
3312
                                                  state_local,
 
3313
                                                  &error);
 
3314
        if (result == NULL) {
 
3315
                pk_backend_error_code (backend,
 
3316
                                       PK_ERROR_ENUM_CANNOT_GET_FILELIST,
 
3317
                                       "failed to filter: %s",
 
3318
                                       error->message);
 
3319
                g_error_free (error);
 
3320
                goto out;
 
3321
        }
3192
3322
 
3193
3323
        /* done */
3194
3324
        pk_backend_set_percentage (backend, 100);