Merge lp:~parnold-x/slingshot/fix-1258740 into lp:~elementary-pantheon/slingshot/trunk

Proposed by Djax on 2014-08-10
Status: Work in progress
Proposed branch: lp:~parnold-x/slingshot/fix-1258740
Merge into: lp:~elementary-pantheon/slingshot/trunk
Diff against target: 75 lines (+21/-15)
1 file modified
lib/synapse-plugins/command-plugin.vala (+21/-15)
To merge this branch: bzr merge lp:~parnold-x/slingshot/fix-1258740
Reviewer Review Type Date Requested Status
Artem Anufrij (community) code style Needs Fixing on 2014-11-24
Cody Carver 2014-08-10 Pending
Review via email: mp+230236@code.launchpad.net

Description of the change

Fix Bug #1258740. Launching the command via
bash -c "command".
Also fixed the issue with sudo commands. It should launch a terminal but when launching over AppInfo with the flag AppInfoCreateFlags.NEEDS_TERMINAL the launch fails because they hardcoded the terminal names in gio/gdesktopappinfo.c and without patching there is no way to launch pantheon-terminal.
So I check for sudo in the plugin and in case it launches the terminal over
pantheon-terminal -e "command"

To post a comment you must log in.
lp:~parnold-x/slingshot/fix-1258740 updated on 2014-08-11
437. By Djax on 2014-08-11

remove boolean

Artem Anufrij (artem-anufrij) wrote :

see line comments

review: Needs Fixing (code style)

Unmerged revisions

437. By Djax on 2014-08-11

remove boolean

436. By Djax on 2014-08-10

fix #1258740 and enable sudo command support

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/synapse-plugins/command-plugin.vala'
2--- lib/synapse-plugins/command-plugin.vala 2014-06-08 11:08:37 +0000
3+++ lib/synapse-plugins/command-plugin.vala 2014-08-11 08:32:47 +0000
4@@ -56,11 +56,15 @@
5 Object (title: _("Execute '%s'").printf (cmd), description: _ ("Run command"), command: cmd,
6 icon_name: "application-x-executable",
7 match_type: MatchType.APPLICATION,
8- needs_terminal: cmd.has_prefix ("sudo "));
9+ needs_terminal: false);
10
11 try
12 {
13- app_info = AppInfo.create_from_commandline (cmd, null, 0);
14+ // launching pantheon-terminal here because over AppInfo with the flag AppInfoCreateFlags.NEEDS_TERMINAL fails.
15+ if (cmd.has_prefix ("sudo "))
16+ app_info = AppInfo.create_from_commandline ("pantheon-terminal -e \"%s\"".printf(cmd),null, 0);
17+ else
18+ app_info = AppInfo.create_from_commandline ("bash -c \"%s\"".printf(cmd),null, 0);
19 }
20 catch (Error err)
21 {
22@@ -87,6 +91,7 @@
23
24 private Gee.Set<string> past_commands;
25 private Regex split_regex;
26+ private Regex split_regex_2;
27
28 construct
29 {
30@@ -95,6 +100,7 @@
31 try
32 {
33 split_regex = new Regex ("\\s+", RegexCompileFlags.OPTIMIZE);
34+ split_regex_2 = new Regex ("\\s&&\\s", RegexCompileFlags.OPTIMIZE);
35 }
36 catch (RegexError err)
37 {
38@@ -161,18 +167,18 @@
39 result.add (create_co (command), Match.Score.AVERAGE);
40 }
41 }
42-
43- string[] args = split_regex.split (stripped);
44- string? valid_cmd = Environment.find_program_in_path (args[0]);
45-
46- if (valid_cmd != null)
47- {
48- // don't allow dangerous commands
49- if (args[0] == "rm") return null;
50- CommandObject? co = create_co (stripped);
51- if (co == null) return null;
52- result.add (co, Match.Score.POOR);
53- co.executed.connect (this.command_executed);
54+
55+ foreach (string split in split_regex_2.split (stripped)) {
56+ string[] args = split_regex.split (split);
57+ // don't allow dangerous commands
58+ if (args[0] == "rm" || Environment.find_program_in_path (args[0]) == null)
59+ return null;
60+ }
61+
62+ CommandObject? co = create_co (stripped);
63+ if (co == null) return null;
64+ result.add (co, Match.Score.POOR);
65+ co.executed.connect (this.command_executed);
66 }
67 }
68 else
69@@ -185,4 +191,4 @@
70 return result;
71 }
72 }
73-}
74+}
75\ No newline at end of file

Subscribers

People subscribed via source and target branches