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
=== modified file 'lib/synapse-plugins/command-plugin.vala'
--- lib/synapse-plugins/command-plugin.vala 2014-06-08 11:08:37 +0000
+++ lib/synapse-plugins/command-plugin.vala 2014-08-11 08:32:47 +0000
@@ -56,11 +56,15 @@
56 Object (title: _("Execute '%s'").printf (cmd), description: _ ("Run command"), command: cmd,56 Object (title: _("Execute '%s'").printf (cmd), description: _ ("Run command"), command: cmd,
57 icon_name: "application-x-executable",57 icon_name: "application-x-executable",
58 match_type: MatchType.APPLICATION,58 match_type: MatchType.APPLICATION,
59 needs_terminal: cmd.has_prefix ("sudo "));59 needs_terminal: false);
6060
61 try61 try
62 {62 {
63 app_info = AppInfo.create_from_commandline (cmd, null, 0);63 // launching pantheon-terminal here because over AppInfo with the flag AppInfoCreateFlags.NEEDS_TERMINAL fails.
64 if (cmd.has_prefix ("sudo "))
65 app_info = AppInfo.create_from_commandline ("pantheon-terminal -e \"%s\"".printf(cmd),null, 0);
66 else
67 app_info = AppInfo.create_from_commandline ("bash -c \"%s\"".printf(cmd),null, 0);
64 }68 }
65 catch (Error err)69 catch (Error err)
66 {70 {
@@ -87,6 +91,7 @@
8791
88 private Gee.Set<string> past_commands;92 private Gee.Set<string> past_commands;
89 private Regex split_regex;93 private Regex split_regex;
94 private Regex split_regex_2;
9095
91 construct96 construct
92 {97 {
@@ -95,6 +100,7 @@
95 try100 try
96 {101 {
97 split_regex = new Regex ("\\s+", RegexCompileFlags.OPTIMIZE);102 split_regex = new Regex ("\\s+", RegexCompileFlags.OPTIMIZE);
103 split_regex_2 = new Regex ("\\s&&\\s", RegexCompileFlags.OPTIMIZE);
98 }104 }
99 catch (RegexError err)105 catch (RegexError err)
100 {106 {
@@ -161,18 +167,18 @@
161 result.add (create_co (command), Match.Score.AVERAGE);167 result.add (create_co (command), Match.Score.AVERAGE);
162 }168 }
163 }169 }
164170
165 string[] args = split_regex.split (stripped);171 foreach (string split in split_regex_2.split (stripped)) {
166 string? valid_cmd = Environment.find_program_in_path (args[0]);172 string[] args = split_regex.split (split);
167173 // don't allow dangerous commands
168 if (valid_cmd != null)174 if (args[0] == "rm" || Environment.find_program_in_path (args[0]) == null)
169 {175 return null;
170 // don't allow dangerous commands176 }
171 if (args[0] == "rm") return null;177
172 CommandObject? co = create_co (stripped);178 CommandObject? co = create_co (stripped);
173 if (co == null) return null;179 if (co == null) return null;
174 result.add (co, Match.Score.POOR);180 result.add (co, Match.Score.POOR);
175 co.executed.connect (this.command_executed);181 co.executed.connect (this.command_executed);
176 }182 }
177 }183 }
178 else184 else
@@ -185,4 +191,4 @@
185 return result;191 return result;
186 }192 }
187 }193 }
188}194}
189\ No newline at end of file195\ No newline at end of file

Subscribers

People subscribed via source and target branches