Blame SOURCES/support-subscription-manager.patch

9c11e1
commit f0d7217508131a006d19128c2988a43e44107418
9c11e1
Author: Richard Hughes <richard@hughsie.com>
9c11e1
Date:   Mon Jul 13 12:02:12 2015 +0100
9c11e1
9c11e1
    Support enrollment engines such as subscription-manager
9c11e1
    
9c11e1
    This is perhaps non-optimal as we have to parse the list of repos twice, but
9c11e1
    does allow the enrollment engine to add and remove sources as required.
9c11e1
    
9c11e1
    Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1223417
9c11e1
9c11e1
diff --git a/libhif/hif-context.c b/libhif/hif-context.c
9c11e1
index 57bda46..454af8a 100644
9c11e1
--- a/libhif/hif-context.c
9c11e1
+++ b/libhif/hif-context.c
9c11e1
@@ -66,6 +66,7 @@ struct _HifContextPrivate
9c11e1
 	gboolean		 only_trusted;
9c11e1
 	gboolean		 enable_yumdb;
9c11e1
 	gboolean		 keep_cache;
9c11e1
+	gboolean		 enrollment_valid;
9c11e1
 	HifLock			*lock;
9c11e1
 	HifTransaction		*transaction;
9c11e1
 	GThread			*transaction_thread;
9c11e1
@@ -1199,6 +1200,43 @@ hif_context_set_http_proxy (HifContext	*context,
9c11e1
 #define MAX_NATIVE_ARCHES	12
9c11e1
 
9c11e1
 /**
9c11e1
+ * hif_context_setup_enrollments:
9c11e1
+ * @context: a #HifContext instance.
9c11e1
+ * @error: A #GError or %NULL
9c11e1
+ *
9c11e1
+ * Resyncs the enrollment with the vendor system. This may change the contents
9c11e1
+ * of files in repos.d according to subscription levels.
9c11e1
+ *
9c11e1
+ * Returns: %TRUE for success, %FALSE otherwise
9c11e1
+ *
9c11e1
+ * Since: 0.2.1
9c11e1
+ **/
9c11e1
+gboolean
9c11e1
+hif_context_setup_enrollments (HifContext *context, GError **error)
9c11e1
+{
9c11e1
+	HifContextPrivate *priv = GET_PRIVATE (context);
9c11e1
+	guint i;
9c11e1
+	const gchar *cmds[] = { "/usr/sbin/rhn-profile-sync",
9c11e1
+				"/usr/bin/subscription-manager refresh",
9c11e1
+				NULL };
9c11e1
+
9c11e1
+	/* no need to refresh */
9c11e1
+	if (priv->enrollment_valid)
9c11e1
+		return TRUE;
9c11e1
+
9c11e1
+	for (i = 0; cmds[i] != NULL; i++) {
9c11e1
+		_cleanup_strv_free_ gchar **argv = g_strsplit (cmds[i], " ", -1);
9c11e1
+		if (!g_file_test (argv[0], G_FILE_TEST_EXISTS))
9c11e1
+			continue;
9c11e1
+		g_debug ("Running: %s", cmds[i]);
9c11e1
+		if (!g_spawn_command_line_sync (cmds[i], NULL, NULL, NULL, error))
9c11e1
+			return FALSE;
9c11e1
+	}
9c11e1
+	priv->enrollment_valid = TRUE;
9c11e1
+	return TRUE;
9c11e1
+}
9c11e1
+
9c11e1
+/**
9c11e1
  * hif_context_setup:
9c11e1
  * @context: a #HifContext instance.
9c11e1
  * @cancellable: A #GCancellable or %NULL
9c11e1
@@ -1373,6 +1411,10 @@ hif_context_setup (HifContext *context,
9c11e1
 	if (!hif_context_copy_vendor_solv (context, error))
9c11e1
 		return FALSE;
9c11e1
 
9c11e1
+	/* initialize external frameworks where installed */
9c11e1
+	if (!hif_context_setup_enrollments (context, error))
9c11e1
+		return FALSE;
9c11e1
+
9c11e1
 	return TRUE;
9c11e1
 }
9c11e1
 
9c11e1
@@ -1730,6 +1772,30 @@ hif_context_commit (HifContext *context, HifState *state, GError **error)
9c11e1
 }
9c11e1
 
9c11e1
 /**
9c11e1
+ * hif_context_invalidate_full:
9c11e1
+ * @context: a #HifContext instance.
9c11e1
+ * @message: the reason for invalidating
9c11e1
+ * @flags: a #HifContextInvalidateFlags, e.g. %HIF_CONTEXT_INVALIDATE_FLAG_ENROLLMENT
9c11e1
+ *
9c11e1
+ * Informs the context that the certain parts of the context may no longer be
9c11e1
+ * in sync or valid.
9c11e1
+ *
9c11e1
+ * Since: 0.2.1
9c11e1
+ **/
9c11e1
+void
9c11e1
+hif_context_invalidate_full (HifContext *context,
9c11e1
+			     const gchar *message,
9c11e1
+			     HifContextInvalidateFlags flags)
9c11e1
+{
9c11e1
+	HifContextPrivate *priv = GET_PRIVATE (context);
9c11e1
+	g_debug ("Msg: %s", message);
9c11e1
+	if (flags & HIF_CONTEXT_INVALIDATE_FLAG_RPMDB)
9c11e1
+		g_signal_emit (context, signals [SIGNAL_INVALIDATE], 0, message);
9c11e1
+	if (flags & HIF_CONTEXT_INVALIDATE_FLAG_ENROLLMENT)
9c11e1
+		priv->enrollment_valid = FALSE;
9c11e1
+}
9c11e1
+
9c11e1
+/**
9c11e1
  * hif_context_invalidate:
9c11e1
  * @context: a #HifContext instance.
9c11e1
  * @message: the reason for invalidating
9c11e1
@@ -1741,7 +1807,8 @@ hif_context_commit (HifContext *context, HifState *state, GError **error)
9c11e1
 void
9c11e1
 hif_context_invalidate (HifContext *context, const gchar *message)
9c11e1
 {
9c11e1
-	g_signal_emit (context, signals [SIGNAL_INVALIDATE], 0, message);
9c11e1
+	hif_context_invalidate_full (context, message,
9c11e1
+				     HIF_CONTEXT_INVALIDATE_FLAG_RPMDB);
9c11e1
 }
9c11e1
 
9c11e1
 /**
9c11e1
diff --git a/libhif/hif-context.h b/libhif/hif-context.h
9c11e1
index ee7a7eb..7aaa8cc 100644
9c11e1
--- a/libhif/hif-context.h
9c11e1
+++ b/libhif/hif-context.h
9c11e1
@@ -65,6 +65,22 @@ struct _HifContextClass
9c11e1
 	void (*_hif_reserved8)	(void);
9c11e1
 };
9c11e1
 
9c11e1
+/**
9c11e1
+ * HifContextInvalidateFlags:
9c11e1
+ * @HIF_CONTEXT_INVALIDATE_FLAG_NONE:		No caches are invalid
9c11e1
+ * @HIF_CONTEXT_INVALIDATE_FLAG_RPMDB:		The rpmdb cache is invalid
9c11e1
+ * @HIF_CONTEXT_INVALIDATE_FLAG_ENROLLMENT:	Any enrollment may be invalid
9c11e1
+ *
9c11e1
+ * The update flags.
9c11e1
+ **/
9c11e1
+typedef enum {
9c11e1
+	HIF_CONTEXT_INVALIDATE_FLAG_NONE	= 0,
9c11e1
+	HIF_CONTEXT_INVALIDATE_FLAG_RPMDB	= 1,
9c11e1
+	HIF_CONTEXT_INVALIDATE_FLAG_ENROLLMENT	= 2,
9c11e1
+	/*< private >*/
9c11e1
+	HIF_CONTEXT_INVALIDATE_FLAG_LAST
9c11e1
+} HifContextInvalidateFlags;
9c11e1
+
9c11e1
 GType		 hif_context_get_type			(void);
9c11e1
 HifContext	*hif_context_new			(void);
9c11e1
 
