Blame SOURCES/flatpak-1.10.2-system-helper-fix.patch

7b6f29
From 49e8bfcea516e96eb950109d0fa45811a352a517 Mon Sep 17 00:00:00 2001
7b6f29
From: Alexander Larsson <alexl@redhat.com>
7b6f29
Date: Wed, 17 Mar 2021 17:12:32 +0100
7b6f29
Subject: [PATCH] system-helper: Fix deploys of local remotes
7b6f29
7b6f29
For updates in remotes with a local (file:) uri we just do a deploy
7b6f29
with a LOCAL_PULL flag set and an empty arg_repo_path. However, our
7b6f29
arg_repo_path checking at some point seemed to stop properly handling
7b6f29
the case where it is empty. I got it to report "No such file" wich
7b6f29
broke the tests.
7b6f29
---
7b6f29
 system-helper/flatpak-system-helper.c | 89 ++++++++++++++-------------
7b6f29
 1 file changed, 46 insertions(+), 43 deletions(-)
7b6f29
7b6f29
diff --git a/system-helper/flatpak-system-helper.c b/system-helper/flatpak-system-helper.c
7b6f29
index b202c94105..adcfe61a86 100644
7b6f29
--- a/system-helper/flatpak-system-helper.c
7b6f29
+++ b/system-helper/flatpak-system-helper.c
7b6f29
@@ -410,61 +410,64 @@ handle_deploy (FlatpakSystemHelper   *object,
7b6f29
       return G_DBUS_METHOD_INVOCATION_HANDLED;
7b6f29
     }
7b6f29
 
7b6f29
-  src_dir = g_path_get_dirname (arg_repo_path);
7b6f29
-  ongoing_pull = take_ongoing_pull_by_dir (src_dir);
7b6f29
-  if (ongoing_pull != NULL)
7b6f29
+  if ((arg_flags & ~FLATPAK_HELPER_DEPLOY_FLAGS_ALL) != 0)
7b6f29
     {
7b6f29
-      g_autoptr(GError) local_error = NULL;
7b6f29
-      uid_t uid;
7b6f29
+      g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS,
7b6f29
+                                             "Unsupported flags enabled: 0x%x", (arg_flags & ~FLATPAK_HELPER_DEPLOY_FLAGS_ALL));
7b6f29
+      return G_DBUS_METHOD_INVOCATION_HANDLED;
7b6f29
+    }
7b6f29
 
7b6f29
-      /* Ensure that pull's uid is same as the caller's uid */
7b6f29
-      if (!get_connection_uid (invocation, &uid, &local_error))
7b6f29
+  if (strlen (arg_repo_path) > 0)
7b6f29
+    {
7b6f29
+      if (!g_file_query_exists (repo_file, NULL))
7b6f29
         {
7b6f29
-          g_dbus_method_invocation_return_gerror (invocation, local_error);
7b6f29
+          g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS,
7b6f29
+                                                 "Path does not exist");
7b6f29
           return G_DBUS_METHOD_INVOCATION_HANDLED;
7b6f29
         }
7b6f29
-      else
7b6f29
+
7b6f29
+      src_dir = g_path_get_dirname (arg_repo_path);
7b6f29
+      ongoing_pull = take_ongoing_pull_by_dir (src_dir);
7b6f29
+      if (ongoing_pull != NULL)
7b6f29
         {
7b6f29
-          if (ongoing_pull->uid != uid)
7b6f29
+          g_autoptr(GError) local_error = NULL;
7b6f29
+          uid_t uid;
7b6f29
+
7b6f29
+          /* Ensure that pull's uid is same as the caller's uid */
7b6f29
+          if (!get_connection_uid (invocation, &uid, &local_error))
7b6f29
             {
7b6f29
-              g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, G_DBUS_ERROR_FAILED,
7b6f29
-                                                     "Ongoing pull's uid(%d) does not match with peer uid(%d)",
7b6f29
-                                                     ongoing_pull->uid, uid);
7b6f29
+              g_dbus_method_invocation_return_gerror (invocation, local_error);
7b6f29
               return G_DBUS_METHOD_INVOCATION_HANDLED;
7b6f29
             }
