From 77f91d6c6be2d264aa14be9d33c0488dc7e141cc Mon Sep 17 00:00:00 2001 From: Matthew Leeds Date: Thu, 14 Feb 2019 01:33:20 -0800 Subject: [PATCH] lib/repo-refs: Resolve collection-refs in-memory and in parent repos Currently the behavior of ostree_repo_resolve_rev() is that it tries to resolve a ref to a commit by checking the refs/ directories, but also by checking for in-memory ref-checksum pairs which are part of an in-progress transaction and also by checking the parent repo if one exists. Currently ostree_repo_resolve_collection_ref() only checks the refs/ directories, so this commit makes its behavior analagous since it is the analagous API which supports collection-refs. The impetus for this was that currently Flatpak uses ostree_repo_resolve_rev() to load a commit after doing a P2P pull in flatpak_dir_do_resolve_p2p_refs(), but that assumes the ref came from the same remote that originally provided it, which might not be the case if more than one remote has the same collection ID configured. And changing Flatpak to use ostree_repo_resolve_collection_ref() doesn't work without this patch. Closes: #1821 Approved by: pwithnall --- src/libostree/ostree-repo-refs.c | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/src/libostree/ostree-repo-refs.c b/src/libostree/ostree-repo-refs.c index 1267b240..ee11eb53 100644 --- a/src/libostree/ostree-repo-refs.c +++ b/src/libostree/ostree-repo-refs.c @@ -537,7 +537,30 @@ ostree_repo_resolve_collection_ref (OstreeRepo *self, cancellable, error)) return FALSE; - const char *ret_contents = g_hash_table_lookup (refs, ref); + g_autofree char *ret_contents = g_strdup (g_hash_table_lookup (refs, ref)); + + /* Check for refs in the current transaction that haven't been written to + * disk, to match the behavior of ostree_repo_resolve_rev() */ + if (ret_contents == NULL && self->in_transaction) + { + g_mutex_lock (&self->txn_lock); + if (self->txn.collection_refs) + ret_contents = g_strdup (g_hash_table_lookup (self->txn.collection_refs, ref)); + g_mutex_unlock (&self->txn_lock); + } + + /* Check for refs in the parent repo */ + if (ret_contents == NULL && self->parent_repo != NULL) + { + if (!ostree_repo_resolve_collection_ref (self->parent_repo, + ref, + TRUE, + flags, + &ret_contents, + cancellable, + error)) + return FALSE; + } if (ret_contents == NULL && !allow_noent) { @@ -548,7 +571,7 @@ ostree_repo_resolve_collection_ref (OstreeRepo *self, } if (out_rev != NULL) - *out_rev = g_strdup (ret_contents); + *out_rev = g_steal_pointer (&ret_contents); return TRUE; }