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
This commit is contained in:
Colin Walters 2016-09-13 21:05:08 -04:00 committed by Atomic Bot
parent 84a9d61e15
commit fcffb73280
3 changed files with 13 additions and 51 deletions

View File

@ -913,35 +913,32 @@ ostree_sysroot_write_origin_file (OstreeSysroot *sysroot,
GCancellable *cancellable, GCancellable *cancellable,
GError **error) GError **error)
{ {
gboolean ret = FALSE;
GKeyFile *origin = GKeyFile *origin =
new_origin ? new_origin : ostree_deployment_get_origin (deployment); new_origin ? new_origin : ostree_deployment_get_origin (deployment);
if (origin) if (origin)
{ {
g_autoptr(GFile) deployment_path = ostree_sysroot_get_deployment_directory (sysroot, deployment); g_autofree char *origin_path = NULL;
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 *contents = NULL; g_autofree char *contents = NULL;
gsize len; 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); contents = g_key_file_to_data (origin, &len, error);
if (!contents) if (!contents)
goto out; return FALSE;
contents_bytes = g_bytes_new_static (contents, len);
if (!ot_gfile_replace_contents_fsync (origin_path, contents_bytes, if (!glnx_file_replace_contents_at (sysroot->sysroot_fd,
origin_path, (guint8*)contents, len,
GLNX_FILE_REPLACE_DATASYNC_NEW,
cancellable, error)) cancellable, error))
goto out; return FALSE;
if (!ot_util_fsync_directory (origin_parent, cancellable, error))
goto out;
} }
ret = TRUE; return TRUE;
out:
return ret;
} }
static gboolean static gboolean

View File

@ -314,37 +314,6 @@ ot_gfile_ensure_unlinked (GFile *path,
return TRUE; 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: * ot_util_ensure_directory_and_fsync:
* @dir: Path to a directory * @dir: Path to a directory

View File

@ -89,10 +89,6 @@ gboolean ot_util_ensure_directory_and_fsync (GFile *dir,
GCancellable *cancellable, GCancellable *cancellable,
GError **error); GError **error);
gboolean ot_util_fsync_directory (GFile *dir,
GCancellable *cancellable,
GError **error);
#if !GLIB_CHECK_VERSION(2, 44, 0) #if !GLIB_CHECK_VERSION(2, 44, 0)
gboolean gboolean
ot_file_enumerator_iterate (GFileEnumerator *direnum, ot_file_enumerator_iterate (GFileEnumerator *direnum,