~ted/ubuntu-app-launch/lp1301173-debug-message

« back to all changes in this revision

Viewing changes to desktop-hook.c

  • Committer: CI bot
  • Author(s): Colin Watson
  • Date: 2014-03-21 17:55:56 UTC
  • mfrom: (135.2.3 libclick-pkgdir)
  • Revision ID: ps-jenkins@lists.canonical.com-20140321175556-6mxaskq0d5q4um3t
Use libclick to get the package directory, saving about 0.7 seconds from Click application startup (on mako). 

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
This is a hook for Click packages.  You can find information on Click package hooks in
25
25
the click documentation:
26
26
 
27
 
https://click-package.readthedocs.org/en/latest/
 
27
https://click.readthedocs.org/en/latest/
28
28
 
29
29
Probably the biggest thing to understand for how this code works is that you need to
30
30
understand that this hook is run after one, or many packages are installed.  A set of
44
44
 
45
45
#include <gio/gio.h>
46
46
#include <glib/gstdio.h>
 
47
#include <click.h>
47
48
#include <string.h>
48
49
#include <errno.h>
49
50
 
390
391
        }
391
392
 
392
393
        /* Check click to find out where the files are */
393
 
        gchar * cmdline = g_strdup_printf("click pkgdir \"%s\"", package);
 
394
        ClickUser * user = click_user_new_for_user(NULL, NULL, &error);
 
395
        if (error != NULL) {
 
396
                g_warning("Unable to read Click database: %s", error->message);
 
397
                g_error_free(error);
 
398
                g_free(package);
 
399
                return;
 
400
        }
 
401
        gchar * pkgdir = click_user_get_path(user, package, &error);
 
402
        if (error != NULL) {
 
403
                g_warning("Unable to get the Click package directory for %s: %s", package, error->message);
 
404
                g_error_free(error);
 
405
                g_free(package);
 
406
                return;
 
407
        }
 
408
        g_object_unref(user);
394
409
        g_free(package);
395
410
 
396
 
        gchar * output = NULL;
397
 
        g_spawn_command_line_sync(cmdline, &output, NULL, NULL, &error);
398
 
        g_free(cmdline);
399
 
 
400
 
        /* If we have an extra newline, we can hide it. */
401
 
        if (output != NULL) {
402
 
                gchar * newline = NULL;
403
 
 
404
 
                newline = g_strstr_len(output, -1, "\n");
405
 
 
406
 
                if (newline != NULL) {
407
 
                        newline[0] = '\0';
408
 
                }
409
 
        }
410
 
 
411
 
        if (error != NULL) {
412
 
                g_warning("Unable to get the package directory from click: %s", error->message);
413
 
                g_error_free(error);
414
 
                g_free(output); /* Probably not set, but just in case */
415
 
                return;
416
 
        }
417
 
 
418
 
        if (!g_file_test(output, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR)) {
419
 
                g_warning("Directory returned by click '%s' couldn't be found", output);
420
 
                g_free(output);
421
 
                return;
422
 
        }
423
 
 
424
 
        gchar * indesktop = manifest_to_desktop(output, state->app_id);
 
411
        if (!g_file_test(pkgdir, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR)) {
 
412
                g_warning("Directory returned by click '%s' couldn't be found", pkgdir);
 
413
                g_free(pkgdir);
 
414
                return;
 
415
        }
 
416
 
 
417
        gchar * indesktop = manifest_to_desktop(pkgdir, state->app_id);
425
418
        if (indesktop == NULL) {
426
 
                g_free(output);
 
419
                g_free(pkgdir);
427
420
                return;
428
421
        }
429
422
 
432
425
        gchar * desktoppath = g_build_filename(desktopdir, desktopfile, NULL);
433
426
        g_free(desktopfile);
434
427
 
435
 
        copy_desktop_file(indesktop, desktoppath, output, state->app_id);
 
428
        copy_desktop_file(indesktop, desktoppath, pkgdir, state->app_id);
436
429
 
437
430
        g_free(desktoppath);
438
431
        g_free(indesktop);
439
 
        g_free(output);
 
432
        g_free(pkgdir);
440
433
 
441
434
        return;
442
435
}