From b27792ade385130e9d0c2924c51107b5f263cb57 Mon Sep 17 00:00:00 2001 From: Luca BRUNO Date: Mon, 24 Jan 2022 16:46:40 +0000 Subject: [PATCH] lib/repo: open file only if required This tightens up the logic for opening a file while inspecting its xattrs. The only codepath fetching xattrs from a FD is the one handling 'bare' mode. It also rearranges the else-assert flow, mostly for future-proofing. --- src/libostree/ostree-repo.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/libostree/ostree-repo.c b/src/libostree/ostree-repo.c index 86948ee2..64a8fea9 100644 --- a/src/libostree/ostree-repo.c +++ b/src/libostree/ostree-repo.c @@ -4218,8 +4218,9 @@ _ostree_repo_load_file_bare (OstreeRepo *self, cancellable, error); } - const gboolean need_open = - (out_fd || out_xattrs || self->mode == OSTREE_REPO_MODE_BARE_USER); + const gboolean need_open = (out_fd || + (out_xattrs && self->mode == OSTREE_REPO_MODE_BARE) || + self->mode == OSTREE_REPO_MODE_BARE_USER); /* If it's a regular file and we're requested to return the fd, do it now. As * a special case in bare-user, we always do an open, since the stat() metadata * lives there. @@ -4284,10 +4285,8 @@ _ostree_repo_load_file_bare (OstreeRepo *self, ret_xattrs = g_variant_ref_sink (g_variant_builder_end (&builder)); } } - else + else if (self->mode == OSTREE_REPO_MODE_BARE) { - g_assert (self->mode == OSTREE_REPO_MODE_BARE); - if (S_ISREG (stbuf.st_mode) && out_xattrs) { if (self->disable_xattrs) @@ -4306,6 +4305,10 @@ _ostree_repo_load_file_bare (OstreeRepo *self, return FALSE; } } + else + { + g_assert_not_reached (); + } if (out_fd) *out_fd = glnx_steal_fd (&fd);