diff options
author | Alexander Larsson <alexl@redhat.com> | 2016-05-11 15:43:40 +0200 |
---|---|---|
committer | Alexander Larsson <alexl@redhat.com> | 2016-05-11 15:43:40 +0200 |
commit | 9e4bb25b2c389263bc146f5393f62ad0e1348df2 (patch) | |
tree | 6298851c67a3536cf8122394fa58d24cbb4eb406 /app | |
parent | e6f6959afbae80ac7ab4f8f70ea6cdea1e5f15cd (diff) | |
download | xdg-app-9e4bb25b2c389263bc146f5393f62ad0e1348df2.tar.gz |
modify-remote: Move the actual config rewriting to FlatpakDir
This is in preparation for doing this in the system helper.
Diffstat (limited to 'app')
-rw-r--r-- | app/flatpak-builtins-add-remote.c | 40 |
1 files changed, 31 insertions, 9 deletions
diff --git a/app/flatpak-builtins-add-remote.c b/app/flatpak-builtins-add-remote.c index fe6b7b8..5186f63 100644 --- a/app/flatpak-builtins-add-remote.c +++ b/app/flatpak-builtins-add-remote.c @@ -118,6 +118,29 @@ open_source_stream (GInputStream **out_source_stream, return TRUE; } +GBytes * +load_keys (GCancellable *cancellable, + GError **error) +{ + g_autoptr(GInputStream) input_stream = NULL; + g_autoptr(GOutputStream) output_stream = NULL; + gssize n_bytes_written; + + if (!open_source_stream (&input_stream, cancellable, error)) + return FALSE; + + output_stream = g_memory_output_stream_new_resizable (); + + n_bytes_written = g_output_stream_splice (output_stream, input_stream, + G_OUTPUT_STREAM_SPLICE_CLOSE_SOURCE | + G_OUTPUT_STREAM_SPLICE_CLOSE_TARGET, + NULL, error); + if (n_bytes_written < 0) + return NULL; + + return g_memory_output_stream_steal_as_bytes (G_MEMORY_OUTPUT_STREAM (output_stream)); +} + gboolean import_keys (FlatpakDir *dir, const char *remote_name, @@ -270,6 +293,7 @@ flatpak_builtin_modify_remote (int argc, char **argv, GCancellable *cancellable, g_autoptr(FlatpakDir) dir = NULL; g_autoptr(GVariantBuilder) optbuilder = NULL; g_autoptr(GKeyFile) config = NULL; + g_autoptr(GBytes) gpg_data = NULL; const char *remote_name; g_autofree char *group = NULL; @@ -329,14 +353,12 @@ flatpak_builtin_modify_remote (int argc, char **argv, GCancellable *cancellable, g_key_file_set_string (config, group, "xa.prio", prio_as_string); } - if (!ostree_repo_write_config (flatpak_dir_get_repo (dir), config, error)) - return FALSE; - - if (!import_keys (dir, remote_name, cancellable, error)) - return FALSE; - - if (!flatpak_dir_mark_changed (dir, error)) - return FALSE; + if (opt_gpg_import != NULL) + { + gpg_data = load_keys (cancellable, error); + if (gpg_data == NULL) + return FALSE; + } - return TRUE; + return flatpak_dir_modify_remove (dir, remote_name, config, gpg_data, cancellable, error); } |