Merge lp:~jeremywootten/pantheon-files/fix-1469122-show-user-bookmarks-when-administrator into lp:~elementary-apps/pantheon-files/trunk

Proposed by Jeremy Wootten
Status: Merged
Approved by: Danielle Foré
Approved revision: 1887
Merged at revision: 2572
Proposed branch: lp:~jeremywootten/pantheon-files/fix-1469122-show-user-bookmarks-when-administrator
Merge into: lp:~elementary-apps/pantheon-files/trunk
Diff against target: 493 lines (+155/-77)
13 files modified
libcore/BookmarkList.vala (+15/-2)
libcore/CMakeLists.txt (+1/-0)
libcore/FileUtils.vala (+2/-2)
libcore/eel-fcts.c (+30/-0)
libcore/eel-fcts.h (+1/-0)
libcore/gof-directory-async.vala (+7/-2)
libcore/pantheon-files-core-C.vapi (+2/-0)
libwidgets/Chrome/BreadcrumbIconList.vala (+1/-1)
src/Application.vala (+6/-3)
src/View/AbstractDirectoryView.vala (+7/-1)
src/View/Sidebar.vala (+70/-60)
src/View/ViewContainer.vala (+1/-0)
src/View/Window.vala (+12/-6)
To merge this branch: bzr merge lp:~jeremywootten/pantheon-files/fix-1469122-show-user-bookmarks-when-administrator
Reviewer Review Type Date Requested Status
Adam Bieńkowski (community) code / testing Approve
David Hewitt Approve
Review via email: mp+315840@code.launchpad.net

Commit message

* Show user bookmarks even when running as root
* Only show local folders in sidebar while root

Description of the change

This branch shows the normal user bookmarks even when running as root - as requested by linked bug.

In addition, the sidebar only shows local files - the Network section and any bookmark linked to a remote system are hidden.

To post a comment you must log in.
Revision history for this message
David Hewitt (davidmhewitt) wrote :

Just a code review so far, I haven't tested the function. But I have two minor pieces of feedback that I've included in the diff comments.

review: Needs Fixing
Revision history for this message
Jeremy Wootten (jeremywootten) wrote :

David's suggestion implemented (thanks!).

Stop offering Trash bookmark and context menu option to root user because they will fail.

Revision history for this message
David Hewitt (davidmhewitt) wrote :

The suggested changes were made, and this seems to work as expected. Approved.

review: Approve
Revision history for this message
RabbitBot (rabbitbot-a) wrote :

Attempt to merge into lp:pantheon-files failed due to conflicts:

text conflict in src/View/Sidebar.vala

Revision history for this message
Jeremy Wootten (jeremywootten) wrote :

Trunk merged to r2563 and conflicts resolved.

Revision history for this message
RabbitBot (rabbitbot-a) wrote :

Attempt to merge into lp:pantheon-files failed due to conflicts:

text conflict in src/View/Window.vala

1886. By Jeremy Wootten

Merge trunk to r2571 and resolve conflict; disambiguate a comment

Revision history for this message
Adam Bieńkowski (donadigo) wrote :

Works as expected. I did one comment on the diff, it is a minor thing though, nothing something critical.

review: Needs Fixing (testing / code)
1887. By Jeremy Wootten

Assign config_dir only once in BookmarkList

Revision history for this message
Jeremy Wootten (jeremywootten) wrote :

Improved code style as recommended by donadigo.

Revision history for this message
Adam Bieńkowski (donadigo) wrote :

Looking good now.