7b6f29
-        }
7b6f29
-
7b6f29
-      terminate_revokefs_backend (ongoing_pull);
7b6f29
-
7b6f29
-      if (!flatpak_canonicalize_permissions (AT_FDCWD,
7b6f29
-                                             arg_repo_path,
7b6f29
-                                             getuid() == 0 ? 0 : -1,
7b6f29
-                                             getuid() == 0 ? 0 : -1,
7b6f29
-                                             &local_error))
7b6f29
-        {
7b6f29
-          g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, G_DBUS_ERROR_FAILED,
7b6f29
-                                                 "Failed to canonicalize permissions of repo %s: %s",
7b6f29
-                                                 arg_repo_path, local_error->message);
7b6f29
-          return G_DBUS_METHOD_INVOCATION_HANDLED;
7b6f29
-        }
7b6f29
+          else
7b6f29
+            {
7b6f29
+              if (ongoing_pull->uid != uid)
7b6f29
+                {
7b6f29
+                  g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, G_DBUS_ERROR_FAILED,
7b6f29
+                                                         "Ongoing pull's uid(%d) does not match with peer uid(%d)",
7b6f29
+                                                         ongoing_pull->uid, uid);
7b6f29
+                  return G_DBUS_METHOD_INVOCATION_HANDLED;
7b6f29
+                }
7b6f29
+            }
7b6f29
 
7b6f29
-      /* At this point, the cache-dir's repo is owned by root. Hence, any failure
7b6f29
-       * from here on, should always cleanup the cache-dir and not preserve it to be re-used. */
7b6f29
-      ongoing_pull->preserve_pull = FALSE;
7b6f29
-    }
7b6f29
+          terminate_revokefs_backend (ongoing_pull);
7b6f29
 
7b6f29
-  if ((arg_flags & ~FLATPAK_HELPER_DEPLOY_FLAGS_ALL) != 0)
7b6f29
-    {
7b6f29
-      g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS,
7b6f29
-                                             "Unsupported flags enabled: 0x%x", (arg_flags & ~FLATPAK_HELPER_DEPLOY_FLAGS_ALL));
7b6f29
-      return G_DBUS_METHOD_INVOCATION_HANDLED;
7b6f29
-    }
7b6f29
+          if (!flatpak_canonicalize_permissions (AT_FDCWD,
7b6f29
+                                                 arg_repo_path,
7b6f29
+                                                 getuid() == 0 ? 0 : -1,
7b6f29
+                                                 getuid() == 0 ? 0 : -1,
7b6f29
+                                                 &local_error))
7b6f29
+            {
7b6f29
+              g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, G_DBUS_ERROR_FAILED,
7b6f29
+                                                     "Failed to canonicalize permissions of repo %s: %s",
7b6f29
+                                                     arg_repo_path, local_error->message);
7b6f29
+              return G_DBUS_METHOD_INVOCATION_HANDLED;
7b6f29
+            }
7b6f29
 
7b6f29
-  if (!g_file_query_exists (repo_file, NULL))
7b6f29
-    {
7b6f29
-      g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS,
7b6f29
-                                             "Path does not exist");
7b6f29
-      return G_DBUS_METHOD_INVOCATION_HANDLED;
7b6f29
+          /* At this point, the cache-dir's repo is owned by root. Hence, any failure
7b6f29
+           * from here on, should always cleanup the cache-dir and not preserve it to be re-used. */
7b6f29
+          ongoing_pull->preserve_pull = FALSE;
7b6f29
+        }
7b6f29
     }
7b6f29
 
7b6f29
   ref = flatpak_decomposed_new_from_ref (arg_ref, &error);