[ostree] admin: code cleanup
- From: Colin Walters <walters src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [ostree] admin: code cleanup
- Date: Fri, 16 Nov 2012 19:29:45 +0000 (UTC)
commit ee533d6ab9031f5e829a30f7aae134191c83bffa
Author: Colin Walters <walters verbum org>
Date: Fri Nov 16 10:40:49 2012 -0500
admin: code cleanup
Refactor internal functions so they can be used by a later patch.
src/ostree/ot-admin-functions.c | 82 +++++++++++++++++++++++++++-----------
1 files changed, 58 insertions(+), 24 deletions(-)
---
diff --git a/src/ostree/ot-admin-functions.c b/src/ostree/ot-admin-functions.c
index 1d41826..85cd478 100644
--- a/src/ostree/ot-admin-functions.c
+++ b/src/ostree/ot-admin-functions.c
@@ -104,31 +104,20 @@ ot_admin_ensure_initialized (GFile *ostree_dir,
return ret;
}
-/**
- * ot_admin_get_current_deployment:
- *
- * Returns in @out_deployment the full file path of the current
- * deployment that the /ostree/current symbolic link points to, or
- * %NULL if none.
- */
-gboolean
-ot_admin_get_current_deployment (GFile *ostree_dir,
- GFile **out_deployment,
- GCancellable *cancellable,
- GError **error)
+static gboolean
+query_file_info_allow_noent (GFile *path,
+ GFileInfo **out_info,
+ GCancellable *cancellable,
+ GError **error)
{
gboolean ret = FALSE;
- ot_lobj GFile *current_path = NULL;
- ot_lobj GFileInfo *file_info = NULL;
- ot_lobj GFile *ret_deployment = NULL;
+ ot_lobj GFileInfo *ret_file_info = NULL;
GError *temp_error = NULL;
- current_path = g_file_get_child (ostree_dir, "current");
-
- file_info = g_file_query_info (current_path, OSTREE_GIO_FAST_QUERYINFO,
- G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
- cancellable, &temp_error);
- if (!file_info)
+ ret_file_info = g_file_query_info (path, OSTREE_GIO_FAST_QUERYINFO,
+ G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
+ cancellable, &temp_error);
+ if (!ret_file_info)
{
if (g_error_matches (temp_error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND))
{
@@ -140,9 +129,34 @@ ot_admin_get_current_deployment (GFile *ostree_dir,
goto out;
}
}
- else
+
+ ret = TRUE;
+ ot_transfer_out_value (out_info, &ret_file_info);
+ out:
+ return ret;
+}
+
+static gboolean
+query_symlink_target_allow_noent (GFile *path,
+ GFile **out_target,
+ GCancellable *cancellable,
+ GError **error)
+{
+ gboolean ret = FALSE;
+ ot_lobj GFileInfo *file_info = NULL;
+ ot_lobj GFile *ret_target = NULL;
+ ot_lobj GFile *path_parent = NULL;
+
+ if (!query_file_info_allow_noent (path, &file_info,
+ cancellable, error))
+ goto out;
+
+ path_parent = g_file_get_parent (path);
+
+ if (file_info != NULL)
{
const char *target;
+
if (g_file_info_get_file_type (file_info) != G_FILE_TYPE_SYMBOLIC_LINK)
{
g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
@@ -151,12 +165,32 @@ ot_admin_get_current_deployment (GFile *ostree_dir,
}
target = g_file_info_get_symlink_target (file_info);
g_assert (target);
- ret_deployment = g_file_resolve_relative_path (ostree_dir, target);
+ ret_target = g_file_resolve_relative_path (path_parent, target);
}
ret = TRUE;
- ot_transfer_out_value (out_deployment, &ret_deployment);
+ ot_transfer_out_value (out_target, &ret_target);
out:
return ret;
}
+/**
+ * ot_admin_get_current_deployment:
+ *
+ * Returns in @out_deployment the full file path of the current
+ * deployment that the /ostree/current symbolic link points to, or
+ * %NULL if none.
+ */
+gboolean
+ot_admin_get_current_deployment (GFile *ostree_dir,
+ GFile **out_deployment,
+ GCancellable *cancellable,
+ GError **error)
+{
+ ot_lobj GFile *current_path = NULL;
+
+ current_path = g_file_get_child (ostree_dir, "current");
+
+ return query_symlink_target_allow_noent (current_path, out_deployment,
+ cancellable, error);
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]