Skip to content

Commit

Permalink
lib/repo-refs: Resolve collection-refs in-memory and in parent repos
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mwleeds committed Feb 14, 2019
1 parent f5c86c8 commit 36933d9
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions src/libostree/ostree-repo-refs.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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;
}

Expand Down

0 comments on commit 36933d9

Please sign in to comment.