[gnome-software/wip/hughsie/flatpak] f
- From: Richard Hughes <rhughes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software/wip/hughsie/flatpak] f
- Date: Thu, 12 May 2016 17:38:23 +0000 (UTC)
commit d052793ae19068439f61f118bfbf28498fb5340a
Author: Richard Hughes <richard hughsie com>
Date: Thu May 12 18:24:21 2016 +0100
f
data/tests/flatpak/build-flatpak.sh | 1 +
src/gs-self-test.c | 129 ++++++++++++++++++++++++-----------
src/plugins/gs-plugin-flatpak.c | 15 ++++-
3 files changed, 104 insertions(+), 41 deletions(-)
---
diff --git a/data/tests/flatpak/build-flatpak.sh b/data/tests/flatpak/build-flatpak.sh
index 9083779..63d87f6 100755
--- a/data/tests/flatpak/build-flatpak.sh
+++ b/data/tests/flatpak/build-flatpak.sh
@@ -1,4 +1,5 @@
rm -rf repo
+flatpak build-finish chiron
flatpak build-export repo chiron
appstream-compose --origin=flatpak --basename=org.test.Chiron --prefix=chiron/files
--output-dir=chiron/files/share/app-info/xmls org.test.Chiron
flatpak build-export repo chiron --update-appstream
diff --git a/src/gs-self-test.c b/src/gs-self-test.c
index 25bd1ff..8029427 100644
--- a/src/gs-self-test.c
+++ b/src/gs-self-test.c
@@ -48,6 +48,7 @@ gs_test_get_filename (const gchar *filename)
return g_strdup (full_tmp);
}
+#if 0
/**
* gs_test_compare_lines:
**/
@@ -77,19 +78,28 @@ gs_test_compare_lines (const gchar *txt1, const gchar *txt2, GError **error)
g_set_error_literal (error, 1, 0, output);
return FALSE;
}
+#endif
/**
- * gs_test_check_contents:
+ * gs_test_idle_delay_cb:
+ **/
+static gboolean
+gs_test_idle_delay_cb (gpointer user_data)
+{
+ GMainLoop *loop = (GMainLoop *) user_data;
+ g_main_loop_quit (loop);
+ return FALSE;
+}
+
+/**
+ * gs_test_idle_delay:
**/
static void
-gs_test_check_contents (const gchar *filename, const gchar *txt)
+gs_test_idle_delay (guint ms)
{
- g_autofree gchar *data = NULL;
- g_autoptr(GError) error = NULL;
- g_file_get_contents (filename, &data, NULL, &error);
- g_assert_no_error (error);
- gs_test_compare_lines (data, txt, &error);
- g_assert_no_error (error);
+ g_autoptr(GMainLoop) loop = g_main_loop_new (NULL, FALSE);
+ g_timeout_add (ms, gs_test_idle_delay_cb, loop);
+ g_main_loop_run (loop);
}
/**
@@ -655,17 +665,24 @@ gs_plugin_loader_fwupd_func (GsPluginLoader *plugin_loader)
static void
gs_plugin_loader_flatpak_func (GsPluginLoader *plugin_loader)
{
+ GsApp *app;
const gchar *root;
gboolean ret;
- GsApp *app;
+ gint kf_remote_repo_version;
+ gint rc;
g_autofree gchar *changed_fn = NULL;
g_autofree gchar *config_fn = NULL;
+ g_autofree gchar *desktop_fn = NULL;
+ g_autofree gchar *kf_remote_url = NULL;
+ g_autofree gchar *metadata_fn = NULL;
g_autofree gchar *testdir = NULL;
+ g_auto(GStrv) argv = NULL;
+ g_auto(GStrv) envp = NULL;
+ g_autoptr(GError) error = NULL;
+ g_autoptr(GKeyFile) kf1 = g_key_file_new ();
+ g_autoptr(GKeyFile) kf2 = g_key_file_new ();
g_autoptr(GsAppList) list = NULL;
g_autoptr(GsAppList) sources = NULL;
- g_autoptr(GError) error = NULL;
- g_auto(GStrv) envp = NULL;
- g_auto(GStrv) argv = NULL;
/* no flatpak, abort */
if (!gs_plugin_loader_get_enabled (plugin_loader, "flatpak"))
@@ -678,10 +695,12 @@ gs_plugin_loader_flatpak_func (GsPluginLoader *plugin_loader)
/* check repo is set up */
config_fn = g_build_filename (root, "flatpak", "repo", "config", NULL);
- gs_test_check_contents (config_fn,
- "[core]\n"
- "repo_version=1\n"
- "mode=bare-user\n");
+ ret = g_key_file_load_from_file (kf1, config_fn, G_KEY_FILE_NONE, &error);
+ g_assert_no_error (error);
+ g_assert (ret);
+ kf_remote_repo_version = g_key_file_get_integer (kf1, "core", "repo_version", &error);
+ g_assert_no_error (error);
+ g_assert_cmpint (kf_remote_repo_version, ==, 1);
/* set up fake environment */
envp = g_new0 (gchar *, 2);
@@ -689,36 +708,35 @@ gs_plugin_loader_flatpak_func (GsPluginLoader *plugin_loader)
/* add a remote */
//FIXME, use the plugin API
+ //XDG_DATA_HOME=/var/tmp/self-test flatpak remote-add --user --no-gpg-verify test
../data/tests/flatpak/repo/
testdir = gs_test_get_filename ("tests/flatpak");
g_assert (testdir != NULL);
argv = g_new0 (gchar *, 7);
argv[0] = g_strdup ("/usr/bin/flatpak");
argv[1] = g_strdup ("--user");
argv[2] = g_strdup ("--no-gpg-verify");
+ argv[2] = g_strdup ("--if-not-exists");
argv[3] = g_strdup ("remote-add");
argv[4] = g_strdup ("test");
argv[5] = g_build_filename (testdir, "repo", NULL);
ret = g_spawn_sync (NULL, argv, envp, G_SPAWN_DEFAULT, NULL, NULL,
- NULL, NULL, NULL, &error);
+ NULL, NULL, &rc, &error);
g_assert_no_error (error);
g_assert (ret);
+ g_assert_cmpint (rc, ==, 0);
/* check remote was set up */
- gs_test_check_contents (config_fn,
- "[core]\n"
- "repo_version=1\n"
- "mode=bare-user\n"
- "\n"
- "[remote \"test\"]\n"
-
"url=file:///home/hughsie/Code/gnome3/gnome-software/data/tests/flatpak/repo\n"
- "gpg-verify=false\n"
- "gpg-verify-summary=false\n"
- );
-
- //XDG_DATA_HOME=/tmp/flatpack/ flatpak remote-add --user --no-gpg-verify test
../data/tests/flatpak/repo/
+ ret = g_key_file_load_from_file (kf2, config_fn, G_KEY_FILE_NONE, &error);
+ g_assert_no_error (error);
+ g_assert (ret);
+ kf_remote_url = g_key_file_get_string (kf2, "remote \"test\"", "url", &error);
+ g_assert_no_error (error);
+ g_assert_cmpstr (kf_remote_url, !=, NULL);
+
+ /* wait a small amount for the monitor */
+if(0) gs_test_idle_delay (1000);
/* check the source now exists */
- //FIXME
sources = gs_plugin_loader_get_sources (plugin_loader,
GS_PLUGIN_REFINE_FLAGS_DEFAULT,
NULL,
@@ -726,12 +744,11 @@ gs_plugin_loader_flatpak_func (GsPluginLoader *plugin_loader)
g_assert_no_error (error);
g_assert (sources != NULL);
g_assert_cmpint (g_list_length (sources), ==, 1);
- app = GS_APP (list->data);
+ app = GS_APP (sources->data);
g_assert_cmpstr (gs_app_get_id (app), ==, "test");
- g_assert_cmpint (gs_app_get_kind (app), ==, AS_APP_KIND_UNKNOWN);
+ g_assert_cmpint (gs_app_get_kind (app), ==, AS_APP_KIND_SOURCE);
/* refresh the appstream metadata */
- //FIXME
//flatpak update --appstream gnome
ret = gs_plugin_loader_refresh (plugin_loader,
G_MAXUINT,
@@ -741,7 +758,9 @@ gs_plugin_loader_flatpak_func (GsPluginLoader *plugin_loader)
g_assert_no_error (error);
g_assert (ret);
+#if 0
/* find available application */
+ //XDG_DATA_HOME=/var/tmp/self-test flatpak --user remote-ls test
list = gs_plugin_loader_search (plugin_loader,
"Bingo",
GS_PLUGIN_REFINE_FLAGS_DEFAULT,
@@ -750,8 +769,6 @@ gs_plugin_loader_flatpak_func (GsPluginLoader *plugin_loader)
g_assert_no_error (error);
g_assert (list != NULL);
- //XDG_DATA_HOME=/tmp/flatpack/ flatpak --user remote-ls test
-
/* make sure there is one entry, the flatpak app */
g_assert_cmpint (g_list_length (list), ==, 1);
app = GS_APP (list->data);
@@ -767,24 +784,53 @@ gs_plugin_loader_flatpak_func (GsPluginLoader *plugin_loader)
g_assert_no_error (error);
g_assert (ret);
g_assert_cmpint (gs_app_get_state (app), ==, AS_APP_STATE_INSTALLED);
+#endif
/* check the application exists in the right places */
- //FIXME
+ metadata_fn = g_build_filename (root,
+ "flatpak",
+ "app",
+ "org.test.Chiron",
+ "current",
+ "active",
+ "metadata",
+ NULL);
+ g_assert (g_file_test (metadata_fn, G_FILE_TEST_IS_REGULAR));
+ desktop_fn = g_build_filename (root,
+ "flatpak",
+ "app",
+ "org.test.Chiron",
+ "current",
+ "active",
+ "export",
+ "share",
+ "applications",
+ "org.test.Chiron.desktop",
+ NULL);
+ g_assert (g_file_test (desktop_fn, G_FILE_TEST_IS_REGULAR));
/* remove the application */
+app = gs_app_new ("org.test.Chiron.desktop");
+gs_app_set_management_plugin (app, "flatpak");
+gs_app_add_source (app, "app/org.test.Chiron/x86_64/master");
+gs_app_set_state (app, AS_APP_STATE_INSTALLED);
ret = gs_plugin_loader_app_action (plugin_loader, app,
GS_PLUGIN_LOADER_ACTION_REMOVE,
NULL,
&error);
g_assert_no_error (error);
g_assert (ret);
- g_assert_cmpint (gs_app_get_state (app), ==, AS_APP_STATE_AVAILABLE);
+ /* NOTE: this isn't AVAILABLE as we don't know if the app is
+ * re-installable */
+ g_assert_cmpint (gs_app_get_state (app), ==, AS_APP_STATE_UNKNOWN);
+ g_assert (!g_file_test (metadata_fn, G_FILE_TEST_IS_REGULAR));
+ g_assert (!g_file_test (desktop_fn, G_FILE_TEST_IS_REGULAR));
}
int
main (int argc, char **argv)
{
- const gchar *tmp_root = "/tmp/self-test";
+ const gchar *tmp_root = "/var/tmp/self-test";
gboolean ret;
g_autofree gchar *fn = NULL;
g_autofree gchar *xml = NULL;
@@ -818,13 +864,16 @@ main (int argc, char **argv)
g_setenv ("GS_SELF_TEST_PROVENANCE_LICENSE_URL", "https://www.debian.org/", TRUE);
g_setenv ("GS_SELF_TEST_FLATPACK_DATADIR", tmp_root, TRUE);
+ /* needed so we can pick up the new AppStream root */
+ g_setenv ("AS_GLIB_FLATPAK_EXTRA_DATADIR", tmp_root, TRUE);
+
/* ensure test root does not exist */
- if (g_file_test (tmp_root, G_FILE_TEST_EXISTS)) {
+ if (0 && g_file_test (tmp_root, G_FILE_TEST_EXISTS)) {
ret = gs_test_rmtree (tmp_root, &error);
g_assert_no_error (error);
g_assert (ret);
+ g_assert (!g_file_test (tmp_root, G_FILE_TEST_EXISTS));
}
- g_assert (!g_file_test (tmp_root, G_FILE_TEST_EXISTS));
fn = gs_test_get_filename ("icons/hicolor/48x48/org.gnome.Software.png");
g_assert (fn != NULL);
diff --git a/src/plugins/gs-plugin-flatpak.c b/src/plugins/gs-plugin-flatpak.c
index 486e27b..42ef6ea 100644
--- a/src/plugins/gs-plugin-flatpak.c
+++ b/src/plugins/gs-plugin-flatpak.c
@@ -282,6 +282,7 @@ gs_plugin_setup (GsPlugin *plugin, GCancellable *cancellable, GError **error)
"flatpak",
NULL);
g_autoptr(GFile) file = g_file_new_for_path (full_path);
+ g_debug ("using custom flatpak path %s", full_path);
priv->installation = flatpak_installation_new_for_path (file,
TRUE,
cancellable,
@@ -854,10 +855,16 @@ gs_plugin_refine_item_metadata (GsPlugin *plugin,
if (gs_app_get_metadata_item (app, "flatpak::kind") != NULL)
return TRUE;
+ /* not a valid type */
+ if (gs_app_get_kind (app) == AS_APP_KIND_SOURCE)
+ return TRUE;
+
/* AppStream sets the source to appname/arch/branch, if this isn't set
* we can't break out the fields */
if (gs_app_get_source_default (app) == NULL) {
- g_warning ("no source set by appstream for %s", gs_plugin_get_name (plugin));
+ g_autofree gchar *tmp = gs_app_to_string (app);
+ g_warning ("no source set by appstream for %s: %s",
+ gs_plugin_get_name (plugin), tmp);
return TRUE;
}
@@ -1233,6 +1240,12 @@ gs_plugin_app_remove (GsPlugin *plugin,
gs_plugin_get_name (plugin)) != 0)
return TRUE;
+ /* refine to get basics */
+ if (!gs_plugin_flatpak_refine_app (plugin, app,
+ GS_PLUGIN_REFINE_FLAGS_DEFAULT,
+ cancellable, error))
+ return FALSE;
+
/* remove */
gs_app_set_state (app, AS_APP_STATE_REMOVING);
if (!flatpak_installation_uninstall (priv->installation,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]