Ejemplo n.º 1
0
static void
on_reformatter_exited (GTask  *task,
                       GError *error)
{
  GisPage *page = GIS_PAGE (g_task_get_source_object (task));

  gis_driver_show_window (page->driver);

  if (error == NULL)
    {
      g_task_return_boolean (task, TRUE);
      return;
    }

  GtkWindow *toplevel = GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (page)));
  GtkWidget *message_dialog;

  g_critical ("Error running the reformatter: %s", error->message);

  message_dialog = gtk_message_dialog_new (toplevel,
                                           GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
                                           GTK_MESSAGE_ERROR,
                                           GTK_BUTTONS_CLOSE,
                                           /* Translators: this is shown when launching the
                                            * reformatter (an external program) fails. The
                                            * placeholder is an error message describing what went
                                            * wrong.
                                            */
                                           _("Error running the reformatter: %s"), error->message);
  g_idle_add_full (G_PRIORITY_DEFAULT_IDLE, run_dialog_cb,
                   message_dialog, (GDestroyNotify) gtk_widget_destroy);

  g_task_return_error (task, g_steal_pointer (&error));
}
Ejemplo n.º 2
0
static gchar *
gis_page_util_get_image_version (const gchar *path,
                                 GError     **error)
{
  ssize_t attrsize;
  g_autofree gchar *value = NULL;

  g_return_val_if_fail (path != NULL, NULL);

  attrsize = getxattr (path, EOS_IMAGE_VERSION_XATTR, NULL, 0);
  if (attrsize >= 0)
    {
      value = g_malloc (attrsize + 1);
      value[attrsize] = 0;

      attrsize = getxattr (path, EOS_IMAGE_VERSION_XATTR, value,
                           attrsize);
    }

  if (attrsize >= 0)
    {
      return g_steal_pointer (&value);
    }
  else
    {
      int errsv = errno;
      g_set_error (error, G_IO_ERROR, g_io_error_from_errno (errsv),
                   "Error examining " EOS_IMAGE_VERSION_XATTR " on %s: %s",
                   path, g_strerror (errsv));
      return NULL;
    }
}
Ejemplo n.º 3
0
static gboolean
add_ref_to_set (const char       *remote,
                int               base_fd,
                const char       *path,
                GHashTable       *refs,
                GCancellable     *cancellable,
                GError          **error)
{
  gsize len;
  char *contents = glnx_file_get_contents_utf8_at (base_fd, path, &len, cancellable, error);
  if (!contents)
    return FALSE;

  g_strchomp (contents);

  g_autoptr(GString) refname = g_string_new ("");
  if (remote)
    {
      g_string_append (refname, remote);
      g_string_append_c (refname, ':');
    }
  g_string_append (refname, path);
  g_hash_table_insert (refs, g_string_free (g_steal_pointer (&refname), FALSE), contents);

  return TRUE;
}
Ejemplo n.º 4
0
static void
photos_glib_file_copy_read (GObject *source_object, GAsyncResult *res, gpointer user_data)
{
  GCancellable *cancellable;
  GFile *source = G_FILE (source_object);
  g_autoptr (GFileInputStream) istream = NULL;
  g_autoptr (GTask) task = G_TASK (user_data);
  PhotosGLibFileCopyData *data;

  cancellable = g_task_get_cancellable (task);
  data = (PhotosGLibFileCopyData *) g_task_get_task_data (task);

  {
    g_autoptr (GError) error = NULL;

    istream = g_file_read_finish (source, res, &error);
    if (error != NULL)
      {
        g_task_return_error (task, g_steal_pointer (&error));
        goto out;
      }
  }

  g_output_stream_splice_async (G_OUTPUT_STREAM (data->ostream),
                                G_INPUT_STREAM (istream),
                                G_OUTPUT_STREAM_SPLICE_CLOSE_SOURCE | G_OUTPUT_STREAM_SPLICE_CLOSE_TARGET,
                                data->io_priority,
                                cancellable,
                                photos_glib_file_copy_splice,
                                g_object_ref (task));

 out:
  return;
}
Ejemplo n.º 5
0
void
ide_build_system_get_build_flags_for_dir_async (IdeBuildSystem      *self,
                                                GFile               *directory,
                                                GCancellable        *cancellable,
                                                GAsyncReadyCallback  callback,
                                                gpointer             user_data)
{
  g_autoptr(IdeTask) task = NULL;

  g_return_if_fail (IDE_IS_BUILD_SYSTEM (self));
  g_return_if_fail (G_IS_FILE (directory));
  g_return_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable));

  task = ide_task_new (self, cancellable, callback, user_data);
  ide_task_set_source_tag (task, ide_build_system_get_build_flags_for_dir_async);
  ide_task_set_priority (task, G_PRIORITY_LOW);

  ide_g_file_get_children_async (directory,
                                 G_FILE_ATTRIBUTE_STANDARD_NAME","
                                 G_FILE_ATTRIBUTE_STANDARD_TYPE,
                                 G_FILE_QUERY_INFO_NONE,
                                 G_PRIORITY_LOW,
                                 cancellable,
                                 ide_build_system_get_build_flags_for_dir_cb,
                                 g_steal_pointer (&task));
}
Ejemplo n.º 6
0
static void
on_import_complete (GObject *source, GAsyncResult *result, gpointer user_data)
{
    SeahorsePgpBackend *backend = SEAHORSE_PGP_BACKEND (source);
    g_autoptr(SeahorseKeyserverResultsRow) row =
        SEAHORSE_KEYSERVER_RESULTS_ROW (user_data);
    const gchar *result_icon_name;
    g_autoptr(GtkWidget) result_icon = NULL;
    g_autofree gchar *result_tooltip = NULL;
    g_autoptr(GError) err = NULL;

    if (!seahorse_pgp_backend_transfer_finish (backend, result, &err)) {
        result_icon_name = "dialog-warning-symbolic";
        result_tooltip = g_strdup_printf (_("Couldn’t import key: %s"),
                                          err->message);
    } else {
        result_icon_name = "emblem-ok-symbolic";
        result_tooltip = g_strdup (_("Key import succeeded"));
    }

    result_icon = gtk_image_new_from_icon_name (result_icon_name,
                                                GTK_ICON_SIZE_BUTTON);
    gtk_button_set_image (row->import_button, g_steal_pointer (&result_icon));
    gtk_widget_set_tooltip_text (GTK_WIDGET (row->import_button),
                                 result_tooltip);
}
Ejemplo n.º 7
0
void
photos_glib_file_copy_async (GFile *source,
                             GFile *destination,
                             GFileCopyFlags flags,
                             gint io_priority,
                             GCancellable *cancellable,
                             GAsyncReadyCallback callback,
                             gpointer user_data)
{
  GFileCreateFlags create_flags = G_FILE_CREATE_NONE;
  g_autoptr (GTask) task = NULL;
  g_autoptr (PhotosGLibFileCopyData) data = NULL;

  g_return_if_fail (G_IS_FILE (source));
  g_return_if_fail (G_IS_FILE (destination));
  g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));

  task = g_task_new (source, cancellable, callback, user_data);
  g_task_set_source_tag (task, photos_glib_file_copy_async);

  data = photos_glib_file_copy_data_new (io_priority);
  g_task_set_task_data (task, g_steal_pointer (&data), (GDestroyNotify) photos_glib_file_copy_data_free);

  if ((flags & G_FILE_COPY_OVERWRITE) != 0)
    create_flags |= G_FILE_CREATE_REPLACE_DESTINATION;

  photos_glib_file_create_async (destination,
                                 create_flags,
                                 io_priority,
                                 cancellable,
                                 photos_glib_file_copy_create,
                                 g_object_ref (task));
}
Ejemplo n.º 8
0
gboolean
ostree_option_context_parse (GOptionContext *context,
                             const GOptionEntry *main_entries,
                             int *argc,
                             char ***argv,
                             OstreeBuiltinFlags flags,
                             OstreeRepo **out_repo,
                             GCancellable *cancellable,
                             GError **error)
{
  g_autoptr(OstreeRepo) repo = NULL;

  /* Entries are listed in --help output in the order added.  We add the
   * main entries ourselves so that we can add the --repo entry first. */

  if (!(flags & OSTREE_BUILTIN_FLAG_NO_REPO))
    g_option_context_add_main_entries (context, repo_entry, NULL);

  if (main_entries != NULL)
    g_option_context_add_main_entries (context, main_entries, NULL);

  g_option_context_add_main_entries (context, global_entries, NULL);

  if (!g_option_context_parse (context, argc, argv, error))
    return FALSE;

  if (opt_version)
    {
      /* This should now be YAML, like `docker version`, so it's both nice to read
       * possible to parse */
      g_auto(GStrv) features = g_strsplit (OSTREE_FEATURES, " ", -1);
      g_print ("%s:\n", PACKAGE_NAME);
      g_print (" Version: %s\n", PACKAGE_VERSION);
      if (strlen (OSTREE_GITREV) > 0)
        g_print (" Git: %s\n", OSTREE_GITREV);
#ifdef BUILDOPT_IS_DEVEL_BUILD
      g_print (" DevelBuild: yes\n");
#endif
      g_print (" Features:\n");
      for (char **iter = features; iter && *iter; iter++)
        g_print ("  - %s\n", *iter);
      exit (EXIT_SUCCESS);
    }

  if (opt_verbose)
    g_log_set_handler (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, message_handler, NULL);

  if (!(flags & OSTREE_BUILTIN_FLAG_NO_REPO))
    {
      repo = parse_repo_option (context, opt_repo, (flags & OSTREE_BUILTIN_FLAG_NO_CHECK) > 0,
                                cancellable, error);
      if (!repo)
        return FALSE;
    }

  if (out_repo)
    *out_repo = g_steal_pointer (&repo);

  return TRUE;
}
Ejemplo n.º 9
0
/**
 * gdata_access_handler_get_rules_async:
 * @self: a #GDataAccessHandler
 * @service: a #GDataService
 * @cancellable: (allow-none): optional #GCancellable object, or %NULL
 * @progress_callback: (allow-none) (closure progress_user_data): a #GDataQueryProgressCallback to call when a rule is loaded, or %NULL
 * @progress_user_data: (closure): data to pass to the @progress_callback function
 * @destroy_progress_user_data: (allow-none): the function to call when @progress_callback will not be called any more, or %NULL. This function will be
 * called with @progress_user_data as a parameter and can be used to free any memory allocated for it.
 * @callback: a #GAsyncReadyCallback to call when the query is finished
 * @user_data: (closure): data to pass to the @callback function
 *
 * Retrieves a #GDataFeed containing all the access rules which apply to the given #GDataAccessHandler. Only the owner of a #GDataAccessHandler may
 * view its rule feed. @self and @service are both reffed when this function is called, so can safely be unreffed after this function returns.
 *
 * For more details, see gdata_access_handler_get_rules(), which is the synchronous version of this function, and gdata_service_query_async(), which
 * is the base asynchronous query function.
 *
 * When the operation is finished, @callback will be called. You can then call gdata_service_query_finish()
 * to get the results of the operation.
 *
 * Since: 0.9.1
 */
