diff options
author | Luca BRUNO <luca.bruno@coreos.com> | 2022-01-24 16:46:40 +0000 |
---|---|---|
committer | Luca BRUNO <luca.bruno@coreos.com> | 2022-01-24 16:54:54 +0000 |
commit | b27792ade385130e9d0c2924c51107b5f263cb57 (patch) | |
tree | 77203bc025d93edc3be9d2c9e382460714a54ebc /src/libostree/ostree-repo.c | |
parent | 0713ad32599441b5861dac05a8413e0d25454b8a (diff) | |
download | ostree-b27792ade385130e9d0c2924c51107b5f263cb57.tar.gz |
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.
Diffstat (limited to 'src/libostree/ostree-repo.c')
-rw-r--r-- | src/libostree/ostree-repo.c | 13 |
1 files 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); |