From 9cf15ed151af8df971e2d47d49d99491e4849a02 Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Fri, 18 Nov 2011 08:42:18 -0500 Subject: [PATCH] core: More cleanup of GIO utility API --- src/libostree/ostree-repo.c | 22 ++++++++------ src/libotutil/ot-gio-utils.c | 59 +++++------------------------------- src/libotutil/ot-gio-utils.h | 16 ++++------ src/ostree/ot-builtin-pull.c | 5 +-- 4 files changed, 29 insertions(+), 73 deletions(-) diff --git a/src/libostree/ostree-repo.c b/src/libostree/ostree-repo.c index e99680ce..cb82bcc5 100644 --- a/src/libostree/ostree-repo.c +++ b/src/libostree/ostree-repo.c @@ -179,13 +179,13 @@ ostree_repo_new (const char *path) static gboolean parse_rev_file (OstreeRepo *self, - const char *path, + GFile *f, char **sha256, GError **error) G_GNUC_UNUSED; static gboolean parse_rev_file (OstreeRepo *self, - const char *path, + GFile *f, char **sha256, GError **error) { @@ -194,7 +194,9 @@ parse_rev_file (OstreeRepo *self, gboolean ret = FALSE; char *rev = NULL; - rev = ot_util_get_file_contents_utf8 (path, &temp_error); + if (!ot_gfile_load_contents_utf8 (f, &rev, NULL, NULL, &temp_error)) + goto out; + if (rev == NULL) { if (g_error_matches (temp_error, G_FILE_ERROR, G_FILE_ERROR_NOENT)) @@ -215,14 +217,11 @@ parse_rev_file (OstreeRepo *self, if (g_str_has_prefix (rev, "ref: ")) { GFile *ref; - const char *ref_path; char *ref_sha256; gboolean subret; ref = g_file_resolve_relative_path (priv->local_heads_dir, rev + 5); - ref_path = ot_gfile_get_path_cached (ref); - - subret = parse_rev_file (self, ref_path, &ref_sha256, error); + subret = parse_rev_file (self, ref, &ref_sha256, error); g_clear_object (&ref); if (!subret) @@ -333,7 +332,7 @@ ostree_repo_resolve_rev (OstreeRepo *self, child_path = ot_gfile_get_path_cached (child); } - if (!ot_util_gfile_load_contents_utf8 (child, NULL, &ret_rev, NULL, &temp_error)) + if (!ot_gfile_load_contents_utf8 (child, &ret_rev, NULL, NULL, &temp_error)) { if (allow_noent && g_error_matches (temp_error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND)) { @@ -756,16 +755,19 @@ prepare_dir_for_checksum_get_object_path (OstreeRepo *self, OstreeObjectType type, GError **error) { + GFile *f = NULL; char *checksum_dir = NULL; char *object_path = NULL; object_path = ostree_repo_get_object_path (self, checksum, type); checksum_dir = g_path_get_dirname (object_path); + f = ot_gfile_new_for_path (checksum_dir); - if (!ot_util_ensure_directory (checksum_dir, FALSE, error)) + if (!ot_gfile_ensure_directory (f, FALSE, error)) goto out; out: + g_clear_object (&f); g_free (checksum_dir); return object_path; } @@ -1359,7 +1361,7 @@ ostree_repo_write_ref (OstreeRepo *self, { dir = g_file_get_child (priv->remote_heads_dir, remote); - if (!ot_util_ensure_directory (ot_gfile_get_path_cached (dir), FALSE, error)) + if (!ot_gfile_ensure_directory (dir, FALSE, error)) goto out; } diff --git a/src/libotutil/ot-gio-utils.c b/src/libotutil/ot-gio-utils.c index 42678a7b..867a0323 100644 --- a/src/libotutil/ot-gio-utils.c +++ b/src/libotutil/ot-gio-utils.c @@ -30,13 +30,13 @@ #include "otutil.h" gboolean -ot_util_ensure_directory (const char *path, gboolean with_parents, GError **error) +ot_gfile_ensure_directory (GFile *dir, + gboolean with_parents, + GError **error) { - GFile *dir; GError *temp_error = NULL; gboolean ret = FALSE; - dir = ot_gfile_new_for_path (path); if (with_parents) ret = g_file_make_directory_with_parents (dir, NULL, &temp_error); else @@ -54,33 +54,15 @@ ot_util_ensure_directory (const char *path, gboolean with_parents, GError **erro ret = TRUE; out: - g_clear_object (&dir); - return ret; -} - - -char * -ot_util_get_file_contents_utf8 (const char *path, - GError **error) -{ - GFile *file = NULL; - char *ret = NULL; - - file = ot_gfile_new_for_path (path); - if (!ot_util_gfile_load_contents_utf8 (file, NULL, &ret, NULL, error)) - goto out; - - out: - g_clear_object (&file); return ret; } gboolean -ot_util_gfile_load_contents_utf8 (GFile *file, - GCancellable *cancellable, - char **contents_out, - char **etag_out, - GError **error) +ot_gfile_load_contents_utf8 (GFile *file, + char **contents_out, + char **etag_out, + GCancellable *cancellable, + GError **error) { char *ret_contents = NULL; char *ret_etag = NULL; @@ -115,31 +97,6 @@ ot_util_gfile_load_contents_utf8 (GFile *file, return ret; } -GInputStream * -ot_util_read_file_noatime (GFile *file, GCancellable *cancellable, GError **error) -{ - GInputStream *ret = NULL; - int fd; - int flags = O_RDONLY; - const char *path = NULL; - - path = ot_gfile_get_path_cached (file); -#ifdef O_NOATIME - flags |= O_NOATIME; -#endif - fd = open (path, flags); - if (fd < 0) - { - ot_util_set_error_from_errno (error, errno); - goto out; - } - - ret = (GInputStream*)g_unix_input_stream_new (fd, TRUE); - - out: - return ret; -} - /* Like g_file_new_for_path, but only do local stuff, not GVFS */ GFile * ot_gfile_new_for_path (const char *path) diff --git a/src/libotutil/ot-gio-utils.h b/src/libotutil/ot-gio-utils.h index fcb4db7b..4f6952dc 100644 --- a/src/libotutil/ot-gio-utils.h +++ b/src/libotutil/ot-gio-utils.h @@ -33,17 +33,13 @@ const char *ot_gfile_get_path_cached (GFile *file); const char *ot_gfile_get_basename_cached (GFile *file); -gboolean ot_util_ensure_directory (const char *path, gboolean with_parents, GError **error); +gboolean ot_gfile_ensure_directory (GFile *dir, gboolean with_parents, GError **error); -char * ot_util_get_file_contents_utf8 (const char *path, GError **error); - -gboolean ot_util_gfile_load_contents_utf8 (GFile *file, - GCancellable *cancellable, - char **contents_out, - char **etag_out, - GError **error); - -GInputStream *ot_util_read_file_noatime (GFile *file, GCancellable *cancellable, GError **error); +gboolean ot_gfile_load_contents_utf8 (GFile *file, + char **contents_out, + char **etag_out, + GCancellable *cancellable, + GError **error); G_END_DECLS diff --git a/src/ostree/ot-builtin-pull.c b/src/ostree/ot-builtin-pull.c index 0e14bffc..10c987bc 100644 --- a/src/ostree/ot-builtin-pull.c +++ b/src/ostree/ot-builtin-pull.c @@ -292,6 +292,7 @@ ostree_builtin_pull (int argc, char **argv, const char *repo_path, GError **erro char *baseurl = NULL; char *refpath = NULL; char *temppath = NULL; + GFile *tempf = NULL; char *remote_ref = NULL; char *original_rev = NULL; GKeyFile *config = NULL; @@ -349,9 +350,9 @@ ostree_builtin_pull (int argc, char **argv, const char *repo_path, GError **erro NULL); if (!fetch_uri (repo, soup, target_uri, &temppath, error)) goto out; + tempf = ot_gfile_new_for_path (temppath); - rev = ot_util_get_file_contents_utf8 (temppath, error); - if (!rev) + if (!ot_gfile_load_contents_utf8 (tempf, &rev, NULL, NULL, error)) goto out; g_strchomp (rev);