Skip to content

Commit

Permalink
Merge pull request #1973 from mwleeds/avoid-extraneous-summary-copy
Browse files Browse the repository at this point in the history
Don't copy summary for collection-ref mirror subset pulls
  • Loading branch information
openshift-merge-robot committed Mar 29, 2020
2 parents 1003a2d + 164b2aa commit 5b4c975
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 3 deletions.
10 changes: 10 additions & 0 deletions man/ostree-find-remotes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,16 @@ Boston, MA 02111-1307, USA.
</para></listitem>
</varlistentry>

<varlistentry>
<term><option>--mirror</option></term>

<listitem><para>
Do a mirror pull (see the documentation for
<command>ostree pull --mirror</command>). This option can
only be used in combination with <option>--pull</option>.
</para></listitem>
</varlistentry>

</variablelist>
</refsect1>

Expand Down
3 changes: 2 additions & 1 deletion src/libostree/ostree-repo-pull.c
Original file line number Diff line number Diff line change
Expand Up @@ -4567,7 +4567,8 @@ ostree_repo_pull_with_options (OstreeRepo *self,
}
}

if (pull_data->is_mirror && pull_data->summary_data && !refs_to_fetch && !configured_branches)
if (pull_data->is_mirror && pull_data->summary_data &&
!refs_to_fetch && !opt_collection_refs_set && !configured_branches)
{
GLnxFileReplaceFlags replaceflag =
pull_data->repo->disable_fsync ? GLNX_FILE_REPLACE_NODATASYNC : 0;
Expand Down
22 changes: 21 additions & 1 deletion src/ostree/ot-builtin-find-remotes.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,15 @@ static gchar *opt_cache_dir = NULL;
static gchar *opt_finders = NULL;
static gboolean opt_disable_fsync = FALSE;
static gboolean opt_pull = FALSE;
static gboolean opt_mirror = FALSE;

static GOptionEntry options[] =
{
{ "cache-dir", 0, 0, G_OPTION_ARG_FILENAME, &opt_cache_dir, "Use custom cache dir", NULL },
{ "disable-fsync", 0, 0, G_OPTION_ARG_NONE, &opt_disable_fsync, "Do not invoke fsync()", NULL },
{ "finders", 0, 0, G_OPTION_ARG_STRING, &opt_finders, "Use the specified comma separated list of finders (e.g. config,lan,mount)", "FINDERS" },
{ "pull", 0, 0, G_OPTION_ARG_NONE, &opt_pull, "Pull the updates after finding them", NULL },
{ "mirror", 0, 0, G_OPTION_ARG_NONE, &opt_mirror, "Do a mirror pull (see ostree pull --mirror)", NULL},
{ NULL }
};

Expand Down Expand Up @@ -188,6 +190,7 @@ ostree_builtin_find_remotes (int argc,
g_auto(OstreeRepoFinderResultv) results = NULL;
g_auto(GLnxConsoleRef) console = { 0, };
g_autoptr(GHashTable) refs_found = NULL; /* set (element-type OstreeCollectionRef) */
g_autoptr(GVariant) pull_options = NULL;

context = g_option_context_new ("COLLECTION-ID REF [COLLECTION-ID REF...]");

Expand All @@ -210,6 +213,12 @@ ostree_builtin_find_remotes (int argc,
return FALSE;
}

if (opt_mirror && !opt_pull)
{
ot_util_usage_error (context, "When --mirror is specified, --pull must also be", error);
return FALSE;
}

if (opt_disable_fsync)
ostree_repo_set_disable_fsync (repo, TRUE);

Expand Down Expand Up @@ -359,13 +368,24 @@ ostree_builtin_find_remotes (int argc,
if (!opt_pull)
return TRUE;

{
GVariantBuilder builder;
g_variant_builder_init (&builder, G_VARIANT_TYPE ("a{sv}"));

if (opt_mirror)
g_variant_builder_add (&builder, "{s@v}", "flags",
g_variant_new_variant (g_variant_new_int32 (OSTREE_REPO_PULL_FLAGS_MIRROR)));

pull_options = g_variant_ref_sink (g_variant_builder_end (&builder));
}

/* Run the pull operation. */
if (console.is_tty)
progress = ostree_async_progress_new_and_connect (ostree_repo_pull_default_console_progress_changed, &console);

ostree_repo_pull_from_remotes_async (repo,
(const OstreeRepoFinderResult * const *) results,
NULL, /* no options */
pull_options,
progress, cancellable,
get_result_cb, &pull_result);

Expand Down
14 changes: 13 additions & 1 deletion tests/test-pull-collections.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ set -euo pipefail

. $(dirname $0)/libtest.sh

echo '1..6'
echo '1..7'

cd ${test_tmpdir}

Expand Down Expand Up @@ -258,3 +258,15 @@ then
fi

echo "ok 6 pull refs from local repos"

ostree_repo_init local-mirror
do_remote_add local-mirror collection-repo --collection-id org.example.CollectionRepo
# Generate a summary in the local mirror; don't use do_summary to avoid gpg
${CMD_PREFIX} ostree --repo=local-mirror summary --update
summarysig=$(sha256sum < local-mirror/summary | cut -f 1 -d ' ')
# Mirror subset of refs: A collection-ref version of https://github.com/ostreedev/ostree/issues/846
${CMD_PREFIX} ostree --repo=local-mirror find-remotes --pull --mirror --finders=config org.example.CollectionRepo goodcref1
newsummarysig=$(sha256sum < local-mirror/summary | cut -f 1 -d ' ')
assert_streq ${summarysig} ${newsummarysig}

echo "ok 7 mirror pull subset of collection-refs with summary"

0 comments on commit 5b4c975

Please sign in to comment.