review: Approve (code / testing)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'libcore/BookmarkList.vala'
2--- libcore/BookmarkList.vala 2017-02-10 19:35:18 +0000
3+++ libcore/BookmarkList.vala 2017-06-04 18:27:07 +0000
4@@ -44,8 +44,20 @@
5 list = new GLib.List<Marlin.Bookmark> ();
6 pending_ops = new GLib.Queue<JobType> ();
7
8+ /* Get the user config directory
9+ * When running under pkexec determine real user from PKEXEC_UID
10+ */
11+ string? user_home = Eel.get_real_user_home ();
12+ string config_dir;
13+
14+ if (user_home != null) {
15+ config_dir = GLib.Path.build_filename (user_home, ".config");
16+ } else {
17+ config_dir = GLib.Environment.get_user_config_dir ();
18+ }
19+
20 /*Check bookmarks file exists and in right place */
21- string filename = GLib.Path.build_filename (GLib.Environment.get_user_config_dir (),
22+ string filename = GLib.Path.build_filename (config_dir,
23 "gtk-3.0",
24 "bookmarks",
25 null);
26@@ -218,7 +230,8 @@
27 }
28 /* Do not insert bookmark for home or filesystem root (already have builtins) */
29 var path = bm.gof_file.location.get_path ();
30- if ((path == Environment.get_home_dir () || path == Path.DIR_SEPARATOR_S)) {
31+
32+ if ((path == Eel.get_real_user_home () || path == Path.DIR_SEPARATOR_S)) {
33 return;
34 }
35
36
37=== modified file 'libcore/CMakeLists.txt'
38--- libcore/CMakeLists.txt 2017-04-12 09:28:45 +0000
39+++ libcore/CMakeLists.txt 2017-06-04 18:27:07 +0000
40@@ -33,6 +33,7 @@
41 gmodule-2.0
42 libcanberra
43 pantheon-files-core-C
44+ posix
45 OPTIONS
46 --vapidir=${CMAKE_CURRENT_SOURCE_DIR}/
47 --thread
48
49=== modified file 'libcore/FileUtils.vala'
50--- libcore/FileUtils.vala 2017-06-03 11:30:49 +0000
51+++ libcore/FileUtils.vala 2017-06-04 18:27:07 +0000
52@@ -203,7 +203,7 @@
53 if (path.length > 0) {
54 if (scheme == "" && path.has_prefix ("/~/")) {
55 sb.erase (0, 2);
56- sb.prepend (Environment.get_home_dir ());
57+ sb.prepend (Eel.get_real_user_home ());
58 }
59 }
60
61@@ -238,8 +238,8 @@
62 public void split_protocol_from_path (string path, out string protocol, out string new_path) {
63 protocol = "";
64 new_path = path.dup ();
65-
66 string[] explode_protocol = new_path.split ("://");
67+
68 if (explode_protocol.length > 2) {
69 new_path = "";
70 return;
71
72=== modified file 'libcore/eel-fcts.c'
73--- libcore/eel-fcts.c 2017-02-10 19:35:18 +0000
74+++ libcore/eel-fcts.c 2017-06-04 18:27:07 +0000
75@@ -235,6 +235,34 @@
76 return TRUE;
77 }
78
79+static const char*
80+get_user_home_from_user_uid (uid_t uid)
81+{
82+ struct passwd *password_info;
83+
84+ password_info = getpwuid (uid);
85+
86+ if (password_info == NULL || password_info->pw_dir == NULL)
87+ return NULL;
88+
89+ return password_info->pw_dir;
90+}
91+
92+char*
93+eel_get_real_user_home ()
94+{
95+ const char *real_uid_s;
96+ int uid;
97+
98+ real_uid_s = g_environ_getenv (g_get_environ (), "PKEXEC_UID");
99+ /* If running as administrator return the real user home, not root home */
100+ if (real_uid_s != NULL && eel_get_id_from_digit_string (real_uid_s, &uid)) {
101+ return g_strdup (get_user_home_from_user_uid ((uid_t)uid));
102+ } else {
103+ return g_strdup (g_get_home_dir ());
104+ }
105+}
106+
107 gboolean
108 eel_get_id_from_digit_string (const char *digit_string, uid_t *id)
109 {
110@@ -249,7 +277,9 @@
111 if (sscanf (digit_string, "%ld%c", &scanned_id, &c) != 1) {
112 return FALSE;
113 }
114+
115 *id = scanned_id;
116+
117 return TRUE;
118 }
119
120
121=== modified file 'libcore/eel-fcts.h'
122--- libcore/eel-fcts.h 2017-02-10 19:35:18 +0000
123+++ libcore/eel-fcts.h 2017-06-04 18:27:07 +0000
124@@ -28,6 +28,7 @@
125 GList *eel_get_all_group_names (void);
126 gboolean eel_get_group_id_from_group_name (const char *group_name, uid_t *gid);
127 gboolean eel_get_user_id_from_user_name (const char *user_name, uid_t *uid);
128+gchar* eel_get_real_user_home ();
129 gboolean eel_get_id_from_digit_string (const char *digit_string, uid_t *id);
130
131 gchar *eel_format_size (guint64 size);
132
133=== modified file 'libcore/gof-directory-async.vala'
134--- libcore/gof-directory-async.vala 2017-06-03 11:30:49 +0000
135+++ libcore/gof-directory-async.vala 2017-06-04 18:27:07 +0000
136@@ -438,6 +438,9 @@
137
138 set_confirm_trash ();
139
140+ /* Do not use root trash_dirs (Move to the Rubbish Bin option will not be shown) */
141+ has_trash_dirs = has_trash_dirs && (Posix.getuid () != 0);
142+
143 if (is_trash) {
144 connect_volume_monitor_signals ();
145 }
146@@ -479,14 +482,16 @@
147 }
148
149 private static void toggle_ref_notify (void* data, Object object, bool is_last) {
150+
151 return_if_fail (object != null && object is Object);
152+
153 if (is_last) {
154 Async dir = (Async) object;
155 debug ("Async toggle_ref_notify %s", dir.file.uri);
156
157- if (!dir.removed_from_cache)
158+ if (!dir.removed_from_cache) {
159 dir.remove_dir_from_cache ();
160-
161+ }
162 dir.remove_toggle_ref ((ToggleNotify) toggle_ref_notify);
163 }
164 }
165
166=== modified file 'libcore/pantheon-files-core-C.vapi'
167--- libcore/pantheon-files-core-C.vapi 2017-02-04 12:33:41 +0000
168+++ libcore/pantheon-files-core-C.vapi 2017-06-04 18:27:07 +0000
169@@ -121,6 +121,8 @@
170 [CCode (cheader_filename = "eel-fcts.h")]
171 public bool get_user_id_from_user_name (string *user_name, out int uid);
172 [CCode (cheader_filename = "eel-fcts.h")]
173+ public string? get_real_user_home ();
174+ [CCode (cheader_filename = "eel-fcts.h")]
175 public bool get_group_id_from_group_name (string *group_name, out int gid);
176 [CCode (cheader_filename = "eel-fcts.h")]
177 public bool get_id_from_digit_string (string digit_str, out int id);
178
179=== modified file 'libwidgets/Chrome/BreadcrumbIconList.vala'
180--- libwidgets/Chrome/BreadcrumbIconList.vala 2017-02-10 19:35:18 +0000
181+++ libwidgets/Chrome/BreadcrumbIconList.vala 2017-06-04 18:27:07 +0000
182@@ -102,7 +102,7 @@
183 }
184
185 /* home */
186- dir = Environment.get_home_dir ();
187+ dir = Eel.get_real_user_home ();
188 if (dir.contains (Path.DIR_SEPARATOR_S)) {
189 BreadcrumbIconInfo icon = {dir, Marlin.ICON_GO_HOME_SYMBOLIC, false, null, null, dir.split (Path.DIR_SEPARATOR_S), true, null};
190 icon.exploded[0] = Path.DIR_SEPARATOR_S;
191
192=== modified file 'src/Application.vala'
193--- src/Application.vala 2017-06-03 12:06:11 +0000
194+++ src/Application.vala 2017-06-04 18:27:07 +0000
195@@ -361,10 +361,13 @@
196 }
197 }
198 if (files == null) {
199- /* Restore session if settings allow */
200- if (!Preferences.settings.get_boolean ("restore-tabs") || window.restore_tabs () < 1) {
201+ /* Restore session if not root and settings allow */
202+ if (Posix.getuid () == 0 ||
203+ !Preferences.settings.get_boolean ("restore-tabs") ||
204+ window.restore_tabs () < 1) {
205+
206 /* Open a tab pointing at the default location if no tabs restored*/
207- var location = File.new_for_path (Environment.get_home_dir ());
208+ var location = File.new_for_path (Eel.get_real_user_home ());
209 window.add_tab (location, Marlin.ViewMode.PREFERRED);
210 }
211 } else {
212
213=== modified file 'src/View/AbstractDirectoryView.vala'
214--- src/View/AbstractDirectoryView.vala 2017-05-16 19:50:22 +0000
215+++ src/View/AbstractDirectoryView.vala 2017-06-04 18:27:07 +0000
216@@ -3407,11 +3407,17 @@
217 int sort_column_id = 0;
218 Gtk.SortType sort_order = 0;
219
220+ /* Setting file attributes fails when root */
221+ if (Posix.getuid () == 0) {
222+ return;
223+ }
224+
225 /* Ignore changes in model sort order while tree frozen (i.e. while still loading) to avoid resetting the
226 * the directory file metadata incorrectly (bug 1511307).
227 */
228- if (tree_frozen || !model.get_sort_column_id (out sort_column_id, out sort_order))
229+ if (tree_frozen || !model.get_sort_column_id (out sort_column_id, out sort_order)) {
230 return;
231+ }
232
233 var info = new GLib.FileInfo ();
234 var dir = slot.directory;
235
236=== modified file 'src/View/Sidebar.vala'
237--- src/View/Sidebar.vala 2017-06-03 11:30:49 +0000
238+++ src/View/Sidebar.vala 2017-06-04 18:27:07 +0000
239@@ -68,6 +68,7 @@
240 bool internal_drag_started;
241 bool dragged_out_of_window;
242 bool renaming = false;
243+ bool local_only;
244
245 /* Identifiers for target types */
246 public enum TargetType {
247@@ -129,11 +130,13 @@
248 }
249 }
250
251- public Sidebar (Marlin.View.Window window) {
252+ public Sidebar (Marlin.View.Window window, bool local_only = false) {
253 init (); /* creates the Gtk.TreeModel store. */
254 this.last_selected_uri = null;
255 this.set_policy (Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC);
256 this.window = window;
257+ this.local_only = local_only;
258+
259 window.loading_uri.connect (loading_uri_callback);
260 window.free_space_change.connect (reload);
261
262@@ -492,7 +495,7 @@
263
264 /* Add Home BUILTIN */
265 try {
266- mount_uri = GLib.Filename.to_uri (GLib.Environment.get_home_dir (), null);
267+ mount_uri = GLib.Filename.to_uri (Eel.get_real_user_home (), null);
268 }
269 catch (ConvertError e) {
270 mount_uri = "";
271@@ -533,24 +536,30 @@
272 uint index;
273 for (index = 0; index < bookmark_count; index++) {
274 bm = bookmarks.item_at (index);
275- if (bm == null
276- || (bm.uri_known_not_to_exist () && !display_all_bookmarks))
277+ if (bm == null ||
278+ (bm.uri_known_not_to_exist () && !display_all_bookmarks) ||
279+ (local_only && GLib.Uri.parse_scheme (bm.get_uri ()) != "file")) {
280+
281 continue;
282+ }
283
284 add_bookmark (iter, bm, index);
285 }
286
287- /* Add trash */
288- add_place (Marlin.PlaceType.BUILT_IN,
289- iter,
290- _("Trash"),
291- Marlin.TrashMonitor.get_icon (),
292- Marlin.TRASH_URI,
293- null,
294- null,
295- null,
296- index + n_builtins_before,
297- _("Open the Trash"));
298+ /* Do not show Trash if running as root (cannot be loaded) */
299+ if (Posix.getuid () != 0) {
300+ /* Add trash */
301+ add_place (Marlin.PlaceType.BUILT_IN,
302+ iter,
303+ _("Trash"),
304+ Marlin.TrashMonitor.get_icon (),
305+ Marlin.TRASH_URI,
306+ null,
307+ null,
308+ null,
309+ index + n_builtins_before,
310+ _("Open the Trash"));
311+ }
312
313 /* ADD STORAGE CATEGORY*/
314 iter = add_category (Marlin.PlaceType.STORAGE_CATEGORY,
315@@ -676,53 +685,54 @@
316 add_device_tooltip.begin (last_iter, root, update_cancellable);
317 }
318
319- /* ADD NETWORK CATEGORY */
320-
321- iter = add_category (Marlin.PlaceType.NETWORK_CATEGORY,
322- _("Network"),
323- _("Your network places"));
324-
325- network_category_reference = new Gtk.TreeRowReference (store, store.get_path (iter));
326-
327- /* Add network mounts */
328- network_mounts.reverse ();
329- foreach (Mount mount in network_mounts) {
330- root = mount.get_root ();
331- /* get_smb_share_from_uri will return the uri unaltered if does not have
332- * the smb scheme so we need not test. This is required because the mount
333- * does not return the true root location of the share but the location used
334- * when creating the mount.
335- */
336- string uri = PF.FileUtils.get_smb_share_from_uri (root.get_uri ());
337-
338- last_iter = add_place (Marlin.PlaceType.BUILT_IN,
339- iter,
340- mount.get_name (),
341- mount.get_icon (),
342- uri,
343- null,
344- null,
345- mount,
346- 0,
347- null);
348-
349- add_device_tooltip.begin (last_iter, root, update_cancellable);
350+ if (!local_only) { /* Network operations fail when root */
351+ /* ADD NETWORK CATEGORY */
352+ iter = add_category (Marlin.PlaceType.NETWORK_CATEGORY,
353+ _("Network"),
354+ _("Your network places"));
355+
356+ network_category_reference = new Gtk.TreeRowReference (store, store.get_path (iter));
357+
358+ /* Add network mounts */
359+ network_mounts.reverse ();
360+ foreach (Mount mount in network_mounts) {
361+ root = mount.get_default_location ();
362+ /* get_smb_share_from_uri will return the uri unaltered if does not have
363+ * the smb scheme so we need not test. This is required because the mount
364+ * does not return the true root location of the share but the location used
365+ * when creating the mount.
366+ */
367+ string uri = PF.FileUtils.get_smb_share_from_uri (root.get_uri ());
368+
369+ last_iter = add_place (Marlin.PlaceType.BUILT_IN,
370+ iter,
371+ mount.get_name (),
372+ mount.get_icon (),
373+ uri,
374+ null,
375+ null,
376+ mount,
377+ 0,
378+ null);
379+
380+ add_device_tooltip.begin (last_iter, root, update_cancellable);
381+ }
382+
383+ /* Add Entire Network BUILTIN */
384+ add_place (Marlin.PlaceType.BUILT_IN,
385+ iter,
386+ _("Entire Network"),
387+ new GLib.ThemedIcon (Marlin.ICON_NETWORK),
388+ "network:///",
389+ null,
390+ null,
391+ null,
392+ 0,
393+ _("Browse the contents of the network"));
394+
395+ plugins.update_sidebar ((Gtk.Widget)this); /* Add "Connect Server plugin */
396 }
397
398- /* Add Entire Network BUILTIN */
399- add_place (Marlin.PlaceType.BUILT_IN,
400- iter,
401- _("Entire Network"),
402- new GLib.ThemedIcon (Marlin.ICON_NETWORK),
403- "network:///",
404- null,
405- null,
406- null,
407- 0,
408- _("Browse the contents of the network"));
409-
410- plugins.update_sidebar ((Gtk.Widget)this);
411-
412 expander_init_pref_state (tree_view);
413
414 /* select any previously selected place or any place matching slot location */
415
416=== modified file 'src/View/ViewContainer.vala'
417--- src/View/ViewContainer.vala 2017-05-16 20:04:17 +0000
418+++ src/View/ViewContainer.vala 2017-06-04 18:27:07 +0000
419@@ -250,6 +250,7 @@
420 view = null; /* Pre-requisite for add view */
421 loading (false);
422 }
423+
424 private void after_mode_change () {
425 /* Slot is created inactive so we activate now since we must be the current tab
426 * to have received a change mode instruction */
427
428=== modified file 'src/View/Window.vala'
429--- src/View/Window.vala 2017-06-03 11:30:49 +0000
430+++ src/View/Window.vala 2017-06-04 18:27:07 +0000
431@@ -153,7 +153,8 @@
432 }
433
434 private void construct_sidebar () {
435- sidebar = new Marlin.Places.Sidebar (this);
436+ /* Show only local places in sidebar when running as root */
437+ sidebar = new Marlin.Places.Sidebar (this, Posix.getuid () == 0);
438 }
439
440 public void show_sidebar (bool show = true) {
441@@ -563,9 +564,10 @@
442 tab.close ();
443 }
444
445- public void add_window (File location = File.new_for_path (Environment.get_home_dir ()),
446+ public void add_window (File location = File.new_for_path (Eel.get_real_user_home ()),
447 Marlin.ViewMode mode = Marlin.ViewMode.PREFERRED,
448 int x = -1, int y = -1) {
449+
450 ((Marlin.Application) application).create_window (location, real_mode (mode), x, y);
451 }
452
453@@ -666,7 +668,7 @@
454 break;
455
456 case "HOME":
457- uri_path_change_request ("file://" + Environment.get_home_dir());
458+ uri_path_change_request ("file://" + Eel.get_real_user_home ());
459 break;
460
461 case "TRASH":
462@@ -954,7 +956,7 @@
463 /* ViewContainer is responsible for returning valid uris */
464 vb.add ("(uss)",
465 view_container.view_mode,
466- view_container.get_root_uri () ?? Environment.get_home_dir (),
467+ view_container.get_root_uri () ?? Eel.get_real_user_home (),
468 view_container.get_tip_uri () ?? ""
469 );
470 }
471@@ -984,8 +986,12 @@
472 restoring_tabs = true;
473
474 while (iter.next ("(uss)", out mode, out root_uri, out tip_uri)) {
475- if (mode < 0 || mode >= Marlin.ViewMode.INVALID || root_uri == null || root_uri == "" || tip_uri == null)
476+
477+ if (mode < 0 || mode >= Marlin.ViewMode.INVALID ||
478+ root_uri == null || root_uri == "" || tip_uri == null) {
479+
480 continue;
481+ }
482
483 /* We do not check valid location here because it may cause the interface to hang
484 * before the window appears (e.g. if trying to connect to a server that has become unavailable)
485@@ -1105,7 +1111,7 @@
486
487 if (location == null || location.has_prefix (root) || location.equal (root)) {
488 if (view_container == current_tab)
489- view_container.focus_location (File.new_for_path (Environment.get_home_dir ()));
490+ view_container.focus_location (File.new_for_path (Eel.get_real_user_home ()));
491 else
492 remove_tab (view_container);
493 }

Subscribers

People subscribed via source and target branches

to all changes: