mirror of
https://github.com/flatpak/flatpak.git
synced 2026-03-29 04:14:23 -04:00
app: Disable fuzzy matching if not on a tty
As discussed in #4848, this disables fuzzy matching entirely if stdin or stdout is not a tty, meaning that something like "flatpak install firefox" would be treated as incorrect syntax, since this syntax is intended for interactive CLI use. Even before this commit, "flatpak install firefox" would error out if run without a tty, since we don't automatically choose a matching app ID even if there is only one match. However "flatpak install -y firefox" could work before, but won't any more. People should be specifying the full app ID in any context other than a tty. This commit also introduces a new env var so the unit tests can continue to check the fuzzy matching behavior, despite them being run without a tty.
This commit is contained in:
committed by
Simon McVittie
parent
5acb4ee7e4
commit
c7d262b375
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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, ...)
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user