Merge lp:~donadigo/switchboard-plug-pantheon-shell/fix-wallpaper-permissions into lp:~elementary-apps/switchboard-plug-pantheon-shell/trunk

Proposed by Adam Bieńkowski
Status: Merged
Approved by: Danielle Foré
Approved revision: 404
Merged at revision: 402
Proposed branch: lp:~donadigo/switchboard-plug-pantheon-shell/fix-wallpaper-permissions
Merge into: lp:~elementary-apps/switchboard-plug-pantheon-shell/trunk
Diff against target: 246 lines (+127/-41)
2 files modified
set-wallpaper-contract/set-wallpaper.vala (+53/-14)
src/Wallpaper.vala (+74/-27)
To merge this branch: bzr merge lp:~donadigo/switchboard-plug-pantheon-shell/fix-wallpaper-permissions
Reviewer Review Type Date Requested Status
The Lemon Man (community) code Approve
Danielle Foré ux Approve
elementary Pantheon team code Pending
Review via email: mp+276153@code.launchpad.net

Commit message

* Sets right permissions for wallpapers to have them visible in the greeter (finally)
* Various code optimizations

Description of the change

The branch fixes some issues and makes optimizations to current wallpaper
* Sets right permissions for wallpapers to have them visible in the greeter (finally)
* Various code optimizations

To post a comment you must log in.
Revision history for this message
The Lemon Man (lemonboy) wrote :

Hmm, I'd be against chmod'ing the user files.

Revision history for this message
Akshay Shekher (voldyman) wrote :

Why don't you ask the user if they want switchboard to fix the file permissions if they are not 0644?

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

voldyman: Why we would 'ask' to fix the 'file permissions' to just change the wallpaper? No one is doing that and it seems reduntant to ask user for these things.

Revision history for this message
Danielle Foré (danrabbit) wrote :

I don't think using a symlink is a good idea. Now you're giving me something to remember: not to delete that wallpaper that's in a random location on my file system. Or worse, it could be on an external drive and now I can't unmount that drive without losing my wallpaper. Copying ensures that the wallpaper won't be removed accidentally.

I do think we should change the permissions without asking. It's a wallpaper, I think it'll be okay. Users expect this feature to work and I don't think we should have to bother less experienced users knowing what permissions even are and why they're needed for this feature.

review: Needs Fixing
Revision history for this message
Danielle Foré (danrabbit) wrote :

I can confirm however that this fixes the issue :D

394. By Adam Bieńkowski

Copy the wallpaper to directory

395. By Adam Bieńkowski

Fix not changing wallpaper in greeter

396. By Adam Bieńkowski

Add missing permission line

397. By Adam Bieńkowski

Fixed: when choosing external source in the plug it does not change it in the greeter

Revision history for this message
Danielle Foré (danrabbit) wrote :

Hey right on. I can confirm that it works both with the contract and with the plug. Nice work :D

review: Approve (ux)
Revision history for this message
Danielle Foré (danrabbit) wrote :

Hrm, I found an issue. Set a non-default wall in the plug. Close the plug. Open it again. Gala background plugin crashes.

review: Needs Fixing
Revision history for this message
kay van der Zander (kay20) wrote :

If the plug creates a copy of the wallpaper the user wants. Why not only change the copy his permissions. The original wallpaper will be untouched (besides copying).

currently the original wallpaper is changed and the copy isn't
and why change all wallpapers there premissions (diff line 68)

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

kay: line 68 is there to e.g: if you choose wallpaper directly from the plug, permissions won't be changed, and it will not be visible in the plug.

398. By Adam Bieńkowski

Simplify wallpaper path's to one local path for both dbus and gsettings; wallpaper folder now in .config

399. By Adam Bieńkowski

Fix some issues

400. By Adam Bieńkowski

Copy requested wallpaper to /var/lib/lightdm-data/user/wallpaper

401. By Adam Bieńkowski

Move greeter_file variable

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

Updated.

Revision history for this message
Danielle Foré (danrabbit) wrote :

Okay alright, it seems to be working as expected. I can confirm that:
* walls are copied into .local/share/backgrounds
* The current wall is copied to /var/lib/lightdm-data/user/wallpaper
* LightDM is able to read the wall
* This works both with the contract and with Drag N Drop
* I can't reproduce any of the other issues/crashes we had previously experienced

Good work :)

review: Approve (ux)
Revision history for this message
Akshay Shekher (voldyman) wrote :

please use const's and not hardcoded strings so that they can easily be changed later, we don't want to grep throught the code to find all the mentions of /usr/share/backgrounds, etc.

402. By Adam Bieńkowski

Replace /usr/share/backgrounds with constant variable

403. By Adam Bieńkowski

Access specifier

Revision history for this message
The Lemon Man (lemonboy) wrote :

Some nitpicks have been outlined in the inline comments.

review: Needs Fixing (code)
404. By Adam Bieńkowski

Single build_filename call; use SYSTEM_BACKGROUNDS_PATH variable everywhere

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

