From 86764dbf007fca1e42aacb830e3c1911b198be6e Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Tue, 6 Jan 2015 16:47:03 -0500 Subject: [PATCH] repo: Improve ostree_repo_load_file() to use `*at()` for xattrs We were already using openat() for the contents, but not the xattrs. Now that libgsystem 2014.3 has gs_fd_get_all_xattrs(), make use of it. Clean things up a bit so we only open the fd once. --- src/libostree/ostree-repo.c | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/src/libostree/ostree-repo.c b/src/libostree/ostree-repo.c index d43cc7f087..5df801d27c 100644 --- a/src/libostree/ostree-repo.c +++ b/src/libostree/ostree-repo.c @@ -1972,26 +1972,37 @@ ostree_repo_load_file (OstreeRepo *self, } } - if (repo_mode == OSTREE_REPO_MODE_BARE) + g_assert (repo_mode == OSTREE_REPO_MODE_BARE); + + if (g_file_info_get_file_type (ret_file_info) == G_FILE_TYPE_REGULAR + && (out_input || out_xattrs)) { + gs_fd_close int fd = -1; + + if (!gs_file_openat_noatime (self->objects_dir_fd, loose_path_buf, &fd, + cancellable, error)) + goto out; + if (out_xattrs) { - gs_unref_object GFile *full_path = - _ostree_repo_get_object_path (self, checksum, OSTREE_OBJECT_TYPE_FILE); - - if (!gs_file_get_all_xattrs (full_path, &ret_xattrs, - cancellable, error)) + if (!gs_fd_get_all_xattrs (fd, &ret_xattrs, + cancellable, error)) goto out; } - } - if (out_input && g_file_info_get_file_type (ret_file_info) == G_FILE_TYPE_REGULAR) + if (out_input) + { + ret_input = g_unix_input_stream_new (fd, TRUE); + fd = -1; /* Transfer ownership */ + } + } + else if (g_file_info_get_file_type (ret_file_info) == G_FILE_TYPE_SYMBOLIC_LINK + && out_xattrs) { - int fd = -1; - if (!gs_file_openat_noatime (self->objects_dir_fd, loose_path_buf, &fd, - cancellable, error)) + if (!gs_dfd_and_name_get_all_xattrs (self->objects_dir_fd, loose_path_buf, + &ret_xattrs, + cancellable, error)) goto out; - ret_input = g_unix_input_stream_new (fd, TRUE); } found = TRUE;