From 49f343a4edfec2e5e6ac9d6b64dd11775fa4c84a Mon Sep 17 00:00:00 2001 From: Sebastian Wick Date: Sat, 8 Jun 2024 14:22:41 +0200 Subject: [PATCH] app-info: Make xdp_app_info_remap_path private There is no remaining user of this function so we can make it private and remove it from the header. --- src/xdp-app-info.c | 108 ++++++++++++++++++++++----------------------- src/xdp-app-info.h | 3 -- 2 files changed, 54 insertions(+), 57 deletions(-) diff --git a/src/xdp-app-info.c b/src/xdp-app-info.c index 52e54bddb..dd300115c 100644 --- a/src/xdp-app-info.c +++ b/src/xdp-app-info.c @@ -318,6 +318,59 @@ xdp_app_info_get_pidns (XdpAppInfo *app_info, return TRUE; } +static char * +remap_path (XdpAppInfo *app_info, + const char *path) +{ + XdpAppInfoPrivate *priv = xdp_app_info_get_instance_private (app_info); + + if (priv->kind == XDP_APP_INFO_KIND_FLATPAK) + { + g_autofree char *app_path = g_key_file_get_string (priv->u.flatpak.keyfile, + FLATPAK_METADATA_GROUP_INSTANCE, + FLATPAK_METADATA_KEY_APP_PATH, NULL); + g_autofree char *runtime_path = g_key_file_get_string (priv->u.flatpak.keyfile, + FLATPAK_METADATA_GROUP_INSTANCE, + FLATPAK_METADATA_KEY_RUNTIME_PATH, + NULL); + + /* For apps we translate /app and /usr to the installed locations. + Also, we need to rewrite to drop the /newroot prefix added by + bubblewrap for other files to work. See + https://github.com/projectatomic/bubblewrap/pull/172 + for a bit more information on the /newroot issue. + */ + + if (g_str_has_prefix (path, "/newroot/")) + path = path + strlen ("/newroot"); + + if (app_path != NULL && g_str_has_prefix (path, "/app/")) + return g_build_filename (app_path, path + strlen ("/app/"), NULL); + else if (runtime_path != NULL && g_str_has_prefix (path, "/usr/")) + return g_build_filename (runtime_path, path + strlen ("/usr/"), NULL); + else if (g_str_has_prefix (path, "/run/host/usr/")) + return g_build_filename ("/usr", path + strlen ("/run/host/usr/"), NULL); + else if (g_str_has_prefix (path, "/run/host/etc/")) + return g_build_filename ("/etc", path + strlen ("/run/host/etc/"), NULL); + else if (g_str_has_prefix (path, "/run/flatpak/app/")) + return g_build_filename (g_get_user_runtime_dir (), "app", + path + strlen ("/run/flatpak/app/"), NULL); + else if (g_str_has_prefix (path, "/run/flatpak/doc/")) + return g_build_filename (g_get_user_runtime_dir (), "doc", + path + strlen ("/run/flatpak/doc/"), NULL); + else if (g_str_has_prefix (path, "/var/config/")) + return g_build_filename (g_get_home_dir (), ".var", "app", + priv->id, "config", + path + strlen ("/var/config/"), NULL); + else if (g_str_has_prefix (path, "/var/data/")) + return g_build_filename (g_get_home_dir (), ".var", "app", + priv->id, "data", + path + strlen ("/var/data/"), NULL); + } + + return g_strdup (path); +} + static gboolean xdp_app_info_supports_opath (XdpAppInfo *app_info) { @@ -386,7 +439,7 @@ verify_proc_self_fd (XdpAppInfo *app_info, } /* remap from sandbox to host if needed */ - return xdp_app_info_remap_path (app_info, path_buffer); + return remap_path (app_info, path_buffer); } static gboolean @@ -595,59 +648,6 @@ xdp_app_info_get_path_for_fd (XdpAppInfo *app_info, return g_steal_pointer (&path); } -char * -xdp_app_info_remap_path (XdpAppInfo *app_info, - const char *path) -{ - XdpAppInfoPrivate *priv = xdp_app_info_get_instance_private (app_info); - - if (priv->kind == XDP_APP_INFO_KIND_FLATPAK) - { - g_autofree char *app_path = g_key_file_get_string (priv->u.flatpak.keyfile, - FLATPAK_METADATA_GROUP_INSTANCE, - FLATPAK_METADATA_KEY_APP_PATH, NULL); - g_autofree char *runtime_path = g_key_file_get_string (priv->u.flatpak.keyfile, - FLATPAK_METADATA_GROUP_INSTANCE, - FLATPAK_METADATA_KEY_RUNTIME_PATH, - NULL); - - /* For apps we translate /app and /usr to the installed locations. - Also, we need to rewrite to drop the /newroot prefix added by - bubblewrap for other files to work. See - https://github.com/projectatomic/bubblewrap/pull/172 - for a bit more information on the /newroot issue. - */ - - if (g_str_has_prefix (path, "/newroot/")) - path = path + strlen ("/newroot"); - - if (app_path != NULL && g_str_has_prefix (path, "/app/")) - return g_build_filename (app_path, path + strlen ("/app/"), NULL); - else if (runtime_path != NULL && g_str_has_prefix (path, "/usr/")) - return g_build_filename (runtime_path, path + strlen ("/usr/"), NULL); - else if (g_str_has_prefix (path, "/run/host/usr/")) - return g_build_filename ("/usr", path + strlen ("/run/host/usr/"), NULL); - else if (g_str_has_prefix (path, "/run/host/etc/")) - return g_build_filename ("/etc", path + strlen ("/run/host/etc/"), NULL); - else if (g_str_has_prefix (path, "/run/flatpak/app/")) - return g_build_filename (g_get_user_runtime_dir (), "app", - path + strlen ("/run/flatpak/app/"), NULL); - else if (g_str_has_prefix (path, "/run/flatpak/doc/")) - return g_build_filename (g_get_user_runtime_dir (), "doc", - path + strlen ("/run/flatpak/doc/"), NULL); - else if (g_str_has_prefix (path, "/var/config/")) - return g_build_filename (g_get_home_dir (), ".var", "app", - priv->id, "config", - path + strlen ("/var/config/"), NULL); - else if (g_str_has_prefix (path, "/var/data/")) - return g_build_filename (g_get_home_dir (), ".var", "app", - priv->id, "data", - path + strlen ("/var/data/"), NULL); - } - - return g_strdup (path); -} - static char ** rewrite_commandline (XdpAppInfo *app_info, const char * const *commandline, diff --git a/src/xdp-app-info.h b/src/xdp-app-info.h index 834bdd935..6defe6946 100644 --- a/src/xdp-app-info.h +++ b/src/xdp-app-info.h @@ -52,9 +52,6 @@ char * xdp_app_info_get_path_for_fd (XdpAppInfo *app_info, gboolean *writable_out, GError **error); -char * xdp_app_info_remap_path (XdpAppInfo *app_info, - const char *path); - gboolean xdp_app_info_validate_autostart (XdpAppInfo *app_info, GKeyFile *keyfile, const char * const *autostart_exec,