void
gdata_access_handler_get_rules_async (GDataAccessHandler *self, GDataService *service, GCancellable *cancellable,
                                      GDataQueryProgressCallback progress_callback, gpointer progress_user_data,
                                      GDestroyNotify destroy_progress_user_data,
                                      GAsyncReadyCallback callback, gpointer user_data)
{
	g_autoptr(GTask) task = NULL;
	GetRulesAsyncData *data;

	g_return_if_fail (GDATA_IS_ACCESS_HANDLER (self));
	g_return_if_fail (GDATA_IS_SERVICE (service));
	g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
	g_return_if_fail (callback != NULL);

	data = g_slice_new (GetRulesAsyncData);
	data->service = g_object_ref (service);
	data->progress_callback = progress_callback;
	data->progress_user_data = progress_user_data;
	data->destroy_progress_user_data = destroy_progress_user_data;

	task = g_task_new (self, cancellable, callback, user_data);
	g_task_set_source_tag (task, gdata_service_query_async);
	g_task_set_task_data (task, g_steal_pointer (&data), (GDestroyNotify) get_rules_async_data_free);
	g_task_run_in_thread (task, get_rules_thread);
}
Ejemplo n.º 10
0
static void
ide_run_manager_run_discover_cb (GObject      *object,
                                 GAsyncResult *result,
                                 gpointer      user_data)
{
  IdeRunManager *self = (IdeRunManager *)object;
  g_autoptr(IdeBuildTarget) build_target = NULL;
  g_autoptr(GTask) task = user_data;
  GError *error = NULL;

  g_assert (IDE_IS_RUN_MANAGER (self));
  g_assert (G_IS_ASYNC_RESULT (result));

  build_target = ide_run_manager_discover_default_target_finish (self, result, &error);

  if (build_target == NULL)
    {
      g_task_return_error (task, error);
      return;
    }

  ide_run_manager_set_build_target (self, build_target);

  g_task_set_task_data (task, g_steal_pointer (&build_target), g_object_unref);

  do_run_async (self, task);
}
Ejemplo n.º 11
0
gboolean
get_origin_refspec (OstreeDeployment *booted_deployment,
                    gchar **out_refspec,
                    GError **error)
{
  GKeyFile *origin;
  g_autofree gchar *refspec = NULL;

  g_return_val_if_fail (OSTREE_IS_DEPLOYMENT (booted_deployment), FALSE);
  g_return_val_if_fail (out_refspec != NULL, FALSE);
  g_return_val_if_fail (error == NULL || *error == NULL, FALSE);

  origin = ostree_deployment_get_origin (booted_deployment);
  if (origin == NULL)
    {
      const gchar *osname = ostree_deployment_get_osname (booted_deployment);
      const gchar *booted = ostree_deployment_get_csum (booted_deployment);

      g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND,
                   "No origin found for %s (%s), cannot upgrade",
                   osname, booted);
      return FALSE;
    }

  refspec = g_key_file_get_string (origin, "origin", "refspec", error);
  if (refspec == NULL)
    return FALSE;

  *out_refspec = g_steal_pointer (&refspec);
  return TRUE;
}
Ejemplo n.º 12
0
gchar *
gs_snapd_get_resource (const gchar *macaroon, gchar **discharges,
                       const gchar *path,
                       gsize *data_length,
                       GCancellable *cancellable, GError **error)
{
    guint status_code;
    g_autofree gchar *reason_phrase = NULL;
    g_autofree gchar *response_type = NULL;
    g_autofree gchar *data = NULL;

    if (!send_request ("GET", path, NULL,
                       macaroon, discharges,
                       &status_code, &reason_phrase,
                       NULL, &data, data_length,
                       cancellable, error))
        return NULL;

    if (status_code != SOUP_STATUS_OK) {
        g_set_error (error,
                     GS_PLUGIN_ERROR,
                     GS_PLUGIN_ERROR_FAILED,
                     "snapd returned status code %u: %s",
                     status_code, reason_phrase);
        return NULL;
    }

    return g_steal_pointer (&data);
}
Ejemplo n.º 13
0
void
gs_page_authenticate (GsPage *page,
		      GsApp *app,
		      const gchar *auth_id,
		      GCancellable *cancellable,
		      GsPageAuthCallback callback,
		      gpointer user_data)
{
	GsPagePrivate *priv = gs_page_get_instance_private (page);
	g_autoptr(GsPageHelper) helper = NULL;
	GtkWidget *dialog;
	g_autoptr(GError) error = NULL;

	helper = g_slice_new0 (GsPageHelper);
	helper->app = app != NULL ? g_object_ref (app) : NULL;
	helper->page = g_object_ref (page);
	helper->callback = callback;
	helper->callback_data = user_data;

	dialog = gs_auth_dialog_new (priv->plugin_loader,
				     app,
				     auth_id,
				     &error);
	if (dialog == NULL) {
		g_warning ("%s", error->message);
		return;
	}
	gs_shell_modal_dialog_present (priv->shell, GTK_DIALOG (dialog));
	g_signal_connect (dialog, "response",
			  G_CALLBACK (gs_page_authenticate_cb),
			  helper);
	g_steal_pointer (&helper);
}
Ejemplo n.º 14
0
static GBytes *
download_file (SoupURI *uri)
{
  g_autoptr(GBytes) contents = NULL;

  if (soup_uri_get_scheme (uri) == SOUP_URI_SCHEME_FILE)
    {
      g_autoptr(GFile) file = g_file_new_for_path (soup_uri_get_path (uri));

      eos_updater_read_file_to_bytes (file, NULL, &contents, NULL);
    }
  else
    {
      g_autoptr(SoupSession) soup = soup_session_new ();
      g_autoptr(SoupMessage) msg = soup_message_new_from_uri ("GET", uri);
      guint status = soup_session_send_message (soup, msg);

      if (SOUP_STATUS_IS_SUCCESSFUL (status))
        g_object_get (msg,
                      SOUP_MESSAGE_RESPONSE_BODY_DATA, &contents,
                      NULL);
    }

  return g_steal_pointer (&contents);
}
Ejemplo n.º 15
0
static void
gs_page_remove_app_response_cb (GtkDialog *dialog,
				gint response,
				gpointer user_data)
{
	g_autoptr(GsPageHelper) helper = (GsPageHelper *) user_data;
	GsPagePrivate *priv = gs_page_get_instance_private (helper->page);
	g_autoptr(GsPluginJob) plugin_job = NULL;

	/* unmap the dialog */
	gtk_widget_destroy (GTK_WIDGET (dialog));

	/* not agreed */
	if (response != GTK_RESPONSE_OK)
		return;

	g_debug ("remove %s", gs_app_get_id (helper->app));
	plugin_job = gs_plugin_job_newv (helper->action,
					 "interactive", TRUE,
					 "app", helper->app,
					 NULL);
	gs_plugin_loader_job_process_async (priv->plugin_loader, plugin_job,
					    helper->cancellable,
					    gs_page_app_removed_cb,
					    helper);
	g_steal_pointer (&helper);
}
Ejemplo n.º 16
0
static void
parse_xml_worker (GTask        *task,
                  gpointer      source_object,
                  gpointer      task_data,
                  GCancellable *cancellable)
{
  DspyIntrospectionModel *self = source_object;
  GBytes *bytes = task_data;
  g_autoptr(GError) error = NULL;
  DspyNodeInfo *info;
  const gchar *xml;

  g_assert (G_IS_TASK (task));
  g_assert (DSPY_IS_INTROSPECTION_MODEL (source_object));
  g_assert (bytes != NULL);
  g_assert (!cancellable || G_IS_CANCELLABLE (cancellable));

  xml = (const gchar *)g_bytes_get_data (bytes, NULL);

  g_mutex_lock (&self->chunks_mutex);
  info = _dspy_node_parse (xml, self->chunks, &error);
  g_mutex_unlock (&self->chunks_mutex);

  if (info != NULL)
    g_task_return_pointer (task, info, (GDestroyNotify) _dspy_node_free);
  else
    g_task_return_error (task, g_steal_pointer (&error));
}
Ejemplo n.º 17
0
static void
dspy_introspection_model_get_value (GtkTreeModel *model,
                                    GtkTreeIter  *iter,
                                    gint          column,
                                    GValue       *value)
{
  LOG_DEBUG (G_STRFUNC);

  if (column == 0)
    {
      DspyNode *node = iter->user_data;
      g_autofree gchar *str = NULL;

      g_assert (node != NULL);
      g_assert (DSPY_IS_NODE (node));

      g_value_init (value, G_TYPE_STRING);

      str = _dspy_node_get_text (node);

      if (_dspy_node_is_group (node))
        {
          if (gtk_tree_model_iter_has_child (model, iter))
            g_value_take_string (value, g_strdup_printf ("<b>%s</b>", str));
          else
            g_value_take_string (value, g_strdup_printf ("<span fgalpha='25000' weight='bold'>%s</span>", str));
        }
      else
        g_value_take_string (value, g_steal_pointer (&str));
    }
}
Ejemplo n.º 18
0
static void
on_import_button_clicked (GtkButton *import_button, gpointer user_data)
{
    SeahorseKeyserverResultsRow *row = user_data;
    g_autoptr(GtkWidget) spinner = NULL;
    g_autoptr(GList) keys = NULL;
    g_autoptr(GCancellable) cancellable = NULL;
    SeahorsePgpBackend *backend;
    SeahorseGpgmeKeyring *keyring;

    /* Let the button show a spinner while importing */
    gtk_widget_set_sensitive (GTK_WIDGET (import_button), FALSE);
    spinner = gtk_spinner_new ();
    gtk_spinner_start (GTK_SPINNER (spinner));
    gtk_button_set_image (import_button, g_steal_pointer (&spinner));

    /* Now import the key */
    keys = g_list_append (keys, row->key);
    cancellable = g_cancellable_new ();
    backend = seahorse_pgp_backend_get ();
    keyring = seahorse_pgp_backend_get_default_keyring (backend);
    seahorse_pgp_backend_transfer_async (backend, keys,
                                         SEAHORSE_PLACE (keyring),
                                         cancellable, on_import_complete,
                                         g_object_ref (row));
}
Ejemplo n.º 19
0
static void
photos_glib_file_copy_splice (GObject *source_object, GAsyncResult *res, gpointer user_data)
{
  GOutputStream *ostream = G_OUTPUT_STREAM (source_object);
  g_autoptr (GTask) task = G_TASK (user_data);
  PhotosGLibFileCopyData *data;

  data = (PhotosGLibFileCopyData *) g_task_get_task_data (task);

  g_assert_true (G_IS_FILE_OUTPUT_STREAM (ostream));
  g_assert_true (G_FILE_OUTPUT_STREAM (ostream) == data->ostream);

  {
    g_autoptr (GError) error = NULL;

    g_output_stream_splice_finish (ostream, res, &error);
    if (error != NULL)
      {
        g_task_return_error (task, g_steal_pointer (&error));
        goto out;
      }
  }

  g_task_return_pointer (task, g_object_ref (data->unique_file), g_object_unref);

 out:
  return;
}
Ejemplo n.º 20
0
static void
ide_keybindings_load_plugin (IdeKeybindings *self,
                             PeasPluginInfo *plugin_info,
                             PeasEngine     *engine)
{
  g_autofree gchar *path = NULL;
  const gchar *module_name;
  g_autoptr(GBytes) bytes = NULL;
  g_autoptr(GtkCssProvider) provider = NULL;

  g_assert (IDE_IS_KEYBINDINGS (self));
  g_assert (plugin_info != NULL);
  g_assert (PEAS_IS_ENGINE (engine));

  if (!self->mode || !self->plugin_providers)
    return;

  module_name = peas_plugin_info_get_module_name (plugin_info);
  path = g_strdup_printf ("/org/gnome/builder/plugins/%s/keybindings/%s.css",
                          module_name, self->mode);
  bytes = g_resources_lookup_data (path, 0, NULL);
  if (bytes == NULL)
    return;

  IDE_TRACE_MSG ("Loading %s keybindings for \"%s\" plugin", self->mode, module_name);

  provider = gtk_css_provider_new ();
  gtk_css_provider_load_from_resource (provider, path);
  gtk_style_context_add_provider_for_screen (gdk_screen_get_default (),
                                             GTK_STYLE_PROVIDER (provider),
                                             GTK_STYLE_PROVIDER_PRIORITY_APPLICATION + 1);
  g_hash_table_insert (self->plugin_providers,
                       g_strdup (module_name),
                       g_steal_pointer (&provider));
}
static void
gbp_cmake_toolchain_provider_load_async (IdeToolchainProvider     *provider,
                                         GCancellable             *cancellable,
                                         GAsyncReadyCallback       callback,
                                         gpointer                  user_data)
{
  GbpCMakeToolchainProvider *self = (GbpCMakeToolchainProvider *)provider;
  g_autoptr(IdeTask) task = NULL;
  g_autoptr(GFile) workdir = NULL;
  IdeContext *context;

  IDE_ENTRY;

  g_assert (IDE_IS_MAIN_THREAD ());
  g_assert (GBP_IS_CMAKE_TOOLCHAIN_PROVIDER (self));
  g_assert (!cancellable || G_IS_CANCELLABLE (cancellable));

  context = ide_object_get_context (IDE_OBJECT (self));
  workdir = ide_context_ref_workdir (context);

  task = ide_task_new (provider, cancellable, callback, user_data);
  ide_task_set_source_tag (task, gbp_cmake_toolchain_provider_load_async);
  ide_task_set_priority (task, G_PRIORITY_LOW);

  ide_g_file_find_with_depth_async (workdir,
                                    "*.cmake",
                                    CMAKE_TOOLCHAIN_MAX_FIND_DEPTH,
                                    cancellable,
                                    load_find_files_cb,
                                    g_steal_pointer (&task));

  IDE_EXIT;
}
Ejemplo n.º 22
0
/*
 * Send the given method call and wait for a reply, spinning the main
 * context as necessary.
 */
