diff --git a/app/flatpak-builtins-install.c b/app/flatpak-builtins-install.c index 9e68cee2..8c263d9e 100644 --- a/app/flatpak-builtins-install.c +++ b/app/flatpak-builtins-install.c @@ -382,7 +382,7 @@ flatpak_builtin_install (int argc, char **argv, GCancellable *cancellable, GErro if (remotes == NULL) return FALSE; - if (strchr (argv[1], '/') != NULL || strchr (argv[1], '.') != NULL) + if (!flatpak_allow_fuzzy_matching (argv[1])) matching_refs_flags = FIND_MATCHING_REFS_FLAGS_NONE; else matching_refs_flags = FIND_MATCHING_REFS_FLAGS_FUZZY; @@ -503,7 +503,7 @@ flatpak_builtin_install (int argc, char **argv, GCancellable *cancellable, GErro g_autoptr(GError) local_error = NULL; FindMatchingRefsFlags matching_refs_flags; - if (strchr (pref, '/') != NULL || strchr (pref, '.') != NULL) + if (!flatpak_allow_fuzzy_matching (pref)) matching_refs_flags = FIND_MATCHING_REFS_FLAGS_NONE; else matching_refs_flags = FIND_MATCHING_REFS_FLAGS_FUZZY; diff --git a/app/flatpak-builtins-uninstall.c b/app/flatpak-builtins-uninstall.c index ca9dcdaf..ec780f33 100644 --- a/app/flatpak-builtins-uninstall.c +++ b/app/flatpak-builtins-uninstall.c @@ -286,7 +286,7 @@ flatpak_builtin_uninstall (int argc, char **argv, GCancellable *cancellable, GEr pref = prefs[j]; - if (strchr (pref, '/') != NULL || strchr (pref, '.') != NULL) + if (!flatpak_allow_fuzzy_matching (pref)) matching_refs_flags = FIND_MATCHING_REFS_FLAGS_NONE; else matching_refs_flags = FIND_MATCHING_REFS_FLAGS_FUZZY; diff --git a/common/flatpak-utils-private.h b/common/flatpak-utils-private.h index d11339d6..70657075 100644 --- a/common/flatpak-utils-private.h +++ b/common/flatpak-utils-private.h @@ -841,6 +841,7 @@ gboolean flatpak_allocate_tmpdir (int tmpdir_dfd, GCancellable *cancellable, GError **error); +gboolean flatpak_allow_fuzzy_matching (const char *term); char * flatpak_prompt (gboolean allow_empty, const char *prompt, diff --git a/common/flatpak-utils.c b/common/flatpak-utils.c index bfafc229..2e96ce06 100644 --- a/common/flatpak-utils.c +++ b/common/flatpak-utils.c @@ -7411,6 +7411,24 @@ flatpak_allocate_tmpdir (int tmpdir_dfd, return TRUE; } +gboolean +flatpak_allow_fuzzy_matching (const char *term) +{ + if (strchr (term, '/') != NULL || strchr (term, '.') != NULL) + return FALSE; + + /* This env var is used by the unit tests and only skips the tty test not the + * check above. + */ + if (g_strcmp0 (g_getenv ("FLATPAK_FORCE_ALLOW_FUZZY_MATCHING"), "1") == 0) + return TRUE; + + if (!isatty (STDIN_FILENO) || !isatty (STDOUT_FILENO)) + return FALSE; + + return TRUE; +} + char * flatpak_prompt (gboolean allow_empty, const char *prompt, ...) diff --git a/tests/libtest.sh b/tests/libtest.sh index e63b9247..965cf667 100644 --- a/tests/libtest.sh +++ b/tests/libtest.sh @@ -99,6 +99,7 @@ export FLATPAK_SYSTEM_HELPER_ON_SESSION=1 export FLATPAK_CONFIG_DIR=${TEST_DATA_DIR}/config export FLATPAK_RUN_DIR=${TEST_DATA_DIR}/run export FLATPAK_FANCY_OUTPUT=0 +export FLATPAK_FORCE_ALLOW_FUZZY_MATCHING=1 export HOME=${TEST_DATA_DIR}/home export XDG_CACHE_HOME=${TEST_DATA_DIR}/home/cache