Updated.

Revision history for this message
The Lemon Man (lemonboy) wrote :

Code-wise it's ok. There's some code that could be factored out but let's get the ball rolling.

review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'set-wallpaper-contract/set-wallpaper.vala'
2--- set-wallpaper-contract/set-wallpaper.vala 2015-09-21 16:34:26 +0000
3+++ set-wallpaper-contract/set-wallpaper.vala 2015-11-15 21:44:26 +0000
4@@ -19,6 +19,8 @@
5 </transition>
6 """;
7
8+ const string SYSTEM_BACKGROUNDS_PATH = "/usr/share/backgrounds";
9+
10 private int delay_value = 60;
11
12 [DBus (name = "org.freedesktop.Accounts.User")]
13@@ -100,16 +102,43 @@
14 return folder;
15 }
16
17- private bool copy_to_local_folder (File source) {
18- try {
19- var dest = File.new_for_path (get_local_bg_location () + source.get_basename ());
20- source.copy (dest, FileCopyFlags.OVERWRITE|FileCopyFlags.NOFOLLOW_SYMLINKS);
21- } catch (Error e) {
22- warning ("%s\n", e.message);
23- return false;
24+ private File? copy_for_library (File source) {
25+ File? dest = null;
26+
27+ try {
28+ dest = File.new_for_path (get_local_bg_location () + source.get_basename ());
29+ source.copy (dest, FileCopyFlags.OVERWRITE | FileCopyFlags.ALL_METADATA);
30+ } catch (Error e) {
31+ warning ("%s\n", e.message);
32+ }
33+
34+ return dest;
35+ }
36+
37+ private File? copy_for_greeter (File source) {
38+ File? dest = null;
39+ try {
40+ string greeter_data_dir = Path.build_filename (Environment.get_variable ("XDG_GREETER_DATA_DIR"), "wallpaper");
41+
42+ var folder = File.new_for_path (greeter_data_dir);
43+ if (folder.query_exists ()) {
44+ var enumerator = folder.enumerate_children ("standard::*", FileQueryInfoFlags.NOFOLLOW_SYMLINKS);
45+ FileInfo? info = null;
46+ while ((info = enumerator.next_file ()) != null) {
47+ enumerator.get_child (info).@delete ();
48+ }
49+ } else {
50+ folder.make_directory_with_parents ();
51+ }
52+
53+ dest = File.new_for_path (Path.build_filename (greeter_data_dir, source.get_basename ()));
54+ source.copy (dest, FileCopyFlags.OVERWRITE | FileCopyFlags.ALL_METADATA);
55+ } catch (Error e) {
56+ warning ("%s\n", e.message);
57+ return null;
58 }
59
60- return true;
61+ return dest;
62 }
63
64 public static int main (string[] args) {
65@@ -129,17 +158,27 @@
66 var files = new List<File> ();
67 for (var i = 1; i < args.length; i++) {
68 var file = File.new_for_path (args[i]);
69- var localfile = File.new_for_path (get_local_bg_location () + file.get_basename ());
70
71 if (file != null) {
72- if (copy_to_local_folder (file)) {
73- files.append (localfile);
74- } else {
75- files.append (file);
76+
77+ string path = file.get_path ();
78+ File append_file = file;
79+ if (!path.has_prefix (SYSTEM_BACKGROUNDS_PATH)) {
80+ var local_file = copy_for_library (file);
81+ if (local_file != null) {
82+ append_file = local_file;
83+ }
84+ }
85+
86+ files.append (append_file);
87+
88+ var greeter_file = copy_for_greeter (file);
89+ if (greeter_file != null) {
90+ path = greeter_file.get_path ();
91 }
92
93 try {
94- accounts_service.set_background_file (file.get_path ());
95+ accounts_service.set_background_file (path);
96 } catch (Error e) {
97 warning ("%s\n", e.message);
98 }
99
100=== modified file 'src/Wallpaper.vala'
101--- src/Wallpaper.vala 2015-10-29 20:50:16 +0000
102+++ src/Wallpaper.vala 2015-11-15 21:44:26 +0000
103@@ -96,7 +96,9 @@
104
105 //name of the default-wallpaper-link that we can prevent loading it again
106 //(assumes that the defaultwallpaper is also in the system wallpaper directory)
107- static string default_link = "file:///usr/share/backgrounds/elementaryos-default";
108+ static string default_link = "file://%s/elementaryos-default".printf (SYSTEM_BACKGROUNDS_PATH);
109+
110+ const string SYSTEM_BACKGROUNDS_PATH = "/usr/share/backgrounds";
111
112 public Wallpaper (Switchboard.Plug _plug) {
113 plug = _plug;
114@@ -201,8 +203,23 @@
115 */
116 try {
117 var file = File.new_for_uri (current_wallpaper_path);
118-
119- accountsservice.set_background_file (file.get_path ());
120+ string uri = file.get_uri ();
121+ string path = file.get_path ();
122+
123+ if (!path.has_prefix (SYSTEM_BACKGROUNDS_PATH)) {
124+ var localfile = copy_for_library (file);
125+ if (localfile != null) {
126+ uri = localfile.get_uri ();
127+ }
128+ }
129+
130+ var greeter_file = copy_for_greeter (file);
131+ if (greeter_file != null) {
132+ path = greeter_file.get_path ();
133+ }
134+
135+ settings.set_string ("picture-uri", uri);
136+ accountsservice.set_background_file (path);
137 } catch (Error e) {
138 warning (e.message);
139 }
140@@ -213,7 +230,6 @@
141
142 if (!(children is SolidColorContainer)) {
143 current_wallpaper_path = children.uri;
144- settings.set_string ("picture-uri", current_wallpaper_path);
145 update_accountsservice ();
146
147 if (active_wallpaper == solid_color) {
148@@ -296,8 +312,8 @@
149 } else if (folder_combo.get_active () == 1) {
150 clean_wallpapers ();
151
152- var system_uri = "file:///usr/share/backgrounds";
153- var user_uri = GLib.File.new_for_path (GLib.Environment.get_user_data_dir () + "/backgrounds").get_uri ();
154+ var system_uri = "file://" + SYSTEM_BACKGROUNDS_PATH;
155+ var user_uri = GLib.File.new_for_path (get_local_bg_location ()).get_uri ();
156
157 load_wallpapers (system_uri, cancellable);
158 load_wallpapers (user_uri, cancellable);
159@@ -447,6 +463,52 @@
160 Cache.clear ();
161 }
162
163+ private string get_local_bg_location () {
164+ return Path.build_filename (Environment.get_user_data_dir (), "backgrounds") + "/";
165+ }
166+
167+ private File? copy_for_library (File source) {
168+ File? dest = null;
169+
170+ try {
171+ dest = File.new_for_path (get_local_bg_location () + source.get_basename ());
172+ source.copy (dest, FileCopyFlags.OVERWRITE | FileCopyFlags.ALL_METADATA);
173+ } catch (Error e) {
174+ warning ("%s\n", e.message);
175+ }
176+
177+ return dest;
178+ }
179+
180+ private File? copy_for_greeter (File source) {
181+ File? dest = null;
182+ try {
183+ string greeter_data_dir = Path.build_filename (Environment.get_variable ("XDG_GREETER_DATA_DIR"), "wallpaper");
184+ if (greeter_data_dir == "") {
185+ greeter_data_dir = Path.build_filename ("/var/lib/lightdm-data/", Environment.get_user_name (), "wallpaper");
186+ }
187+
188+ var folder = File.new_for_path (greeter_data_dir);
189+ if (folder.query_exists ()) {
190+ var enumerator = folder.enumerate_children ("standard::*", FileQueryInfoFlags.NOFOLLOW_SYMLINKS);
191+ FileInfo? info = null;
192+ while ((info = enumerator.next_file ()) != null) {
193+ enumerator.get_child (info).@delete ();
194+ }
195+ } else {
196+ folder.make_directory_with_parents ();
197+ }
198+
199+ dest = File.new_for_path (Path.build_filename (greeter_data_dir, source.get_basename ()));
200+ source.copy (dest, FileCopyFlags.OVERWRITE | FileCopyFlags.ALL_METADATA);
201+ } catch (Error e) {
202+ warning ("%s\n", e.message);
203+ return null;
204+ }
205+
206+ return dest;
207+ }
208+
209 void on_drag_data_received (Widget widget, Gdk.DragContext ctx, int x, int y, SelectionData sel, uint information, uint timestamp) {
210 if (sel.get_length () > 0) {
211 File file = File.new_for_uri (sel.get_uris ()[0]);
212@@ -457,29 +519,14 @@
213 return;
214 }
215
216-
217- string display_name = Filename.display_basename (file.get_path ());
218-
219- var dest_folder = File.new_for_path (Environment.get_user_data_dir () + "/backgrounds");
220- var dest = File.new_for_path (Environment.get_user_data_dir () + "/backgrounds/" + display_name);
221- if (!dest_folder.query_exists ()) {
222- try {
223- dest_folder.make_directory ();
224- } catch (Error e) {
225- warning ("Creating local wallpaper directory failed: %s", e.message);
226- }
227- }
228-
229- try {
230- file.copy (dest, 0);
231- } catch (Error e) {
232- warning ("Copying wallpaper to local directory failed: %s", e.message);
233- }
234-
235- string uri = dest.get_uri ();
236+ string local_uri = file.get_uri ();
237+ var dest = copy_for_library (file);
238+ if (dest != null) {
239+ local_uri = dest.get_uri ();
240+ }
241
242 // Add the wallpaper name and thumbnail to the IconView
243- var wallpaper = new WallpaperContainer (uri);
244+ var wallpaper = new WallpaperContainer (local_uri);
245 wallpaper_view.add (wallpaper);
246 wallpaper.show_all ();
247

Subscribers

People subscribed via source and target branches

to all changes: