From: Alexander Larsson <alexl@redhat.com>
Date: Mon, 19 Jun 2017 13:09:33 +0200
Subject: install: Manually save summary[.sig] in cache repo

With the latest ostree, pull --mirror does not mirror the
summary for partial pulls, so system-wide installs fail. We
fix it by manually updating the summary.

Origin: backport, 0.9.6, commit:e987d92ad03981895a2a60db4f82420a12cd6cb7
Forwarded: https://github.com/flatpak/flatpak/pull/874
Applied-upstream: 0.8.8, commit:82495934823a501dccd54486143dee790ffe3f32
---
 common/flatpak-dir.c | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/common/flatpak-dir.c b/common/flatpak-dir.c
index f83fb71..83c0f1b 100644
--- a/common/flatpak-dir.c
+++ b/common/flatpak-dir.c
@@ -4509,11 +4509,20 @@ flatpak_dir_install (FlatpakDir          *self,
           /* We're pulling from a remote source, we do the network mirroring pull as a
              user and hand back the resulting data to the system-helper, that trusts us
              due to the GPG signatures in the repo */
+          g_autoptr(GBytes) summary_copy = NULL;
+          g_autoptr(GBytes) summary_sig_copy = NULL;
+          g_autoptr(GFile) summary_file = NULL;
+          g_autoptr(GFile) summary_sig_file = NULL;
 
           child_repo = flatpak_dir_create_system_child_repo (self, &child_repo_lock, error);
           if (child_repo == NULL)
             return FALSE;
 
+          if (!flatpak_dir_remote_fetch_summary (self, remote_name,
+                                                 &summary_copy, &summary_sig_copy,
+                                                 cancellable, error))
+            return FALSE;
+
           if (!flatpak_dir_pull (self, remote_name, ref, NULL, subpaths,
                                  child_repo,
                                  FLATPAK_PULL_FLAGS_DOWNLOAD_EXTRA_DATA | FLATPAK_PULL_FLAGS_SIDELOAD_EXTRA_DATA,
@@ -4521,6 +4530,20 @@ flatpak_dir_install (FlatpakDir          *self,
                                  progress, cancellable, error))
             return FALSE;
 
+          summary_file = g_file_get_child (ostree_repo_get_path (child_repo), "summary");
+          if (!g_file_replace_contents (summary_file,
+                                        g_bytes_get_data (summary_copy, NULL),
+                                        g_bytes_get_size (summary_copy),
+                                        NULL, FALSE, 0, NULL, cancellable, NULL))
+            return FALSE;
+
+          summary_sig_file = g_file_get_child (ostree_repo_get_path (child_repo), "summary.sig");
+          if (!g_file_replace_contents (summary_sig_file,
+                                        g_bytes_get_data (summary_sig_copy, NULL),
+                                        g_bytes_get_size (summary_sig_copy),
+                                        NULL, FALSE, 0, NULL, cancellable, NULL))
+            return FALSE;
+
           child_repo_path = g_file_get_path (ostree_repo_get_path (child_repo));
         }
 
