diff --git a/app/flatpak-builtins-add-remote.c b/app/flatpak-builtins-add-remote.c index be3e05809..f5a0e72f4 100644 --- a/app/flatpak-builtins-add-remote.c +++ b/app/flatpak-builtins-add-remote.c @@ -403,7 +403,7 @@ flatpak_builtin_add_remote (int argc, char **argv, } if (opt_from || - g_str_has_suffix (location, ".flatpakrepo")) + flatpak_file_arg_has_suffix (location, ".flatpakrepo")) { load_options (location, &gpg_data); if (opt_url == NULL) diff --git a/app/flatpak-builtins-install.c b/app/flatpak-builtins-install.c index d5e9fceed..2fea513ea 100644 --- a/app/flatpak-builtins-install.c +++ b/app/flatpak-builtins-install.c @@ -375,6 +375,7 @@ install_from (FlatpakDir *dir, return TRUE; } + gboolean flatpak_builtin_install (int argc, char **argv, GCancellable *cancellable, GError **error) { @@ -396,9 +397,9 @@ flatpak_builtin_install (int argc, char **argv, GCancellable *cancellable, GErro if (!opt_bundle && !opt_from && argc >= 2) { - if (g_str_has_suffix (argv[1], ".flatpakref")) + if (flatpak_file_arg_has_suffix (argv[1], ".flatpakref")) opt_from = TRUE; - if (g_str_has_suffix (argv[1], ".flatpak")) + if (flatpak_file_arg_has_suffix (argv[1], ".flatpak")) opt_bundle = TRUE; } diff --git a/common/flatpak-utils.c b/common/flatpak-utils.c index 515b0c389..0edcca684 100644 --- a/common/flatpak-utils.c +++ b/common/flatpak-utils.c @@ -1924,6 +1924,16 @@ flatpak_quote_argv (const char *argv[]) return g_string_free (res, FALSE); } +/* This is useful, because it handles escaped characters in uris, and ? arguments at the end of the uri */ +gboolean +flatpak_file_arg_has_suffix (const char *arg, const char *suffix) +{ + g_autoptr(GFile) file = g_file_new_for_commandline_arg (arg); + g_autofree char *basename = g_file_get_basename (file); + + return g_str_has_suffix (basename, suffix); +} + gboolean flatpak_spawn (GFile *dir, char **output, diff --git a/common/flatpak-utils.h b/common/flatpak-utils.h index 5455674da..92002b06f 100644 --- a/common/flatpak-utils.h +++ b/common/flatpak-utils.h @@ -383,6 +383,7 @@ GList *flatpak_list_extensions (GKeyFile *metakey, const char *branch); char * flatpak_quote_argv (const char *argv[]); +gboolean flatpak_file_arg_has_suffix (const char *arg, const char *suffix); gboolean flatpak_spawn (GFile *dir, char **output,