From fcffb732806a10a2be77a4642ccf7370836572e6 Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Tue, 13 Sep 2016 21:05:08 -0400 Subject: [PATCH] sysroot: Port origin writing code to fd-relative Just preparatory cleanup for a next patch which makes the fsyncing configurable. Closes: #509 Approved by: giuseppe --- src/libostree/ostree-sysroot-deploy.c | 29 +++++++++++-------------- src/libotutil/ot-gio-utils.c | 31 --------------------------- src/libotutil/ot-gio-utils.h | 4 ---- 3 files changed, 13 insertions(+), 51 deletions(-) diff --git a/src/libostree/ostree-sysroot-deploy.c b/src/libostree/ostree-sysroot-deploy.c index 79f9c9f3..8f0ff733 100644 --- a/src/libostree/ostree-sysroot-deploy.c +++ b/src/libostree/ostree-sysroot-deploy.c @@ -913,35 +913,32 @@ ostree_sysroot_write_origin_file (OstreeSysroot *sysroot, GCancellable *cancellable, GError **error) { - gboolean ret = FALSE; GKeyFile *origin = new_origin ? new_origin : ostree_deployment_get_origin (deployment); if (origin) { - g_autoptr(GFile) deployment_path = ostree_sysroot_get_deployment_directory (sysroot, deployment); - g_autoptr(GFile) origin_path = ostree_sysroot_get_deployment_origin_path (deployment_path); - g_autoptr(GFile) origin_parent = g_file_get_parent (origin_path); + g_autofree char *origin_path = NULL; g_autofree char *contents = NULL; gsize len; - g_autoptr(GBytes) contents_bytes = NULL; + + origin_path = g_strdup_printf ("ostree/deploy/%s/deploy/%s.%d.origin", + ostree_deployment_get_osname (deployment), + ostree_deployment_get_csum (deployment), + ostree_deployment_get_deployserial (deployment)); contents = g_key_file_to_data (origin, &len, error); if (!contents) - goto out; - contents_bytes = g_bytes_new_static (contents, len); + return FALSE; - if (!ot_gfile_replace_contents_fsync (origin_path, contents_bytes, - cancellable, error)) - goto out; - - if (!ot_util_fsync_directory (origin_parent, cancellable, error)) - goto out; + if (!glnx_file_replace_contents_at (sysroot->sysroot_fd, + origin_path, (guint8*)contents, len, + GLNX_FILE_REPLACE_DATASYNC_NEW, + cancellable, error)) + return FALSE; } - ret = TRUE; - out: - return ret; + return TRUE; } static gboolean diff --git a/src/libotutil/ot-gio-utils.c b/src/libotutil/ot-gio-utils.c index 683fa48e..06bf1a27 100644 --- a/src/libotutil/ot-gio-utils.c +++ b/src/libotutil/ot-gio-utils.c @@ -314,37 +314,6 @@ ot_gfile_ensure_unlinked (GFile *path, return TRUE; } -/** - * ot_util_fsync_directory: - * @dir: Path to a directory - * @cancellable: Cancellable - * @error: Error - * - * Ensure that all entries in directory @dir are on disk. - */ -gboolean -ot_util_fsync_directory (GFile *dir, - GCancellable *cancellable, - GError **error) -{ - gboolean ret = FALSE; - glnx_fd_close int dfd = -1; - - if (!glnx_opendirat (AT_FDCWD, gs_file_get_path_cached (dir), TRUE, - &dfd, error)) - goto out; - - if (fsync (dfd) != 0) - { - glnx_set_error_from_errno (error); - goto out; - } - - ret = TRUE; - out: - return ret; -} - /** * ot_util_ensure_directory_and_fsync: * @dir: Path to a directory diff --git a/src/libotutil/ot-gio-utils.h b/src/libotutil/ot-gio-utils.h index 0d3c45d2..0750a5b4 100644 --- a/src/libotutil/ot-gio-utils.h +++ b/src/libotutil/ot-gio-utils.h @@ -89,10 +89,6 @@ gboolean ot_util_ensure_directory_and_fsync (GFile *dir, GCancellable *cancellable, GError **error); -gboolean ot_util_fsync_directory (GFile *dir, - GCancellable *cancellable, - GError **error); - #if !GLIB_CHECK_VERSION(2, 44, 0) gboolean ot_file_enumerator_iterate (GFileEnumerator *direnum,