From 2b16b256088a5805c68c1a1f0764923f253df21a Mon Sep 17 00:00:00 2001
From: Simon McVittie <smcv@collabora.com>
Date: Wed, 14 Apr 2021 12:17:19 +0100
Subject: [PATCH] pv-wrap: Automatically use Flatpak sub-sandboxing if Flatpak
 is 1.11.x

Now that the ability to specify a custom path for /usr and /app has
been merged into Flatpak git master, we can mostly assume that if the
user has a git snapshot of Flatpak, they have that feature available.

Signed-off-by: Simon McVittie <smcv@collabora.com>
---
 pressure-vessel/launch.c       | 16 ----------------
 pressure-vessel/wrap-flatpak.c |  9 ++++++++-
 2 files changed, 8 insertions(+), 17 deletions(-)

diff --git a/pressure-vessel/launch.c b/pressure-vessel/launch.c
index 7d8ad44bd..d0c337995 100644
--- a/pressure-vessel/launch.c
+++ b/pressure-vessel/launch.c
@@ -1078,14 +1078,6 @@ main (int argc,
       g_debug ("Using \"%s\" as /app instead of runtime", opt_app_path);
 
       g_assert (api == &subsandbox_api);
-
-      if (g_getenv ("PRESSURE_VESSEL_FLATPAK_PR4018") == NULL)
-        {
-          glnx_throw (error,
-                      "--app-path requires an experimental branch of Flatpak");
-          goto out;
-        }
-
       check_portal_version ("app-path", 6);
 
       if (opt_app_path[0] == '\0')
@@ -1113,14 +1105,6 @@ main (int argc,
       g_debug ("Using %s as /usr instead of runtime", opt_usr_path);
 
       g_assert (api == &subsandbox_api);
-
-      if (g_getenv ("PRESSURE_VESSEL_FLATPAK_PR4018") == NULL)
-        {
-          glnx_throw (error,
-                      "--usr-path requires an experimental branch of Flatpak");
-          goto out;
-        }
-
       check_portal_version ("usr-path", 6);
 
       handle = path_to_handle (fd_list, opt_usr_path, home_realpath,
diff --git a/pressure-vessel/wrap-flatpak.c b/pressure-vessel/wrap-flatpak.c
index cb2e86e4a..fb0a9b8ef 100644
--- a/pressure-vessel/wrap-flatpak.c
+++ b/pressure-vessel/wrap-flatpak.c
@@ -149,11 +149,18 @@ pv_wrap_check_flatpak (const char *tools_dir,
                                         "pressure-vessel-launch",
                                         NULL);
 
+  if (flatpak_version != NULL && strverscmp (flatpak_version, "1.11.0") >= 0)
+    {
+      g_warning ("Using experimental Flatpak sub-sandboxing "
+                 "(requires Flatpak 1.11.x commit 1.10.1-65-g3ebf371f "
+                 "or later)");
+      subsandbox = get_subsandbox_adverb (launch_executable);
+    }
   /* Deliberately not documented: only people who are in a position
    * to run their own modified versions of Flatpak and pressure-vessel
    * should be using this, and those people can find this in the
    * source code */
-  if (g_getenv ("PRESSURE_VESSEL_FLATPAK_PR4018") != NULL)
+  else if (g_getenv ("PRESSURE_VESSEL_FLATPAK_PR4018") != NULL)
     {
       g_warning ("Assuming your version of Flatpak contains unmerged "
                  "changes (#4018, #4125, #4126, #4093)");
-- 
GitLab