[kupfer] fileactions: Only allow Running "sane" executables



commit 12d8c32adb435e32181eee76345c83d0b1074ab5
Author: Ulrik Sverdrup <ulrik sverdrup gmail com>
Date:   Mon Mar 21 15:22:39 2011 +0100

    fileactions: Only allow Running "sane" executables
    
    Ask gio which content types are likely to be executable.
    
    At the same time, increase the rank of Execute to be above Open since
    we now have fewer false positives.

 kupfer/obj/fileactions.py |   10 ++++++++--
 1 files changed, 8 insertions(+), 2 deletions(-)
---
diff --git a/kupfer/obj/fileactions.py b/kupfer/obj/fileactions.py
index fa1ad52..8795522 100644
--- a/kupfer/obj/fileactions.py
+++ b/kupfer/obj/fileactions.py
@@ -10,12 +10,18 @@ from kupfer.obj.base import Action, InvalidDataError, OperationError
 class NoDefaultApplicationError (OperationError):
 	pass
 
+def is_good_executable(fileleaf):
+	if not fileleaf._is_executable():
+		return False
+	ctype, uncertain = gio.content_type_guess(fileleaf.object, None, True)
+	return uncertain or gio.content_type_can_be_executable(ctype)
+
 def get_actions_for_file(fileleaf):
 	acts = [RevealFile(), ]
 	if fileleaf.is_dir():
 		acts.append(OpenTerminal())
 	elif fileleaf.is_valid():
-		if fileleaf._is_executable():
+		if is_good_executable(fileleaf):
 			acts.extend((Execute(), Execute(in_terminal=True)))
 	return [Open()] + acts
 
@@ -94,7 +100,7 @@ class OpenTerminal (Action):
 
 class Execute (Action):
 	""" Execute executable file (FileLeaf) """
-	rank_adjust = 5
+	rank_adjust = 10
 	def __init__(self, in_terminal=False, quoted=True):
 		name = _("Run in Terminal") if in_terminal else _("Run (Execute)")
 		super(Execute, self).__init__(name)



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]