~ted/ubuntu-app-launch/stop-proxy-unref

« back to all changes in this revision

Viewing changes to helpers.c

  • Committer: Tarmac
  • Author(s): Ted Gould
  • Date: 2013-10-09 21:50:43 UTC
  • mfrom: (72.2.4 click-info)
  • Revision ID: tarmac-20131009215043-26g904p9dsoi8trp
Use 'click info' to get manifests. Fixes: https://bugs.launchpad.net/bugs/1232118.

Approved by Charles Kerr, PS Jenkins bot.

Show diffs side-by-side

added added

removed removed

Lines of Context:
61
61
manifest_to_desktop (const gchar * app_dir, const gchar * app_id)
62
62
{
63
63
        gchar * package = NULL;
 
64
        gchar * output = NULL;
64
65
        gchar * application = NULL;
65
66
        gchar * version = NULL;
66
67
        JsonParser * parser = NULL;
72
73
                return NULL;
73
74
        }
74
75
 
75
 
        gchar * manifestfile = g_strdup_printf("%s.manifest", package);
76
 
        gchar * manifestpath = g_build_filename(app_dir, ".click", "info", manifestfile, NULL);
77
 
        g_free(manifestfile);
 
76
        gchar * cmdline = g_strdup_printf("click info \"%s\"", package);
 
77
        g_spawn_command_line_sync(cmdline, &output, NULL, NULL, &error);
 
78
        g_free(cmdline);
78
79
 
79
 
        if (!g_file_test(manifestpath, G_FILE_TEST_EXISTS)) {
80
 
                g_warning("Unable to find manifest file: %s", manifestpath);
 
80
        if (error != NULL) {
 
81
                g_warning("Unable to get manifest for '%s': %s", package, error->message);
 
82
                g_error_free(error);
81
83
                goto manifest_out;
82
84
        }
83
85
 
84
86
        parser = json_parser_new();
85
87
 
86
 
        json_parser_load_from_file(parser, manifestpath, &error);
 
88
        json_parser_load_from_data(parser, output, -1, &error);
 
89
        g_free(output);
 
90
 
87
91
        if (error != NULL) {
88
 
                g_warning("Unable to load manifest file '%s': %s", manifestpath, error->message);
 
92
                g_warning("Unable to load manifest data '%s': %s", package, error->message);
89
93
                g_error_free(error);
90
94
                goto manifest_out;
91
95
        }
92
96
 
93
97
        JsonNode * root = json_parser_get_root(parser);
94
98
        if (json_node_get_node_type(root) != JSON_NODE_OBJECT) {
95
 
                g_warning("Manifest '%s' doesn't start with an object", manifestpath);
 
99
                g_warning("Manifest '%s' doesn't start with an object", package);
96
100
                goto manifest_out;
97
101
        }
98
102
 
99
103
        JsonObject * rootobj = json_node_get_object(root);
100
104
        if (!json_object_has_member(rootobj, "version")) {
101
 
                g_warning("Manifest '%s' doesn't have a version", manifestpath);
 
105
                g_warning("Manifest '%s' doesn't have a version", package);
102
106
                goto manifest_out;
103
107
        }
104
108
 
105
109
        if (g_strcmp0(json_object_get_string_member(rootobj, "version"), version) != 0) {
106
 
                g_warning("Manifest '%s' version '%s' doesn't match AppID version '%s'", manifestpath, json_object_get_string_member(rootobj, "version"), version);
 
110
                g_warning("Manifest '%s' version '%s' doesn't match AppID version '%s'", package, json_object_get_string_member(rootobj, "version"), version);
107
111
                goto manifest_out;
108
112
        }
109
113
 
110
114
        if (!json_object_has_member(rootobj, "hooks")) {
111
 
                g_warning("Manifest '%s' doesn't have an hooks section", manifestpath);
 
115
                g_warning("Manifest '%s' doesn't have an hooks section", package);
112
116
                goto manifest_out;
113
117
        }
114
118
 
115
119
        JsonObject * appsobj = json_object_get_object_member(rootobj, "hooks");
116
120
        if (appsobj == NULL) {
117
 
                g_warning("Manifest '%s' has an hooks section that is not a JSON object", manifestpath);
 
121
                g_warning("Manifest '%s' has an hooks section that is not a JSON object", package);
118
122
                goto manifest_out;
119
123
        }
120
124
 
121
125
        if (!json_object_has_member(appsobj, application)) {
122
 
                g_warning("Manifest '%s' doesn't have the application '%s' defined", manifestpath, application);
 
126
                g_warning("Manifest '%s' doesn't have the application '%s' defined", package, application);
123
127
                goto manifest_out;
124
128
        }
125
129
 
126
130
        JsonObject * appobj = json_object_get_object_member(appsobj, application);
127
131
        if (appobj == NULL) {
128
 
                g_warning("Manifest '%s' has a definition for application '%s' that is not an object", manifestpath, application);
 
132
                g_warning("Manifest '%s' has a definition for application '%s' that is not an object", package, application);
129
133
                goto manifest_out;
130
134
        }
131
135
 
147
151
 
148
152
manifest_out:
149
153
        g_clear_object(&parser);
150
 
        g_free(manifestpath);
151
154
        g_free(package);
152
155
        g_free(application);
153
156
        g_free(version);