DBusMessage *
test_main_context_call_and_wait (TestMainContext *ctx,
    DBusConnection *connection,
    DBusMessage *call,
    int timeout)
{
  DBusPendingCall *pc = NULL;
  DBusMessage *reply = NULL;

  if (!dbus_connection_send_with_reply (connection, call, &pc, timeout) ||
      pc == NULL)
    test_oom ();

  if (dbus_pending_call_get_completed (pc))
    test_pending_call_store_reply (pc, &reply);
  else if (!dbus_pending_call_set_notify (pc, test_pending_call_store_reply,
        &reply, NULL))
    test_oom ();

  while (reply == NULL)
    test_main_context_iterate (ctx, TRUE);

  dbus_clear_pending_call (&pc);
  return g_steal_pointer (&reply);
}
Ejemplo n.º 23
0
/* swiss-army knife: takes an strv of pkgspecs destined for
 * install, and splits it into repo pkgs, and for local
 * pkgs, an fd list & idx variant. */
gboolean
rpmostree_sort_pkgs_strv (const char *const* pkgs,
                          GUnixFDList  *fd_list,
                          GPtrArray   **out_repo_pkgs,
                          GVariant    **out_fd_idxs,
                          GError      **error)
{
  g_autoptr(GPtrArray) repo_pkgs = g_ptr_array_new_with_free_func (g_free);
  g_auto(GVariantBuilder) builder;

  g_variant_builder_init (&builder, G_VARIANT_TYPE ("ah"));
  for (const char *const* pkg = pkgs; pkg && *pkg; pkg++)
    {
      if (!g_str_has_suffix (*pkg, ".rpm"))
        g_ptr_array_add (repo_pkgs, g_strdup (*pkg));
      else
        {
          glnx_fd_close int fd = -1;
          if (!glnx_openat_rdonly (AT_FDCWD, *pkg, TRUE, &fd, error))
            return FALSE;

          int idx = g_unix_fd_list_append (fd_list, fd, error);
          if (idx < 0)
            return FALSE;

          g_variant_builder_add (&builder, "h", idx);
        }
    }

  *out_fd_idxs = g_variant_ref_sink (g_variant_new ("ah", &builder));
  *out_repo_pkgs = g_steal_pointer (&repo_pkgs);
  return TRUE;
}
Ejemplo n.º 24
0
static AsApp *
load_appdata (const gchar *prefix, const gchar *app_name, GError **error)
{
	g_autofree gchar *appdata_basename = NULL;
	g_autofree gchar *appdata_path = NULL;
	g_autoptr(AsApp) app = NULL;
	g_autoptr(GPtrArray) problems = NULL;
	AsProblemKind problem_kind;
	AsProblem *problem;
	guint i;

	appdata_basename = g_strconcat (app_name,
					".appdata.xml",
					NULL);
	appdata_path = g_build_filename (prefix,
					 "share",
					 "appdata",
					 appdata_basename,
					 NULL);
	g_debug ("Looking for %s", appdata_path);

	app = as_app_new ();
	if (!as_app_parse_file (app, appdata_path,
				AS_APP_PARSE_FLAG_USE_HEURISTICS,
				error))
		return NULL;
	if (as_app_get_kind (app) == AS_APP_KIND_UNKNOWN) {
		g_set_error (error,
			     AS_APP_ERROR,
			     AS_APP_ERROR_FAILED,
			     "%s has no recognised type",
			     as_app_get_id (AS_APP (app)));
		return NULL;
	}

	problems = as_app_validate (app,
				    AS_APP_VALIDATE_FLAG_NO_NETWORK |
				    AS_APP_VALIDATE_FLAG_RELAX,
				    error);
	if (problems == NULL)
		return NULL;
	for (i = 0; i < problems->len; i++) {
		problem = g_ptr_array_index (problems, i);
		problem_kind = as_problem_get_kind (problem);
		as_compose_app_log (app,
				    "AppData problem: %s : %s",
				    as_problem_kind_to_string (problem_kind),
				    as_problem_get_message (problem));
	}
	if (problems->len > 0) {
		g_set_error (error,
			     AS_APP_ERROR,
			     AS_APP_ERROR_FAILED,
			     "AppData file %s was not valid",
			     appdata_path);
		return NULL;
	}

	return g_steal_pointer (&app);
}
Ejemplo n.º 25
0
/**
* rpmostree_load_sysroot
* @sysroot: sysroot path
* @force_peer: Force a peer connection
* @cancellable: A GCancellable
* @out_sysroot: (out) Return location for sysroot
* @error: A pointer to a GError pointer.
*
* Returns: True on success
**/
gboolean
rpmostree_load_sysroot (gchar *sysroot,
                        gboolean force_peer,
                        GCancellable *cancellable,
                        RPMOSTreeSysroot **out_sysroot_proxy,
                        GPid *out_peer_pid,
                        GError **error)
{
  const char *bus_name = NULL;
  glnx_unref_object GDBusConnection *connection = NULL;
  glnx_unref_object RPMOSTreeSysroot *sysroot_proxy = NULL;
  g_autoptr(GVariantBuilder) options_builder =
    g_variant_builder_new (G_VARIANT_TYPE ("a{sv}"));
  _cleanup_peer_ GPid peer_pid = 0;

  connection = get_connection_for_path (sysroot, force_peer, &peer_pid,
                                        cancellable, error);
  if (connection == NULL)
    return FALSE;

  if (g_dbus_connection_get_unique_name (connection) != NULL)
    bus_name = BUS_NAME;

  sysroot_proxy = rpmostree_sysroot_proxy_new_sync (connection,
                                                    G_DBUS_PROXY_FLAGS_NONE,
                                                    bus_name,
                                                    "/org/projectatomic/rpmostree1/Sysroot",
                                                    NULL,
                                                    error);
  if (sysroot_proxy == NULL)
    return FALSE;

  /* Try to register if we can; it doesn't matter much now since the daemon doesn't
   * auto-exit, though that might change in the future. But only register if we're active or
   * root; the daemon won't allow it otherwise. */
  uid_t uid = getuid ();
  gboolean should_register;
  if (uid == 0)
    should_register = TRUE;
  else
    {
      g_autofree char *state = NULL;
      if (sd_uid_get_state (uid, &state) >= 0)
        should_register = (g_strcmp0 (state, "active") == 0);
      else
        should_register = FALSE;
    }

  if (should_register)
    {
      if (!rpmostree_sysroot_call_register_client_sync (sysroot_proxy,
                                                        g_variant_builder_end (options_builder),
                                                        cancellable, error))
        return FALSE;
    }

  *out_sysroot_proxy = g_steal_pointer (&sysroot_proxy);
  *out_peer_pid = peer_pid; peer_pid = 0;
  return TRUE;
}
Ejemplo n.º 26
0
/**
 * self: The SeahorseSource to use as server for the uri
 * path: The path to add to the SOUP uri
 *
 * Returns: A #SoupUri with server, port and paths
 */
