/* Check that a given commit object is valid for the ref it was looked up via. * @collection_id will be %NULL for normal refs, and non-%NULL for collection–refs. */ static gboolean fsck_commit_for_ref (OstreeRepo *repo, const char *checksum, const char *collection_id, const char *ref_name, gboolean *found_corruption, GCancellable *cancellable, GError **error) { if (!fsck_one_object (repo, checksum, OSTREE_OBJECT_TYPE_COMMIT, NULL, NULL, found_corruption, cancellable, error)) return FALSE; /* Check the commit exists. */ g_autoptr(GVariant) commit = NULL; if (!ostree_repo_load_variant (repo, OSTREE_OBJECT_TYPE_COMMIT, checksum, &commit, error)) { if (collection_id != NULL) return glnx_prefix_error (error, "Loading commit for ref (%s, %s)", collection_id, ref_name); else return glnx_prefix_error (error, "Loading commit for ref %s", ref_name); } /* Check its bindings. */ if (opt_verify_bindings) { if (!ostree_cmd__private__ ()->ostree_repo_verify_bindings (collection_id, ref_name, commit, error)) return glnx_prefix_error (error, "Commit %s", checksum); } return TRUE; }
gboolean ot_admin_instutil_builtin_grub2_generate (int argc, char **argv, GCancellable *cancellable, GError **error) { gboolean ret = FALSE; guint bootversion; g_autoptr(GOptionContext) context = NULL; glnx_unref_object OstreeSysroot *sysroot = NULL; context = g_option_context_new ("[BOOTVERSION] - generate GRUB2 configuration from given BLS entries"); if (!ostree_admin_option_context_parse (context, options, &argc, &argv, OSTREE_ADMIN_BUILTIN_FLAG_SUPERUSER | OSTREE_ADMIN_BUILTIN_FLAG_UNLOCKED, &sysroot, cancellable, error)) goto out; if (!ostree_sysroot_load (sysroot, cancellable, error)) goto out; if (argc >= 2) { bootversion = (guint) g_ascii_strtoull (argv[1], NULL, 10); if (!(bootversion == 0 || bootversion == 1)) { g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "Invalid bootversion: %u", bootversion); goto out; } } else { const char *bootversion_env = g_getenv ("_OSTREE_GRUB2_BOOTVERSION"); if (bootversion_env) bootversion = g_ascii_strtoull (bootversion_env, NULL, 10); else bootversion = ostree_sysroot_get_bootversion (sysroot); g_assert (bootversion == 0 || bootversion == 1); } if (!ostree_cmd__private__()->ostree_generate_grub2_config (sysroot, bootversion, 1, cancellable, error)) goto out; ret = TRUE; out: return ret; }
/* Called by ostree-finalize-staged.service, and in turn * invokes a cmdprivate function inside the shared library. */ gboolean ot_admin_builtin_finalize_staged (int argc, char **argv, OstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error) { /* Just a sanity check; we shouldn't be called outside of the service though. */ struct stat stbuf; if (fstatat (AT_FDCWD, "/run/ostree-booted", &stbuf, 0) < 0) return TRUE; g_autoptr(GFile) sysroot_file = g_file_new_for_path ("/"); g_autoptr(OstreeSysroot) sysroot = ostree_sysroot_new (sysroot_file); if (!ostree_sysroot_load (sysroot, cancellable, error)) return FALSE; if (!ostree_cmd__private__()->ostree_finalize_staged (sysroot, cancellable, error)) return FALSE; return TRUE; }