Blame SOURCES/flatpak-1.0.4-oci-fixes.patch

1d7db6
From 3f5235e925ba6555cd9c639684660356867c952f Mon Sep 17 00:00:00 2001
1d7db6
From: "Owen W. Taylor" <otaylor@fishsoup.net>
1d7db6
Date: Fri, 30 Nov 2018 16:11:06 -0500
1d7db6
Subject: [PATCH 1/3] flatpak_cache_http_uri: save downloaded files with
1d7db6
 permission 0644
1d7db6
1d7db6
Previously, downloaded files were being saved with 0600 permissions,
1d7db6
which prevented OCI icons downloaded by the system helper at appstream
1d7db6
creation time from being read by users.
1d7db6
1d7db6
Closes: #2362
1d7db6
Approved by: matthiasclasen
1d7db6
---
1d7db6
 common/flatpak-utils-http.c | 3 +++
1d7db6
 1 file changed, 3 insertions(+)
1d7db6
1d7db6
diff --git a/common/flatpak-utils-http.c b/common/flatpak-utils-http.c
1d7db6
index 53074162..997c9db8 100644
1d7db6
--- a/common/flatpak-utils-http.c
1d7db6
+++ b/common/flatpak-utils-http.c
1d7db6
@@ -645,6 +645,9 @@ sync_and_rename_tmpfile (GLnxTmpfile *tmpfile,
1d7db6
   if (fdatasync (tmpfile->fd) != 0)
1d7db6
     return glnx_throw_errno_prefix (error, "fdatasync");
1d7db6
 
1d7db6
+  if (fchmod (tmpfile->fd, 0644) != 0)
1d7db6
+    return glnx_throw_errno_prefix (error, "fchmod");
1d7db6
+
1d7db6
   if (!glnx_link_tmpfile_at (tmpfile,
1d7db6
                              GLNX_LINK_TMPFILE_REPLACE,
1d7db6
                              tmpfile->src_dfd, dest_name, error))
1d7db6
-- 
1d7db6
2.19.2
1d7db6
1d7db6
1d7db6
From 3263827dbbd4d84919899e91ca066d2d3cf338bc Mon Sep 17 00:00:00 2001
1d7db6
From: Alexander Larsson <alexl@redhat.com>
1d7db6
Date: Fri, 30 Nov 2018 10:30:20 +0100
1d7db6
Subject: [PATCH 2/3] OCI: Use system helper to generate summary for OCI
1d7db6
 remotes
1d7db6
1d7db6
The OCI support relies on downloading a json index and converting it
1d7db6
to a ostree-style summary, which we the use in all sorts of operations
1d7db6
in the client code. Currently this happens in the user code, which means
1d7db6
that it will fail (due to permissions) in the system installation case.
1d7db6
1d7db6
We could do the conversion as the user, but when eventually installing
1d7db6
something the system-helper will anyway do this download and
1d7db6
conversion, so that would only double the work and risk things going out
1d7db6
of sync. Also, the OCI index is not gpg signed, so we can't realy on
1d7db6
downloads done as the user.
1d7db6
1d7db6
So, the solution done here is to add a GenerateOciSummary
1d7db6
system-helper call which we use instead of directly generating the
1d7db6
oci summary.
1d7db6
1d7db6
This fixes https://github.com/flatpak/flatpak/issues/2350
1d7db6
1d7db6
Closes: #2363
1d7db6
Approved by: matthiasclasen
1d7db6
---
1d7db6
 common/flatpak-dir-private.h          |  5 ++
1d7db6
 common/flatpak-dir.c                  | 94 +++++++++++++++++++--------
1d7db6
 data/org.freedesktop.Flatpak.xml      |  5 ++
1d7db6
 system-helper/flatpak-system-helper.c | 52 ++++++++++++++-
1d7db6
 4 files changed, 129 insertions(+), 27 deletions(-)
1d7db6
1d7db6
diff --git a/common/flatpak-dir-private.h b/common/flatpak-dir-private.h
1d7db6
index 64a72758..f6126056 100644
1d7db6
--- a/common/flatpak-dir-private.h
1d7db6
+++ b/common/flatpak-dir-private.h
1d7db6
@@ -718,6 +718,11 @@ FlatpakRemoteState * flatpak_dir_get_remote_state_for_summary (FlatpakDir   *sel
1d7db6
                                                                GBytes       *opt_summary_sig,
1d7db6
                                                                GCancellable *cancellable,
1d7db6
                                                                GError      **error);
1d7db6
+gboolean flatpak_dir_remote_make_oci_summary (FlatpakDir   *self,
1d7db6
+                                              const char   *remote,
1d7db6
+                                              GBytes      **out_summary,
1d7db6
+                                              GCancellable *cancellable,
1d7db6
+                                              GError      **error);
1d7db6
 FlatpakRemoteState * flatpak_dir_get_remote_state_optional (FlatpakDir   *self,
1d7db6
                                                             const char   *remote,
1d7db6
                                                             GCancellable *cancellable,
1d7db6
diff --git a/common/flatpak-dir.c b/common/flatpak-dir.c
1d7db6
index 828945ca..7853b74a 100644
1d7db6
--- a/common/flatpak-dir.c
1d7db6
+++ b/common/flatpak-dir.c
1d7db6
@@ -1385,6 +1385,22 @@ flatpak_dir_system_helper_call_update_summary (FlatpakDir   *self,
1d7db6
   return ret != NULL;
1d7db6
 }
1d7db6
 
1d7db6
+static gboolean
1d7db6
+flatpak_dir_system_helper_call_generate_oci_summary (FlatpakDir   *self,
1d7db6
+                                                     const gchar  *arg_origin,
1d7db6
+                                                     const gchar  *arg_installation,
1d7db6
+                                                     GCancellable *cancellable,
1d7db6
+                                                     GError      **error)
1d7db6
+{
1d7db6
+  g_autoptr(GVariant) ret =
1d7db6
+    flatpak_dir_system_helper_call (self, "GenerateOciSummary",
1d7db6
+                                    g_variant_new ("(ss)",
1d7db6
+                                                   arg_origin,
1d7db6
+                                                   arg_installation),
1d7db6
+                                    cancellable, error);
1d7db6
+  return ret != NULL;
1d7db6
+}
1d7db6
+
1d7db6
 static OstreeRepo *
1d7db6
 system_ostree_repo_new (GFile *repodir)
1d7db6
 {
1d7db6
@@ -9088,7 +9104,7 @@ flatpak_dir_cache_summary (FlatpakDir *self,
1d7db6
   G_UNLOCK (cache);
1d7db6
 }
1d7db6
 
1d7db6
-static gboolean
1d7db6
+gboolean
1d7db6
 flatpak_dir_remote_make_oci_summary (FlatpakDir   *self,
1d7db6
                                      const char   *remote,
1d7db6
                                      GBytes      **out_summary,
1d7db6
@@ -9103,42 +9119,68 @@ flatpak_dir_remote_make_oci_summary (FlatpakDir   *self,
1d7db6
   g_autoptr(GError) local_error = NULL;
1d7db6
   g_autoptr(GMappedFile) mfile = NULL;
1d7db6
   g_autoptr(GBytes) cache_bytes = NULL;
1d7db6
+  g_autoptr(GBytes) summary_bytes = NULL;
1d7db6
 
1d7db6
-  self_name = flatpak_dir_get_name (self);
1d7db6
-
1d7db6
-  index_cache = flatpak_dir_update_oci_index (self, remote, &index_uri, cancellable, error);
1d7db6
-  if (index_cache == NULL)
1d7db6
-    return FALSE;
1d7db6
+  if (flatpak_dir_use_system_helper (self, NULL))
1d7db6
+    {
1d7db6
+      const char *installation = flatpak_dir_get_id (self);
1d7db6
 
1d7db6
-  summary_cache = flatpak_dir_get_oci_summary_location (self, remote, error);
1d7db6
-  if (summary_cache == NULL)
1d7db6
-    return FALSE;
1d7db6
+      if (!flatpak_dir_system_helper_call_generate_oci_summary (self, remote,
1d7db6
+                                                                installation ? installation : "",
1d7db6
+                                                                cancellable, error))
1d7db6
+        return FALSE;
1d7db6
 
1d7db6
-  if (check_destination_mtime (index_cache, summary_cache, cancellable))
1d7db6
+      summary_cache = flatpak_dir_get_oci_summary_location (self, remote, error);
1d7db6
+      if (summary_cache == NULL)
1d7db6
+        return FALSE;
1d7db6
+    }
1d7db6
+  else
1d7db6
     {
1d7db6
-      mfile = g_mapped_file_new (flatpak_file_get_path_cached (summary_cache), FALSE, NULL);
1d7db6
-      if (mfile)
1d7db6
+      self_name = flatpak_dir_get_name (self);
1d7db6
+
1d7db6
+      index_cache = flatpak_dir_update_oci_index (self, remote, &index_uri, cancellable, error);
1d7db6
+      if (index_cache == NULL)
1d7db6
+        return FALSE;
1d7db6
+
1d7db6
+      summary_cache = flatpak_dir_get_oci_summary_location (self, remote, error);
1d7db6
+      if (summary_cache == NULL)
1d7db6
+        return FALSE;
1d7db6
+
1d7db6
+      if (!check_destination_mtime (index_cache, summary_cache, cancellable))
1d7db6
         {
1d7db6
-          cache_bytes = g_mapped_file_get_bytes (mfile);
1d7db6
-          *out_summary = g_steal_pointer (&cache_bytes);
1d7db6
+          summary = flatpak_oci_index_make_summary (index_cache, index_uri, cancellable, &local_error);
1d7db6
+          if (summary == NULL)
1d7db6
+            {
1d7db6
+              g_propagate_error (error, g_steal_pointer (&local_error));
1d7db6
+              return FALSE;
1d7db6
+            }
1d7db6
+
1d7db6
+          summary_bytes = g_variant_get_data_as_bytes (summary);
1d7db6
+
1d7db6
+          if (!g_file_replace_contents (summary_cache,
1d7db6
+                                        g_bytes_get_data (summary_bytes, NULL),
1d7db6
+                                        g_bytes_get_size (summary_bytes),
1d7db6
+                                        NULL, FALSE, 0, NULL, cancellable, error))
1d7db6
+            {
1d7db6
+              g_prefix_error (error, _("Failed to write summary cache: "));
1d7db6
+              return FALSE;
1d7db6
+            }
1d7db6
+
1d7db6
+          if (out_summary)
1d7db6
+              *out_summary = g_steal_pointer (&summary_bytes);
1d7db6
           return TRUE;
1d7db6
         }
1d7db6
     }
1d7db6
 
1d7db6
-  summary = flatpak_oci_index_make_summary (index_cache, index_uri, cancellable, &local_error);
1d7db6
-  if (summary == NULL)
1d7db6
+  if (out_summary)
1d7db6
     {
1d7db6
-      g_propagate_error (error, g_steal_pointer (&local_error));
1d7db6
-      return FALSE;
1d7db6
-    }
1d7db6
-
1d7db6
-  *out_summary = g_variant_get_data_as_bytes (summary);
1d7db6
+      mfile = g_mapped_file_new (flatpak_file_get_path_cached (summary_cache), FALSE, error);
1d7db6
+      if (mfile == NULL)
1d7db6
+        return FALSE;
1d7db6
 
1d7db6
-  if (!g_file_replace_contents (summary_cache,
1d7db6
-                                g_bytes_get_data (*out_summary, NULL),
1d7db6
-                                g_bytes_get_size (*out_summary),
1d7db6
-                                NULL, FALSE, 0, NULL, cancellable, NULL))
1d7db6
-    g_warning ("Failed to write summary cache");
1d7db6
+      cache_bytes = g_mapped_file_get_bytes (mfile);
1d7db6
+      *out_summary = g_steal_pointer (&cache_bytes);
1d7db6
+    }
1d7db6
 
1d7db6
   return TRUE;
1d7db6
 }
1d7db6
diff --git a/data/org.freedesktop.Flatpak.xml b/data/org.freedesktop.Flatpak.xml
1d7db6
index 25dc8a02..8b1606c6 100644
1d7db6
--- a/data/org.freedesktop.Flatpak.xml
1d7db6
+++ b/data/org.freedesktop.Flatpak.xml
1d7db6
@@ -144,6 +144,11 @@
1d7db6
       <arg type='s' name='installation' direction='in'/>
1d7db6
     </method>
1d7db6
 
1d7db6
+    <method name="GenerateOciSummary">
1d7db6
+      <arg type='s' name='origin' direction='in'/>
1d7db6
+      <arg type='s' name='installation' direction='in'/>
1d7db6
+    </method>
1d7db6
+
1d7db6
   </interface>
1d7db6
 
1d7db6
 </node>
1d7db6
diff --git a/system-helper/flatpak-system-helper.c b/system-helper/flatpak-system-helper.c
1d7db6
index ce647b6e..29a2d3e1 100644
1d7db6
--- a/system-helper/flatpak-system-helper.c
1d7db6
+++ b/system-helper/flatpak-system-helper.c
1d7db6
@@ -1122,6 +1122,54 @@ handle_update_summary (FlatpakSystemHelper   *object,
1d7db6
   return TRUE;
1d7db6
 }
1d7db6
 
1d7db6
+static gboolean
1d7db6
+handle_generate_oci_summary (FlatpakSystemHelper   *object,
1d7db6
+                             GDBusMethodInvocation *invocation,
1d7db6
+                             const gchar           *arg_origin,
1d7db6
+                             const gchar           *arg_installation)
1d7db6
+{
1d7db6
+  g_autoptr(FlatpakDir) system = NULL;
1d7db6
+  g_autoptr(GError) error = NULL;
1d7db6
+  gboolean is_oci;
1d7db6
+
1d7db6
+  g_debug ("GenerateOciSummary %s %s", arg_origin, arg_installation);
1d7db6
+
1d7db6
+  system = dir_get_system (arg_installation, &error);
1d7db6
+  if (system == NULL)
1d7db6
+    {
1d7db6
+      g_dbus_method_invocation_return_gerror (invocation, error);
1d7db6
+      return TRUE;
1d7db6
+    }
1d7db6
+
1d7db6
+  if (!flatpak_dir_ensure_repo (system, NULL, &error))
1d7db6
+    {
1d7db6
+      g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, G_DBUS_ERROR_FAILED,
1d7db6
+                                             "Can't open system repo %s", error->message);
1d7db6
+      return TRUE;
1d7db6
+    }
1d7db6
+
1d7db6
+  is_oci = flatpak_dir_get_remote_oci (system, arg_origin);
1d7db6
+  if (!is_oci)
1d7db6
+    {
1d7db6
+      g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS,
1d7db6
+                                             "%s is not a OCI remote", arg_origin);
1d7db6
+      return TRUE;
1d7db6
+    }
1d7db6
+
1d7db6
+  if (!flatpak_dir_remote_make_oci_summary (system, arg_origin, NULL, NULL, &error))
1d7db6
+    {
1d7db6
+      g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, G_DBUS_ERROR_FAILED,
1d7db6
+                                             "Failed to update OCI summary: %s", error->message);
1d7db6
+      return TRUE;
1d7db6
+    }
1d7db6
+
1d7db6
+
1d7db6
+  flatpak_system_helper_complete_generate_oci_summary (object, invocation);
1d7db6
+
1d7db6
+  return TRUE;
1d7db6
+}
1d7db6
+
1d7db6
+
1d7db6
 static gboolean
