diff --git a/src/libostree/ostree-bootloader-uboot.c b/src/libostree/ostree-bootloader-uboot.c index 5a51aae6..81791e1c 100644 --- a/src/libostree/ostree-bootloader-uboot.c +++ b/src/libostree/ostree-bootloader-uboot.c @@ -29,12 +29,13 @@ #include +static const char uboot_config_path[] = "boot/loader/uEnv.txt"; + struct _OstreeBootloaderUboot { GObject parent_instance; OstreeSysroot *sysroot; - GFile *config_path; }; typedef GObjectClass OstreeBootloaderUbootClass; @@ -50,8 +51,11 @@ _ostree_bootloader_uboot_query (OstreeBootloader *bootloader, GError **error) { OstreeBootloaderUboot *self = OSTREE_BOOTLOADER_UBOOT (bootloader); + struct stat stbuf; - *out_is_active = g_file_query_file_type (self->config_path, G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, NULL) == G_FILE_TYPE_REGULAR; + if (!glnx_fstatat_allow_noent (self->sysroot->sysroot_fd, uboot_config_path, &stbuf, AT_SYMLINK_NOFOLLOW, error)) + return FALSE; + *out_is_active = (errno == 0); return TRUE; } @@ -156,36 +160,26 @@ _ostree_bootloader_uboot_write_config (OstreeBootloader *bootloader, GError **error) { OstreeBootloaderUboot *self = OSTREE_BOOTLOADER_UBOOT (bootloader); - g_autoptr(GFile) new_config_path = NULL; - g_autofree char *config_contents = NULL; - g_autofree char *new_config_contents = NULL; - g_autoptr(GPtrArray) new_lines = NULL; /* This should follow the symbolic link to the current bootversion. */ - config_contents = glnx_file_get_contents_utf8_at (AT_FDCWD, gs_file_get_path_cached (self->config_path), NULL, - cancellable, error); + g_autofree char *config_contents = + glnx_file_get_contents_utf8_at (self->sysroot->sysroot_fd, uboot_config_path, NULL, + cancellable, error); if (!config_contents) return FALSE; - new_config_path = ot_gfile_resolve_path_printf (self->sysroot->path, "boot/loader.%d/uEnv.txt", - bootversion); - - new_lines = g_ptr_array_new_with_free_func (g_free); - + g_autoptr(GPtrArray) new_lines = g_ptr_array_new_with_free_func (g_free); if (!create_config_from_boot_loader_entries (self, bootversion, new_lines, cancellable, error)) return FALSE; - new_config_contents = _ostree_sysroot_join_lines (new_lines); - { - g_autoptr(GBytes) new_config_contents_bytes = - g_bytes_new_static (new_config_contents, - strlen (new_config_contents)); - - if (!ot_gfile_replace_contents_fsync (new_config_path, new_config_contents_bytes, - cancellable, error)) - return FALSE; - } + g_autofree char *new_config_path = g_strdup_printf ("boot/loader.%d/uEnv.txt", bootversion); + g_autofree char *new_config_contents = _ostree_sysroot_join_lines (new_lines); + if (!glnx_file_replace_contents_at (self->sysroot->sysroot_fd, new_config_path, + (guint8*)new_config_contents, strlen (new_config_contents), + GLNX_FILE_REPLACE_DATASYNC_NEW, + cancellable, error)) + return FALSE; return TRUE; } @@ -196,7 +190,6 @@ _ostree_bootloader_uboot_finalize (GObject *object) OstreeBootloaderUboot *self = OSTREE_BOOTLOADER_UBOOT (object); g_clear_object (&self->sysroot); - g_clear_object (&self->config_path); G_OBJECT_CLASS (_ostree_bootloader_uboot_parent_class)->finalize (object); } @@ -227,6 +220,5 @@ _ostree_bootloader_uboot_new (OstreeSysroot *sysroot) { OstreeBootloaderUboot *self = g_object_new (OSTREE_TYPE_BOOTLOADER_UBOOT, NULL); self->sysroot = g_object_ref (sysroot); - self->config_path = g_file_resolve_relative_path (self->sysroot->path, "boot/loader/uEnv.txt"); return self; }