static SoupURI*
get_http_server_uri (SeahorseHKPSource *self, const char *path)
{
    g_autoptr(SoupURI) uri = NULL;
    g_autofree gchar *server = NULL;
    gchar *port;

    g_object_get (self, "key-server", &server, NULL);
    g_return_val_if_fail (server != NULL, NULL);

    uri = soup_uri_new (NULL);
    soup_uri_set_scheme (uri, SOUP_URI_SCHEME_HTTP);

    /* If it already has a port then use that */
    port = strchr (server, ':');
    if (port) {
        *port++ = '\0';
        soup_uri_set_port (uri, atoi (port));
    } else {
        /* default HKP port */
        soup_uri_set_port (uri, 11371);
    }

    soup_uri_set_host (uri, server);
    soup_uri_set_path (uri, path);

    return g_steal_pointer (&uri);
}
Ejemplo n.º 27
0
static void
on_import_message_complete (SoupSession *session,
                            SoupMessage *message,
                            gpointer user_data)
{
    g_autoptr(GTask) task = G_TASK (user_data);
    source_import_closure *closure = g_task_get_task_data (task);
    g_autoptr(GError) error = NULL;
    g_autofree gchar *errmsg = NULL;

    g_assert (closure->requests > 0);
    seahorse_progress_end (closure->cancellable, GUINT_TO_POINTER (closure->requests));
    closure->requests--;

    if (hkp_message_propagate_error (closure->source, message, &error)) {
        g_task_return_error (task, g_steal_pointer (&error));
        return;
    }

    if ((errmsg = get_send_result (message->response_body->data)) != NULL) {
        g_task_return_new_error (task, HKP_ERROR_DOMAIN, message->status_code,
                                 "%s", errmsg);
        return;
    }

    /* A successful status from the server is all we want in this case */
    if (closure->requests == 0) {
        /* We don't know which keys got imported, so just return NULL */
        g_task_return_pointer (task, NULL, NULL);
    }
}
Ejemplo n.º 28
0
static void
on_search_message_complete (SoupSession *session,
                            SoupMessage *message,
                            gpointer user_data)
{
    g_autoptr(GTask) task = G_TASK (user_data);
    source_search_closure *closure = g_task_get_task_data (task);
    g_autoptr(GError) error = NULL;
    GList *keys, *l;

    seahorse_progress_end (closure->cancellable, message);

    if (hkp_message_propagate_error (closure->source, message, &error)) {
        g_task_return_error (task, g_steal_pointer (&error));
        return;
    }

    keys = parse_hkp_index (message->response_body->data);
    for (l = keys; l; l = g_list_next (l)) {
        g_object_set (l->data, "place", closure->source, NULL);
        gcr_simple_collection_add (closure->results, l->data);
    }
    g_list_free_full (keys, g_object_unref);

    g_task_return_boolean (task, TRUE);
}
Ejemplo n.º 29
0
/* Process a --repo arg; used below, and for the remote builtins */
static OstreeRepo *
parse_repo_option (GOptionContext *context,
                   const char     *repo_path,
                   gboolean        skip_repo_open,
                   GCancellable   *cancellable,
                   GError        **error)
{
  g_autoptr(OstreeRepo) repo = NULL;

  if (repo_path == NULL)
    {
      g_autoptr(GError) local_error = NULL;

      repo = ostree_repo_new_default ();
      if (!ostree_repo_open (repo, cancellable, &local_error))
        {
          if (g_error_matches (local_error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND))
            {
              g_autofree char *help = NULL;

              g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED,
                                   "Command requires a --repo argument");

              help = g_option_context_get_help (context, FALSE, NULL);
              g_printerr ("%s", help);
            }
          else
            {
              g_propagate_error (error, g_steal_pointer (&local_error));
            }
          return NULL;
        }
    }
  else
    {
      g_autoptr(GFile) repo_file = g_file_new_for_path (repo_path);

      repo = ostree_repo_new (repo_file);
      if (!skip_repo_open)
        {
          if (!ostree_repo_open (repo, cancellable, error))
            return NULL;
        }
    }

  return g_steal_pointer (&repo);
}
/* TODO: Docs. Return value is only valid as long as @txt is. Reference: RFC 6763, §6. */
GHashTable *
_ostree_txt_records_parse (AvahiStringList *txt)
{
  AvahiStringList *l;
  g_autoptr(GHashTable) out = NULL;

  out = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, (GDestroyNotify) g_bytes_unref);

  for (l = txt; l != NULL; l = avahi_string_list_get_next (l))
    {
      const guint8 *txt;
      gsize txt_len;
      const gchar *key;
      const guint8 *value;
      gsize key_len, value_len;
      g_autofree gchar *key_allocated = NULL;
      g_autoptr(GBytes) value_allocated = NULL;

      txt = avahi_string_list_get_text (l);
      txt_len = avahi_string_list_get_size (l);

      if (!parse_txt_record (txt, txt_len, &key, &key_len, &value, &value_len))
        {
          g_debug ("Ignoring invalid TXT record of length %" G_GSIZE_FORMAT,
                   txt_len);
          continue;
        }

      key_allocated = g_ascii_strdown (key, key_len);

      if (g_hash_table_lookup_extended (out, key_allocated, NULL, NULL))
        {
          g_debug ("Ignoring duplicate TXT record ‘%s’", key_allocated);
          continue;
        }

      /* Distinguish between the case where the entire record is the key
       * (value == NULL) and the case where the record is the key + ‘=’ and the
       * value is empty (value != NULL && value_len == 0). */
      if (value != NULL)
        value_allocated = g_bytes_new_static (value, value_len);

      g_hash_table_insert (out, g_steal_pointer (&key_allocated), g_steal_pointer (&value_allocated));
    }

  return g_steal_pointer (&out);
}