core: Skip over local packages for downloads

Because `hif_source_get_location()` is actually a reference to the
upstream repo, we shouldn't create a cache directory there.

This is just a two line fix, but I changed some things so that we keep
track of the number of local packages, in order to make the "Need to
download" print accurate.

We still need to add them (confusingly) to the `packages_to_download`
because that's also used for the container path which imports them.

Closes: #255

Closes: #256
Approved by: jlebon
This commit is contained in:
Colin Walters 2016-03-31 13:16:42 -04:00 committed by Colin Walters (automation)
parent 7e55b484e3
commit 63761e5127

View File

@ -58,6 +58,7 @@ struct _RpmOstreeInstall {
GPtrArray *packages_requested; GPtrArray *packages_requested;
/* Target state */ /* Target state */
guint n_packages_download_local;
GPtrArray *packages_to_download; GPtrArray *packages_to_download;
guint64 n_bytes_to_fetch; guint64 n_bytes_to_fetch;
@ -653,6 +654,7 @@ static gboolean
get_packages_to_download (HifContext *hifctx, get_packages_to_download (HifContext *hifctx,
OstreeRepo *ostreerepo, OstreeRepo *ostreerepo,
GPtrArray **out_packages, GPtrArray **out_packages,
guint *out_n_local,
GError **error) GError **error)
{ {
gboolean ret = FALSE; gboolean ret = FALSE;
@ -660,6 +662,7 @@ get_packages_to_download (HifContext *hifctx,
g_autoptr(GPtrArray) packages = NULL; g_autoptr(GPtrArray) packages = NULL;
g_autoptr(GPtrArray) packages_to_download = NULL; g_autoptr(GPtrArray) packages_to_download = NULL;
GPtrArray *sources = hif_context_get_repos (hifctx); GPtrArray *sources = hif_context_get_repos (hifctx);
guint n_local = 0;
packages = hif_goal_get_packages (hif_context_get_goal (hifctx), packages = hif_goal_get_packages (hif_context_get_goal (hifctx),
HIF_PACKAGE_INFO_INSTALL, HIF_PACKAGE_INFO_INSTALL,
@ -721,12 +724,15 @@ get_packages_to_download (HifContext *hifctx,
if (g_file_test (cachepath, G_FILE_TEST_EXISTS)) if (g_file_test (cachepath, G_FILE_TEST_EXISTS))
continue; continue;
} }
else
n_local++;
g_ptr_array_add (packages_to_download, g_object_ref (pkg)); g_ptr_array_add (packages_to_download, g_object_ref (pkg));
} }
ret = TRUE; ret = TRUE;
*out_packages = g_steal_pointer (&packages_to_download); *out_packages = g_steal_pointer (&packages_to_download);
*out_n_local = n_local;
out: out:
return ret; return ret;
} }
@ -766,11 +772,14 @@ rpmostree_context_prepare_install (RpmOstreeContext *self,
} }
printf ("%s", "done\n"); printf ("%s", "done\n");
if (!get_packages_to_download (hifctx, self->ostreerepo, &ret_install->packages_to_download, error)) if (!get_packages_to_download (hifctx, self->ostreerepo, &ret_install->packages_to_download,
&ret_install->n_packages_download_local,
error))
goto out; goto out;
rpmostree_print_transaction (hifctx); rpmostree_print_transaction (hifctx);
g_print ("\n Need to download %u packages\n", ret_install->packages_to_download->len); g_print ("\n Need to download %u packages\n",
ret_install->packages_to_download->len - ret_install->n_packages_download_local);
ret = TRUE; ret = TRUE;
*out_install = g_steal_pointer (&ret_install); *out_install = g_steal_pointer (&ret_install);
@ -957,6 +966,9 @@ source_download_packages (HifRepo *source,
HifPackage *pkg = packages->pdata[i]; HifPackage *pkg = packages->pdata[i];
struct PkgDownloadState *dlstate; struct PkgDownloadState *dlstate;
if (pkg_is_local (pkg))
continue;
if (target_dfd == -1) if (target_dfd == -1)
{ {
target_dir = g_build_filename (hif_repo_get_location (source), "/packages/", NULL); target_dir = g_build_filename (hif_repo_get_location (source), "/packages/", NULL);