diff options
| author | Harald Judt <h.judt@gmx.at> | 2015-02-27 22:26:09 +0100 |
|---|---|---|
| committer | Harald Judt <h.judt@gmx.at> | 2015-02-28 13:39:49 +0100 |
| commit | b385bcf7c856fdc0a63b5f91a6d4053a7d22347e (patch) | |
| tree | 26ed8b270c38dd64aa0f22f736ece5bd3f6a262f | |
| parent | 3be61269f30a34e80790cbc0152f9c73e441b8c1 (diff) | |
| download | thunar-b385bcf7c856fdc0a63b5f91a6d4053a7d22347e.tar.gz | |
Improve check for shell scripts and add hidden option forBug #7596
The check for shell scripts was incomplete. This commit extends it to
all executable scripts that are text/plain. For people wanting the
old, unsafe behaviour there is a new boolean option called
"misc-exec-shell-scripts-by-default" that can be created and set to
TRUE using xfconf-query or the Xfce settings editor.
| -rw-r--r-- | thunar/thunar-file.c | 34 | ||||
| -rw-r--r-- | thunar/thunar-preferences.c | 17 |
2 files changed, 36 insertions, 15 deletions
diff --git a/thunar/thunar-file.c b/thunar/thunar-file.c index e254347..9b5aa9b 100644 --- a/thunar/thunar-file.c +++ b/thunar/thunar-file.c @@ -63,6 +63,7 @@ #include <thunar/thunar-gio-extensions.h> #include <thunar/thunar-gobject-extensions.h> #include <thunar/thunar-private.h> +#include <thunar/thunar-preferences.h> #include <thunar/thunar-user.h> #include <thunar/thunar-util.h> #include <thunar/thunar-dialogs.h> @@ -2755,8 +2756,10 @@ thunar_file_is_ancestor (const ThunarFile *file, gboolean thunar_file_is_executable (const ThunarFile *file) { - gboolean can_execute = FALSE; - const gchar *content_type; + ThunarPreferences *preferences; + gboolean can_execute = FALSE; + gboolean exec_shell_scripts = FALSE; + const gchar *content_type; _thunar_return_val_if_fail (THUNAR_IS_FILE (file), FALSE); @@ -2769,20 +2772,21 @@ thunar_file_is_executable (const ThunarFile *file) content_type = thunar_file_get_content_type (THUNAR_FILE (file)); if (G_LIKELY (content_type != NULL)) { -#ifdef G_OS_WIN32 - /* check for .exe, .bar or .com */ can_execute = g_content_type_can_be_executable (content_type); -#else - /* Check if the content type is safe to execute, we don't - * use g_content_type_can_be_executable() for unix because - * it also returns true for "text/plain" and we don't want - * that. Also do not execute x-shellscripts by default, it - * is safer to open them in an editor or run them in a - * terminal, usually they require parameters. */ - if (g_content_type_is_a (content_type, "application/x-executable") - && ! g_content_type_is_a (content_type, "application/x-shellscript")) - can_execute = TRUE; -#endif + + if (can_execute) + { + /* check if the shell scripts should be executed or opened by default */ + preferences = thunar_preferences_get (); + g_object_get (preferences, "misc-exec-shell-scripts-by-default", &exec_shell_scripts, NULL); + g_object_unref (preferences); + + /* do never execute plain text files which are not shell scripts but marked executable */ + if (g_strcmp0 (content_type, "text/plain") == 0) + can_execute = FALSE; + else if (g_content_type_is_a (content_type, "text/plain") && ! exec_shell_scripts) + can_execute = FALSE; + } } } diff --git a/thunar/thunar-preferences.c b/thunar/thunar-preferences.c index 684485f..9a86ae1 100644 --- a/thunar/thunar-preferences.c +++ b/thunar/thunar-preferences.c @@ -75,6 +75,7 @@ enum PROP_MISC_VOLUME_MANAGEMENT, PROP_MISC_CASE_SENSITIVE, PROP_MISC_DATE_STYLE, + PROP_EXEC_SHELL_SCRIPTS_BY_DEFAULT, PROP_MISC_FOLDERS_FIRST, PROP_MISC_FULL_PATH_IN_TITLE, PROP_MISC_HORIZONTAL_WHEEL_NAVIGATES, @@ -492,6 +493,22 @@ thunar_preferences_class_init (ThunarPreferencesClass *klass) EXO_PARAM_READWRITE); /** + * ThunarPreferences:misc-execute-shell-scripts-by-default: + * + * Shell scripts are often unsafe to execute, require additional + * parameters and most users will only want to edit them in their + * favorite editor, so the default is to open them in the associated + * application. Setting this to TRUE allows executing them, like + * binaries, by default. See bug #7596. + **/ + preferences_props[PROP_EXEC_SHELL_SCRIPTS_BY_DEFAULT] = + g_param_spec_boolean ("misc-exec-shell-scripts-by-default", + "MiscExecShellScriptsByDefault", + NULL, + FALSE, + EXO_PARAM_READWRITE); + + /** * ThunarPreferences:misc-folders-first: * * Whether to sort folders before files. |