9c11e1
@@ -140,6 +156,8 @@ void             hif_context_set_http_proxy		(HifContext	*context,
9c11e1
 gboolean	 hif_context_setup			(HifContext	*context,
9c11e1
 							 GCancellable	*cancellable,
9c11e1
 							 GError		**error);
9c11e1
+gboolean	 hif_context_setup_enrollments		(HifContext	*context,
9c11e1
+							 GError		**error);
9c11e1
 gboolean	 hif_context_setup_sack			(HifContext	*context,
9c11e1
 							 HifState	*state,
9c11e1
 							 GError		**error);
9c11e1
@@ -148,6 +166,9 @@ gboolean	 hif_context_commit			(HifContext	*context,
9c11e1
 							 GError		**error);
9c11e1
 void		 hif_context_invalidate			(HifContext	*context,
9c11e1
 							 const gchar	*message);
9c11e1
+void		 hif_context_invalidate_full		(HifContext	*context,
9c11e1
+							 const gchar	*message,
9c11e1
+							 HifContextInvalidateFlags flags);
9c11e1
 gboolean	 hif_context_install			(HifContext	*context,
9c11e1
 							 const gchar	*name,
9c11e1
 							 GError		**error);
9c11e1
diff --git a/libhif/hif-repos.c b/libhif/hif-repos.c
9c11e1
index 7554289..44af677 100644
9c11e1
--- a/libhif/hif-repos.c
9c11e1
+++ b/libhif/hif-repos.c
9c11e1
@@ -88,6 +88,8 @@ hif_repos_invalidate (HifRepos *repos)
9c11e1
 {
9c11e1
 	HifReposPrivate *priv = GET_PRIVATE (repos);
9c11e1
 	priv->loaded = FALSE;
9c11e1
+	hif_context_invalidate_full (priv->context, "repos.d invalidated",
9c11e1
+				     HIF_CONTEXT_INVALIDATE_FLAG_ENROLLMENT);
9c11e1
 }
9c11e1
 
9c11e1
 /**
9c11e1
@@ -424,6 +426,10 @@ hif_repos_refresh (HifRepos *repos, GError **error)
9c11e1
 	hif_repos_invalidate (repos);
9c11e1
 	g_ptr_array_set_size (priv->sources, 0);
9c11e1
 
9c11e1
+	/* re-populate redhat.repo */
9c11e1
+	if (!hif_context_setup_enrollments (priv->context, error))
9c11e1
+		return FALSE;
9c11e1
+
9c11e1
 	/* open dir */
9c11e1
 	repo_path = hif_context_get_repo_dir (priv->context);
9c11e1
 	dir = g_dir_open (repo_path, 0, error);
9c11e1
diff --git a/libhif/hif-source.c b/libhif/hif-source.c
9c11e1
index 026c919..3e46027 100644
9c11e1
--- a/libhif/hif-source.c
9c11e1
+++ b/libhif/hif-source.c
9c11e1
@@ -1484,6 +1484,10 @@ hif_source_update (HifSource *source,
9c11e1
 	if (!ret)
9c11e1
 		goto out;
9c11e1
 
9c11e1
+	/* signal that the vendor platform data is not resyned */
9c11e1
+	hif_context_invalidate_full (priv->context, "updated repo cache",
9c11e1
+				     HIF_CONTEXT_INVALIDATE_FLAG_ENROLLMENT);
9c11e1
+
9c11e1
 	/* done */
9c11e1
 	ret = hif_state_done (state, error);
9c11e1
 	if (!ret)
9c11e1
diff --git a/libhif/hif-transaction.c b/libhif/hif-transaction.c
9c11e1
index f7e9b17..24a59a4 100644
9c11e1
--- a/libhif/hif-transaction.c
9c11e1
+++ b/libhif/hif-transaction.c
9c11e1
@@ -1428,7 +1428,9 @@ hif_transaction_commit (HifTransaction *transaction,
9c11e1
 	}
9c11e1
 
9c11e1
 	/* all sacks are invalid now */
9c11e1
-	hif_context_invalidate (priv->context, "transaction performed");
9c11e1
+	hif_context_invalidate_full (priv->context, "transaction performed",
9c11e1
+				     HIF_CONTEXT_INVALIDATE_FLAG_RPMDB |
9c11e1
+				     HIF_CONTEXT_INVALIDATE_FLAG_ENROLLMENT);
9c11e1
 
9c11e1
 	/* this section done */
9c11e1
 	ret = hif_state_done (state, error);
9c11e1
commit 733c14386165edb05c4d6e456778a5403f87b908
9c11e1
Author: Colin Walters <walters@verbum.org>
9c11e1
Date:   Sat Jul 18 10:35:07 2015 -0400
9c11e1
9c11e1
    context: Don't do entitlements for alternative install roots
9c11e1
    
9c11e1
    Using rpm-ostree shouldn't try to check or update my host repo's
9c11e1
    entitlement status.
9c11e1
    
9c11e1
    Conflicts:
9c11e1
    	libhif/hif-context.c
9c11e1
9c11e1
diff --git a/libhif/hif-context.c b/libhif/hif-context.c
9c11e1
index 454af8a..c259fa9 100644
9c11e1
--- a/libhif/hif-context.c
9c11e1
+++ b/libhif/hif-context.c
9c11e1
@@ -1224,6 +1224,15 @@ hif_context_setup_enrollments (HifContext *context, GError **error)
9c11e1
 	if (priv->enrollment_valid)
9c11e1
 		return TRUE;
9c11e1
 
9c11e1
+	/* Let's assume that alternative installation roots don't
9c11e1
+	 * require entitlement.  We only want to do system things if
9c11e1
+	 * we're actually affecting the system.  A more accurate test
9c11e1
+	 * here would be checking that we're using /etc/yum.repos.d or
9c11e1
+	 * so, but that can come later.
9c11e1
+	 */
9c11e1
+	if (g_strcmp0 (priv->install_root, "/") != 0)
9c11e1
+		return TRUE;
9c11e1
+
9c11e1
 	for (i = 0; cmds[i] != NULL; i++) {
9c11e1
 		_cleanup_strv_free_ gchar **argv = g_strsplit (cmds[i], " ", -1);
9c11e1
 		if (!g_file_test (argv[0], G_FILE_TEST_EXISTS))