gboolean flatpak_remote_commit (FlatpakRemote *self, FlatpakDir *dir, GCancellable *cancellable, GError **error) { FlatpakRemotePrivate *priv = flatpak_remote_get_instance_private (self); g_autofree char *url = NULL; g_autoptr(GKeyFile) config = NULL; g_autofree char *group = g_strdup_printf ("remote \"%s\"", priv->name); url = flatpak_remote_get_url (self); if (url == NULL || *url == 0) return flatpak_fail (error, "No url specified"); config = ostree_repo_copy_config (flatpak_dir_get_repo (dir)); if (priv->local_url_set) g_key_file_set_string (config, group, "url", priv->local_url); if (priv->local_title_set) g_key_file_set_string (config, group, "xa.title", priv->local_title); if (priv->local_gpg_verify_set) { g_key_file_set_boolean (config, group, "gpg-verify", priv->local_gpg_verify); g_key_file_set_boolean (config, group, "gpg-verify-summary", priv->local_gpg_verify); } if (priv->local_noenumerate_set) g_key_file_set_boolean (config, group, "xa.noenumerate", priv->local_noenumerate); if (priv->local_disabled_set) g_key_file_set_boolean (config, group, "xa.disable", priv->local_disabled); if (priv->local_prio_set) { g_autofree char *prio_as_string = g_strdup_printf ("%d", priv->local_prio); g_key_file_set_string (config, group, "xa.prio", prio_as_string); } return flatpak_dir_modify_remote (dir, priv->name, config, priv->local_gpg_key, cancellable, error); }
gboolean ostree_builtin_config (int argc, char **argv, GCancellable *cancellable, GError **error) { g_autoptr(GOptionContext) context = NULL; glnx_unref_object OstreeRepo *repo = NULL; gboolean ret = FALSE; const char *op; const char *section_key; const char *value; g_autofree char *section = NULL; g_autofree char *key = NULL; GKeyFile *config = NULL; context = g_option_context_new ("- Change configuration settings"); if (!ostree_option_context_parse (context, options, &argc, &argv, OSTREE_BUILTIN_FLAG_NONE, &repo, cancellable, error)) goto out; if (argc < 2) { ot_util_usage_error (context, "OPERATION must be specified", error); goto out; } op = argv[1]; if (!strcmp (op, "set")) { if (argc < 4) { g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "KEY and VALUE must be specified"); goto out; } section_key = argv[2]; value = argv[3]; if (!split_key_string (section_key, §ion, &key, error)) goto out; config = ostree_repo_copy_config (repo); g_key_file_set_string (config, section, key, value); if (!ostree_repo_write_config (repo, config, error)) goto out; } else if (!strcmp (op, "get")) { GKeyFile *readonly_config = NULL; g_autofree char *value = NULL; if (argc < 3) { g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "KEY must be specified"); goto out; } section_key = argv[2]; if (!split_key_string (section_key, §ion, &key, error)) goto out; readonly_config = ostree_repo_get_config (repo); value = g_key_file_get_string (readonly_config, section, key, error); if (value == NULL) goto out; g_print ("%s\n", value); } else { g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "Unknown operation %s", op); goto out; } ret = TRUE; out: if (config) g_key_file_free (config); return ret; }
static GKeyFile * get_config_from_opts (FlatpakDir *dir, const char *remote_name, gboolean *changed) { OstreeRepo *repo; GKeyFile *config; g_autofree char *group = g_strdup_printf ("remote \"%s\"", remote_name); repo = flatpak_dir_get_repo (dir); if (repo == NULL) config = g_key_file_new (); else config = ostree_repo_copy_config (repo); if (opt_no_gpg_verify) { g_key_file_set_boolean (config, group, "gpg-verify", FALSE); g_key_file_set_boolean (config, group, "gpg-verify-summary", FALSE); *changed = TRUE; } if (opt_do_gpg_verify) { g_key_file_set_boolean (config, group, "gpg-verify", TRUE); g_key_file_set_boolean (config, group, "gpg-verify-summary", TRUE); *changed = TRUE; } if (opt_url) { if (g_str_has_prefix (opt_url, "metalink=")) g_key_file_set_string (config, group, "metalink", opt_url + strlen ("metalink=")); else g_key_file_set_string (config, group, "url", opt_url); *changed = TRUE; } if (opt_collection_id) { g_key_file_set_string (config, group, "collection-id", opt_collection_id); g_key_file_set_boolean (config, group, "gpg-verify-summary", FALSE); *changed = TRUE; } if (opt_title) { g_key_file_set_string (config, group, "xa.title", opt_title); g_key_file_set_boolean (config, group, "xa.title-is-set", TRUE); *changed = TRUE; } if (opt_comment) { g_key_file_set_string (config, group, "xa.comment", opt_comment); g_key_file_set_boolean (config, group, "xa.comment-is-set", TRUE); *changed = TRUE; } if (opt_description) { g_key_file_set_string (config, group, "xa.description", opt_description); g_key_file_set_boolean (config, group, "xa.description-is-set", TRUE); *changed = TRUE; } if (opt_homepage) { g_key_file_set_string (config, group, "xa.homepage", opt_homepage); g_key_file_set_boolean (config, group, "xa.homepage-is-set", TRUE); *changed = TRUE; } if (opt_icon) { g_key_file_set_string (config, group, "xa.icon", opt_icon); g_key_file_set_boolean (config, group, "xa.icon-is-set", TRUE); *changed = TRUE; } if (opt_default_branch) { g_key_file_set_string (config, group, "xa.default-branch", opt_default_branch); g_key_file_set_boolean (config, group, "xa.default-branch-is-set", TRUE); *changed = TRUE; } if (opt_no_enumerate) { g_key_file_set_boolean (config, group, "xa.noenumerate", TRUE); *changed = TRUE; } if (opt_do_enumerate) { g_key_file_set_boolean (config, group, "xa.noenumerate", FALSE); *changed = TRUE; } if (opt_no_deps) { g_key_file_set_boolean (config, group, "xa.nodeps", TRUE); *changed = TRUE; } if (opt_do_deps) { g_key_file_set_boolean (config, group, "xa.nodeps", FALSE); *changed = TRUE; } if (opt_disable) { g_key_file_set_boolean (config, group, "xa.disable", TRUE); *changed = TRUE; } if (opt_prio != -1) { g_autofree char *prio_as_string = g_strdup_printf ("%d", opt_prio); g_key_file_set_string (config, group, "xa.prio", prio_as_string); *changed = TRUE; } if (comment) { g_key_file_set_string (config, group, "xa.comment", comment); g_key_file_set_boolean (config, group, "xa.comment-is-set", TRUE); *changed = TRUE; } if (description) { g_key_file_set_string (config, group, "xa.description", description); g_key_file_set_boolean (config, group, "xa.description-is-set", TRUE); *changed = TRUE; } if (icon) { g_key_file_set_string (config, group, "xa.icon", icon); g_key_file_set_boolean (config, group, "xa.icon-is-set", TRUE); *changed = TRUE; } if (homepage) { g_key_file_set_string (config, group, "xa.homepage", homepage); g_key_file_set_boolean (config, group, "xa.homepage-is-set", TRUE); *changed = TRUE; } return config; }
gboolean ostree_builtin_remote (int argc, char **argv, OstreeRepo *repo, GCancellable *cancellable, GError **error) { GOptionContext *context; gboolean ret = FALSE; const char *op; gs_free char *key = NULL; guint i; GKeyFile *config = NULL; const char *remote_name; context = g_option_context_new ("OPERATION NAME [args] - Control remote repository configuration"); g_option_context_add_main_entries (context, options, NULL); if (!g_option_context_parse (context, &argc, &argv, error)) goto out; if (argc < 3) { if (argc == 1) usage_error (context, "OPERATION must be specified", error); else usage_error (context, "NAME must be specified", error); goto out; } op = argv[1]; remote_name = argv[2]; key = g_strdup_printf ("remote \"%s\"", remote_name); config = ostree_repo_copy_config (repo); if (!strcmp (op, "add")) { const char *url = argv[3]; gs_unref_object GFile *etc_ostree_remotes_d = g_file_new_for_path (SYSCONFDIR "/ostree/remotes.d"); gs_free char *target_name = NULL; gs_unref_object GFile *target_conf = NULL; local_cleanup_keyfile GKeyFile *new_keyfile = NULL; GKeyFile *target_keyfile = NULL; gs_unref_ptrarray GPtrArray *branches = NULL; if (strchr (remote_name, '/') != NULL) { g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "Invalid character '/' in remote name: %s", remote_name); goto out; } if (argc < 4) { usage_error (context, "URL must be specified", error); goto out; } branches = g_ptr_array_new (); for (i = 4; i < argc; i++) g_ptr_array_add (branches, argv[i]); if (ostree_repo_is_system (repo)) { new_keyfile = g_key_file_new (); target_keyfile = new_keyfile; target_name = g_strconcat (remote_name, ".conf", NULL); target_conf = g_file_get_child (etc_ostree_remotes_d, target_name); if (g_file_query_exists (target_conf, NULL)) { g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "Remote configuration already exists: %s", gs_file_get_path_cached (target_conf)); goto out; } } else { target_keyfile = config; } if (!add_remote_to_keyfile (target_keyfile, key, url, branches, error)) goto out; /* For the system repository, write to /etc/ostree/remotes.d */ if (ostree_repo_is_system (repo)) { gsize len; gs_free char *data = g_key_file_to_data (target_keyfile, &len, error); if (!g_file_replace_contents (target_conf, data, len, NULL, FALSE, 0, NULL, cancellable, error)) goto out; } else { if (!ostree_repo_write_config (repo, config, error)) goto out; } } else if (!strcmp (op, "show-url")) { gs_free char *url = NULL; url = g_key_file_get_string (config, key, "url", error); if (url == NULL) goto out; g_print ("%s\n", url); } else { usage_error (context, "Unknown operation", error); goto out; } ret = TRUE; out: if (context) g_option_context_free (context); if (config) g_key_file_free (config); return ret; }
gboolean ostree_builtin_config (int argc, char **argv, OstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error) { g_autoptr(GOptionContext) context = NULL; g_autoptr(OstreeRepo) repo = NULL; gboolean ret = FALSE; const char *op; const char *section_key; const char *value; g_autofree char *section = NULL; g_autofree char *key = NULL; GKeyFile *config = NULL; context = g_option_context_new ("(get KEY|set KEY VALUE)"); if (!ostree_option_context_parse (context, options, &argc, &argv, invocation, &repo, cancellable, error)) goto out; if (argc < 2) { ot_util_usage_error (context, "OPERATION must be specified", error); goto out; } op = argv[1]; if (!strcmp (op, "set")) { if (opt_group) { if (argc < 4) { g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "GROUP name, KEY and VALUE must be specified"); goto out; } section = g_strdup(opt_group); key = g_strdup(argv[2]); value = argv[3]; } else { if (argc < 4) { g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "KEY and VALUE must be specified"); goto out; } section_key = argv[2]; value = argv[3]; if(!split_key_string (section_key, §ion, &key, error)) goto out; } config = ostree_repo_copy_config (repo); g_key_file_set_string (config, section, key, value); if (!ostree_repo_write_config (repo, config, error)) goto out; } else if (!strcmp (op, "get")) { GKeyFile *readonly_config = NULL; g_autofree char *value = NULL; if (opt_group) { if (argc < 3) { g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "Group name and key must be specified"); goto out; } section = g_strdup(opt_group); key = g_strdup(argv[2]); } else { if(argc < 3) { g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "KEY must be specified"); goto out; } section_key = argv[2]; if (!split_key_string (section_key, §ion, &key, error)) goto out; } readonly_config = ostree_repo_get_config (repo); value = g_key_file_get_string (readonly_config, section, key, error); if (value == NULL) goto out; g_print ("%s\n", value); } else { g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "Unknown operation %s", op); goto out; } ret = TRUE; out: if (config) g_key_file_free (config); return ret; }
gboolean ostree_builtin_remote (int argc, char **argv, GFile *repo_path, GError **error) { GOptionContext *context; gboolean ret = FALSE; const char *op; guint i; ot_lobj OstreeRepo *repo = NULL; ot_lptrarray GPtrArray *branches = NULL; GKeyFile *config = NULL; context = g_option_context_new ("OPERATION [args] - Control remote repository configuration"); g_option_context_add_main_entries (context, options, NULL); if (!g_option_context_parse (context, &argc, &argv, error)) goto out; repo = ostree_repo_new (repo_path); if (!ostree_repo_check (repo, error)) goto out; if (argc < 2) { usage_error (context, "OPERATION must be specified", error); goto out; } op = argv[1]; config = ostree_repo_copy_config (repo); if (!strcmp (op, "add")) { char *key; if (argc < 4) { usage_error (context, "NAME and URL must be specified", error); goto out; } branches = g_ptr_array_new (); for (i = 4; i < argc; i++) g_ptr_array_add (branches, argv[i]); key = g_strdup_printf ("remote \"%s\"", argv[2]); g_key_file_set_string (config, key, "url", argv[3]); if (branches->len > 0) g_key_file_set_string_list (config, key, "branches", (const char *const *)branches->pdata, branches->len); g_free (key); } else { usage_error (context, "Unknown operation", error); goto out; } if (!ostree_repo_write_config (repo, config, error)) goto out; ret = TRUE; out: if (context) g_option_context_free (context); if (config) g_key_file_free (config); return ret; }