static GVariant * get_args_variant (void) { GVariantDict dict; g_variant_dict_init (&dict, NULL); g_variant_dict_insert (&dict, "reboot", "b", opt_reboot); g_variant_dict_insert (&dict, "dry-run", "b", opt_dry_run); #if 0 if (opt_no_scripts) g_variant_dict_insert (&dict, "noscripts", "b", TRUE); if (opt_ignore_script) g_variant_dict_insert (&dict, "ignore-scripts", "^as", opt_ignore_script); #endif return g_variant_dict_end (&dict); }
static GVariant * track_cursor_to_variant_dict (TrackerSparqlCursor *const cursor) { GVariantDict dict; g_variant_dict_init (&dict, NULL); insert_string_value (cursor, &dict, "urn", 0); insert_integer_value (cursor, &dict, "id", 1); insert_string_value (cursor, &dict, "url", 2); insert_string_value (cursor, &dict, "title", 3); insert_integer_value (cursor, &dict, "track-number", 4); insert_integer_value (cursor, &dict, "disc-number", 5); return g_variant_dict_end (&dict); }
GVariant* rpmostree_get_options_variant (gboolean reboot, gboolean allow_downgrade, gboolean skip_purge, gboolean no_pull_base, gboolean dry_run, gboolean no_overrides) { GVariantDict dict; g_variant_dict_init (&dict, NULL); g_variant_dict_insert (&dict, "reboot", "b", reboot); g_variant_dict_insert (&dict, "allow-downgrade", "b", allow_downgrade); g_variant_dict_insert (&dict, "skip-purge", "b", skip_purge); g_variant_dict_insert (&dict, "no-pull-base", "b", no_pull_base); g_variant_dict_insert (&dict, "dry-run", "b", dry_run); g_variant_dict_insert (&dict, "no-overrides", "b", no_overrides); return g_variant_ref_sink (g_variant_dict_end (&dict)); }
static gboolean do_update_step (UpdateStep step, EosUpdater *proxy) { gpointer step_data = GINT_TO_POINTER (step); /* Don't do more of the process than configured */ if (step > last_automatic_step) return FALSE; switch (step) { case UPDATE_STEP_POLL: /* Don't poll more than once, or we will get stuck in a loop */ if (polled_already) return FALSE; /* TODO: What to do with the volume code path? */ polled_already = TRUE; if (volume_path != NULL) eos_updater_call_poll_volume (proxy, volume_path, NULL, update_step_callback, step_data); else eos_updater_call_poll (proxy, NULL, update_step_callback, step_data); break; case UPDATE_STEP_FETCH: { g_auto(GVariantDict) options_dict = G_VARIANT_DICT_INIT (NULL); g_variant_dict_insert (&options_dict, "force", "b", force_update); eos_updater_call_fetch_full (proxy, g_variant_dict_end (&options_dict), NULL, update_step_callback, step_data); break; } case UPDATE_STEP_APPLY: eos_updater_call_apply (proxy, NULL, update_step_callback, step_data); break; case UPDATE_STEP_NONE: default: g_assert_not_reached (); } return TRUE; }
static gboolean get_modifiers_variant (const char *set_refspec, const char *set_revision, const char *const* install_pkgs, const char *const* uninstall_pkgs, const char *const* override_replace_pkgs, const char *const* override_remove_pkgs, const char *const* override_reset_pkgs, GVariant **out_modifiers, GUnixFDList **out_fd_list, GError **error) { GVariantDict dict; g_variant_dict_init (&dict, NULL); g_autoptr(GUnixFDList) fd_list = g_unix_fd_list_new (); if (install_pkgs) { if (!vardict_sort_and_insert_pkgs (&dict, "install", fd_list, install_pkgs, error)) return FALSE; } if (override_replace_pkgs) { if (!vardict_sort_and_insert_pkgs (&dict, "override-replace", fd_list, override_replace_pkgs, error)) return FALSE; } if (set_refspec) g_variant_dict_insert (&dict, "set-refspec", "s", set_refspec); if (set_revision) g_variant_dict_insert (&dict, "set-revision", "s", set_revision); vardict_insert_strv (&dict, "uninstall-packages", uninstall_pkgs); vardict_insert_strv (&dict, "override-remove-packages", override_remove_pkgs); vardict_insert_strv (&dict, "override-reset-packages", override_reset_pkgs); *out_fd_list = g_steal_pointer (&fd_list); *out_modifiers = g_variant_ref_sink (g_variant_dict_end (&dict)); return TRUE; }
GVariant * rpmostreed_deployment_generate_variant (OstreeDeployment *deployment, OstreeRepo *repo) { g_autoptr(GVariant) commit = NULL; g_autofree gchar *origin_refspec = NULL; g_autofree gchar *version_commit = NULL; g_autofree gchar *id = NULL; GVariant *sigs = NULL; /* floating variant */ GError *error = NULL; GVariantDict dict; guint64 timestamp = 0; const gchar *osname = ostree_deployment_get_osname (deployment); const gchar *csum = ostree_deployment_get_csum (deployment); gint serial = ostree_deployment_get_deployserial (deployment); id = rpmostreed_deployment_generate_id (deployment); if (ostree_repo_load_variant (repo, OSTREE_OBJECT_TYPE_COMMIT, csum, &commit, &error)) { g_autoptr(GVariant) metadata = NULL; timestamp = ostree_commit_get_timestamp (commit); metadata = g_variant_get_child_value (commit, 0); if (metadata != NULL) g_variant_lookup (metadata, "version", "s", &version_commit); } else { g_warning ("Error loading commit %s", error->message); } g_clear_error (&error); origin_refspec = rpmostreed_deployment_get_refspec (deployment); if (origin_refspec) sigs = rpmostreed_deployment_gpg_results (repo, origin_refspec, csum); g_variant_dict_init (&dict, NULL); g_variant_dict_insert (&dict, "id", "s", id); if (osname != NULL) g_variant_dict_insert (&dict, "osname", "s", osname); g_variant_dict_insert (&dict, "serial", "i", serial); g_variant_dict_insert (&dict, "checksum", "s", csum); if (version_commit != NULL) g_variant_dict_insert (&dict, "version", "s", version_commit); if (timestamp > 0) g_variant_dict_insert (&dict, "timestamp", "t", timestamp); if (origin_refspec != NULL) g_variant_dict_insert (&dict, "origin", "s", origin_refspec); if (sigs != NULL) g_variant_dict_insert_value (&dict, "signatures", sigs); return g_variant_dict_end (&dict); }
static void abrt_p2_task_finish_gtask(GObject *source_object, GAsyncResult *result, gpointer user_data) { AbrtP2Task *task = ABRT_P2_TASK(source_object); if (!g_task_is_valid(result, task)) { error_msg("BUG:%s:%s: invalid GTask", __FILE__, __func__); return; } GError *error = NULL; const gint32 code = g_task_propagate_int(G_TASK(result), &error); if (code == ABRT_P2_TASK_CODE_STOP) { log_debug("Task stopped"); abrt_p2_task_change_status(task, ABRT_P2_TASK_STATUS_STOPPED); } else if (code >= ABRT_P2_TASK_CODE_DONE) { log_debug("Task done"); task->pv->p2t_code = code - ABRT_P2_TASK_CODE_DONE; abrt_p2_task_change_status(task, ABRT_P2_TASK_STATUS_DONE); } else if (abrt_p2_task_is_cancelled(task)) { if (error != NULL) { log_debug("Task canceled with error: %s", error->message); g_error_free(error); error = NULL; } else log_debug("Task canceled"); ABRT_P2_TASK_VIRTUAL_CANCEL(task, &error); abrt_p2_task_change_status(task, ABRT_P2_TASK_STATUS_CANCELED); } else { GVariantDict response; g_variant_dict_init(&response, NULL); if (error != NULL) { log_debug("Task failed with error: %s", error->message); g_variant_dict_insert(&response, "Error.Message", "s", error->message); g_error_free(error); } else if (code == ABRT_P2_TASK_CODE_ERROR) { log_debug("Task failed without error message"); g_variant_dict_insert(&response, "Error.Message", "s", "Task failed"); } else { error_msg("BUG:%s:%s: unknown Task return code: %d", __FILE__, __func__, code); g_variant_dict_insert(&response, "Error.Message", "s", "Internal error: Invalid Task return code"); } abrt_p2_task_set_response(task, g_variant_dict_end(&response)); abrt_p2_task_change_status(task, ABRT_P2_TASK_STATUS_FAILED); } g_object_unref(task->pv->p2t_cancellable); task->pv->p2t_cancellable = NULL; }
GVariant * rpmostreed_deployment_generate_variant (OstreeDeployment *deployment, const char *booted_id, OstreeRepo *repo, GError **error) { g_autoptr(GVariant) commit = NULL; g_autoptr(RpmOstreeOrigin) origin = NULL; g_autofree gchar *id = NULL; GVariant *sigs = NULL; /* floating variant */ GVariantDict dict; const gchar *osname = ostree_deployment_get_osname (deployment); const gchar *csum = ostree_deployment_get_csum (deployment); gint serial = ostree_deployment_get_deployserial (deployment); gboolean gpg_enabled = FALSE; if (!ostree_repo_load_variant (repo, OSTREE_OBJECT_TYPE_COMMIT, csum, &commit, error)) return NULL; id = rpmostreed_deployment_generate_id (deployment); origin = rpmostree_origin_parse_deployment (deployment, error); if (!origin) return NULL; g_variant_dict_init (&dict, NULL); g_variant_dict_insert (&dict, "id", "s", id); if (osname != NULL) g_variant_dict_insert (&dict, "osname", "s", osname); g_variant_dict_insert (&dict, "serial", "i", serial); g_variant_dict_insert (&dict, "checksum", "s", csum); if (rpmostree_origin_is_locally_assembled (origin)) { const char *parent = ostree_commit_get_parent (commit); g_assert (parent); g_variant_dict_insert (&dict, "base-checksum", "s", parent); sigs = rpmostreed_deployment_gpg_results (repo, rpmostree_origin_get_refspec (origin), parent, &gpg_enabled); } else sigs = rpmostreed_deployment_gpg_results (repo, rpmostree_origin_get_refspec (origin), csum, &gpg_enabled); variant_add_commit_details (&dict, commit); g_variant_dict_insert (&dict, "origin", "s", rpmostree_origin_get_refspec (origin)); if (rpmostree_origin_get_packages (origin) != NULL) g_variant_dict_insert (&dict, "packages", "^as", rpmostree_origin_get_packages (origin)); if (sigs != NULL) g_variant_dict_insert_value (&dict, "signatures", sigs); g_variant_dict_insert (&dict, "gpg-enabled", "b", gpg_enabled); g_variant_dict_insert (&dict, "unlocked", "s", ostree_deployment_unlocked_state_to_string (ostree_deployment_get_unlocked (deployment))); if (booted_id != NULL) g_variant_dict_insert (&dict, "booted", "b", g_strcmp0 (booted_id, id) == 0); return g_variant_dict_end (&dict); }
static gboolean rewrite_delta (OstreeRepo *src_repo, const char *src_commit, OstreeRepo *dst_repo, const char *dst_commit, GVariant *dst_commitv, const char *from, GError **error) { g_autoptr(GFile) src_delta_file = NULL; g_autoptr(GFile) dst_delta_file = NULL; g_autofree char *src_detached_key = _ostree_get_relative_static_delta_path (from, src_commit, "commitmeta"); g_autofree char *dst_detached_key = _ostree_get_relative_static_delta_path (from, dst_commit, "commitmeta"); g_autofree char *src_delta_dir = _ostree_get_relative_static_delta_path (from, src_commit, NULL); g_autofree char *dst_delta_dir = _ostree_get_relative_static_delta_path (from, dst_commit, NULL); g_autofree char *src_superblock_path = _ostree_get_relative_static_delta_path (from, src_commit, "superblock"); g_autofree char *dst_superblock_path = _ostree_get_relative_static_delta_path (from, dst_commit, "superblock"); GMappedFile *mfile = NULL; g_auto(GVariantBuilder) superblock_builder = FLATPAK_VARIANT_BUILDER_INITIALIZER; g_autoptr(GVariant) src_superblock = NULL; g_autoptr(GVariant) dst_superblock = NULL; g_autoptr(GBytes) bytes = NULL; g_autoptr(GVariant) dst_detached = NULL; g_autoptr(GVariant) src_metadata = NULL; g_autoptr(GVariant) src_recurse = NULL; g_autoptr(GVariant) src_parts = NULL; g_auto(GVariantDict) dst_metadata_dict = FLATPAK_VARIANT_DICT_INITIALIZER; int i; src_delta_file = g_file_resolve_relative_path (ostree_repo_get_path (src_repo), src_superblock_path); mfile = g_mapped_file_new (flatpak_file_get_path_cached (src_delta_file), FALSE, NULL); if (mfile == NULL) return TRUE; /* No superblock, not an error */ bytes = g_mapped_file_get_bytes (mfile); g_mapped_file_unref (mfile); src_superblock = g_variant_ref_sink (g_variant_new_from_bytes (G_VARIANT_TYPE (OSTREE_STATIC_DELTA_SUPERBLOCK_FORMAT), bytes, FALSE)); src_metadata = g_variant_get_child_value (src_superblock, 0); src_recurse = g_variant_get_child_value (src_superblock, 5); src_parts = g_variant_get_child_value (src_superblock, 6); if (g_variant_n_children (src_recurse) != 0) return flatpak_fail (error, "Recursive deltas not supported, ignoring"); g_variant_builder_init (&superblock_builder, G_VARIANT_TYPE (OSTREE_STATIC_DELTA_SUPERBLOCK_FORMAT)); g_variant_dict_init (&dst_metadata_dict, src_metadata); g_variant_dict_remove (&dst_metadata_dict, src_detached_key); if (ostree_repo_read_commit_detached_metadata (dst_repo, dst_commit, &dst_detached, NULL, NULL) && dst_detached != NULL) g_variant_dict_insert_value (&dst_metadata_dict, dst_detached_key, dst_detached); g_variant_builder_add_value (&superblock_builder, g_variant_dict_end (&dst_metadata_dict)); g_variant_builder_add_value (&superblock_builder, g_variant_get_child_value (src_superblock, 1)); /* timestamp */ g_variant_builder_add_value (&superblock_builder, from ? ostree_checksum_to_bytes_v (from) : new_bytearray ((guchar *) "", 0)); g_variant_builder_add_value (&superblock_builder, ostree_checksum_to_bytes_v (dst_commit)); g_variant_builder_add_value (&superblock_builder, dst_commitv); g_variant_builder_add_value (&superblock_builder, src_recurse); g_variant_builder_add_value (&superblock_builder, src_parts); g_variant_builder_add_value (&superblock_builder, g_variant_get_child_value (src_superblock, 7)); /* fallback */ dst_superblock = g_variant_ref_sink (g_variant_builder_end (&superblock_builder)); if (!glnx_shutil_mkdir_p_at (ostree_repo_get_dfd (dst_repo), dst_delta_dir, 0755, NULL, error)) return FALSE; for (i = 0; i < g_variant_n_children (src_parts); i++) { g_autofree char *src_part_path = g_strdup_printf ("%s/%d", src_delta_dir, i); g_autofree char *dst_part_path = g_strdup_printf ("%s/%d", dst_delta_dir, i); if (!glnx_file_copy_at (ostree_repo_get_dfd (src_repo), src_part_path, NULL, ostree_repo_get_dfd (dst_repo), dst_part_path, GLNX_FILE_COPY_OVERWRITE | GLNX_FILE_COPY_NOXATTRS, NULL, error)) return FALSE; } dst_delta_file = g_file_resolve_relative_path (ostree_repo_get_path (dst_repo), dst_superblock_path); if (!flatpak_variant_save (dst_delta_file, dst_superblock, NULL, error)) return FALSE; return TRUE; }
/** * rpmostreed_repo_pull_ancestry: * @repo: Repo * @refspec: Repository branch * @visitor: (allow-none): Visitor function to call on each commit * @visitor_data: (allow-none): User data for @visitor * @progress: (allow-none): Progress * @cancellable: Cancellable * @error: Error * * Downloads an ancestry of commit objects starting from @refspec. * * If a @visitor function pointer is given, commit objects are downloaded * in batches and the @visitor function is called for each commit object. * The @visitor function can stop the recursion, such as when looking for * a particular commit. * * Returns: %TRUE on success, %FALSE on failure */ gboolean rpmostreed_repo_pull_ancestry (OstreeRepo *repo, const char *refspec, RpmostreedCommitVisitor visitor, gpointer visitor_data, OstreeAsyncProgress *progress, GCancellable *cancellable, GError **error) { OstreeRepoPullFlags flags; GVariantDict options; GVariant *refs_value; const char *refs_array[] = { NULL, NULL }; g_autofree char *remote = NULL; g_autofree char *ref = NULL; g_autofree char *checksum = NULL; int depth, ii; gboolean ret = FALSE; g_return_val_if_fail (OSTREE_IS_REPO (repo), FALSE); g_return_val_if_fail (refspec != NULL, FALSE); if (!ostree_parse_refspec (refspec, &remote, &ref, error)) goto out; /* If no visitor function was provided then we won't be short-circuiting * the recursion, so pull everything in one shot. Otherwise pull commits * in increasingly large batches. */ depth = (visitor != NULL) ? 10 : -1; flags = OSTREE_REPO_PULL_FLAGS_COMMIT_ONLY; /* It's important to use the ref name instead of a checksum on the first * pass because we want to search from the latest available commit on the * remote server, which is not necessarily what the ref name is currently * pointing at in our local repo. */ refs_array[0] = ref; while (TRUE) { /* Floating reference, transferred to dictionary. */ refs_value = g_variant_new_strv ((const char * const *) refs_array, -1); g_variant_dict_init (&options, NULL); g_variant_dict_insert (&options, "depth", "i", depth); g_variant_dict_insert (&options, "flags", "i", flags); g_variant_dict_insert_value (&options, "refs", refs_value); if (!ostree_repo_pull_with_options (repo, remote, g_variant_dict_end (&options), progress, cancellable, error)) goto out; /* First pass only. Now we can resolve the ref to a checksum. */ if (checksum == NULL) { if (!ostree_repo_resolve_rev (repo, ref, FALSE, &checksum, error)) goto out; } /* If depth is negative (no visitor), this loop is skipped. */ for (ii = 0; ii < depth && checksum != NULL; ii++) { g_autoptr(GVariant) commit = NULL; gboolean stop = FALSE; if (!ostree_repo_load_commit (repo, checksum, &commit, NULL, error)) goto out; if (!visitor (repo, checksum, commit, visitor_data, &stop, error)) goto out; g_clear_pointer (&checksum, g_free); if (!stop) checksum = ostree_commit_get_parent (commit); } /* Break if no visitor, or visitor told us to stop. */ if (depth < 0 || checksum == NULL) break; /* Pull the next batch of commits, twice as many. */ refs_array[0] = checksum; depth = depth * 2; } ret = TRUE; out: return ret; }
static gboolean pkg_change (RpmOstreeCommandInvocation *invocation, RPMOSTreeSysroot *sysroot_proxy, const char *const* packages_to_add, const char *const* packages_to_remove, GCancellable *cancellable, GError **error) { const char *const strv_empty[] = { NULL }; if (!packages_to_add) packages_to_add = strv_empty; if (!packages_to_remove) packages_to_remove = strv_empty; glnx_unref_object RPMOSTreeOS *os_proxy = NULL; if (!rpmostree_load_os_proxy (sysroot_proxy, opt_osname, cancellable, &os_proxy, error)) return FALSE; g_autoptr(GVariant) previous_deployment = rpmostree_os_dup_default_deployment (os_proxy); GVariantDict dict; g_variant_dict_init (&dict, NULL); g_variant_dict_insert (&dict, "reboot", "b", opt_reboot); g_variant_dict_insert (&dict, "cache-only", "b", opt_cache_only); g_variant_dict_insert (&dict, "download-only", "b", opt_download_only); g_variant_dict_insert (&dict, "no-pull-base", "b", TRUE); g_variant_dict_insert (&dict, "dry-run", "b", opt_dry_run); g_variant_dict_insert (&dict, "allow-inactive", "b", opt_allow_inactive); g_variant_dict_insert (&dict, "no-layering", "b", opt_uninstall_all); g_autoptr(GVariant) options = g_variant_ref_sink (g_variant_dict_end (&dict)); gboolean met_local_pkg = FALSE; for (const char *const* it = packages_to_add; it && *it; it++) met_local_pkg = met_local_pkg || g_str_has_suffix (*it, ".rpm"); /* Use newer D-Bus API only if we have to. */ g_autofree char *transaction_address = NULL; if (met_local_pkg) { if (!rpmostree_update_deployment (os_proxy, NULL, /* refspec */ NULL, /* revision */ packages_to_add, packages_to_remove, NULL, /* override replace */ NULL, /* override remove */ NULL, /* override reset */ options, &transaction_address, cancellable, error)) return FALSE; } else { if (!rpmostree_os_call_pkg_change_sync (os_proxy, options, packages_to_add, packages_to_remove, NULL, &transaction_address, NULL, cancellable, error)) return FALSE; } return rpmostree_transaction_client_run (invocation, sysroot_proxy, os_proxy, options, FALSE, transaction_address, previous_deployment, cancellable, error); }