1d7db6
 flatpak_authorize_method_handler (GDBusInterfaceSkeleton *interface,
1d7db6
                                   GDBusMethodInvocation  *invocation,
1d7db6
@@ -1250,7 +1298,8 @@ flatpak_authorize_method_handler (GDBusInterfaceSkeleton *interface,
1d7db6
            g_strcmp0 (method_name, "PruneLocalRepo") == 0 ||
1d7db6
            g_strcmp0 (method_name, "EnsureRepo") == 0 ||
1d7db6
            g_strcmp0 (method_name, "RunTriggers") == 0 ||
1d7db6
-           g_strcmp0 (method_name, "UpdateSummary") == 0)
1d7db6
+           g_strcmp0 (method_name, "UpdateSummary") == 0 ||
1d7db6
+           g_strcmp0 (method_name, "GenerateOciSummary") == 0)
1d7db6
     {
1d7db6
       const char *remote;
1d7db6
 
1d7db6
@@ -1321,6 +1370,7 @@ on_bus_acquired (GDBusConnection *connection,
1d7db6
   g_signal_connect (helper, "handle-ensure-repo", G_CALLBACK (handle_ensure_repo), NULL);
1d7db6
   g_signal_connect (helper, "handle-run-triggers", G_CALLBACK (handle_run_triggers), NULL);
1d7db6
   g_signal_connect (helper, "handle-update-summary", G_CALLBACK (handle_update_summary), NULL);
1d7db6
+  g_signal_connect (helper, "handle-generate-oci-summary", G_CALLBACK (handle_generate_oci_summary), NULL);
1d7db6
 
1d7db6
   g_signal_connect (helper, "g-authorize-method",
1d7db6
                     G_CALLBACK (flatpak_authorize_method_handler),
1d7db6
-- 
1d7db6
2.19.2
1d7db6
1d7db6
1d7db6
From b7f1d5118fc4e1df472f7108472f122e279fe2b9 Mon Sep 17 00:00:00 2001
1d7db6
From: Matthias Clasen <mclasen@redhat.com>
1d7db6
Date: Fri, 7 Dec 2018 14:39:06 -0500
1d7db6
Subject: [PATCH 3/3] Fix oci pull progress reporting
1d7db6
1d7db6
Comparing the code in flatpak-utils.c:progress_cb,
1d7db6
we need to set bytes-transferred for the total amount
1d7db6
of data that has been transferred so far. The value
1d7db6
we were setting so far, fetched-delta-part-size, refers
1d7db6
to the size of the objects we already have locally, and
1d7db6
is subtracted from the total, which explains oci progress
1d7db6
running backwards.
1d7db6
1d7db6
Closes: #2392
1d7db6
1d7db6
Closes: #2400
1d7db6
Approved by: matthiasclasen
1d7db6
---
1d7db6
 common/flatpak-dir.c | 2 +-
1d7db6
 1 file changed, 1 insertion(+), 1 deletion(-)
1d7db6
1d7db6
diff --git a/common/flatpak-dir.c b/common/flatpak-dir.c
1d7db6
index 7853b74a..51cd1e66 100644
1d7db6
--- a/common/flatpak-dir.c
1d7db6
+++ b/common/flatpak-dir.c
1d7db6
@@ -4154,7 +4154,7 @@ oci_pull_progress_cb (guint64 total_size, guint64 pulled_size,
1d7db6
                              "total-delta-parts", "u", n_layers,
1d7db6
                              "fetched-delta-fallbacks", "u", 0,
1d7db6
                              "total-delta-fallbacks", "u", 0,
1d7db6
-                             "fetched-delta-part-size", "t", pulled_size,
1d7db6
+                             "bytes-transferred", "t", pulled_size,
1d7db6
                              "total-delta-part-size", "t", total_size,
1d7db6
                              "total-delta-part-usize", "t", total_size,
1d7db6
                              "total-delta-superblocks", "u", 0,
1d7db6
-- 
1d7db6
2.19.2
1d7db6