Merge lp:~mterry/deja-dup/parse-file-path into lp:deja-dup/26

Proposed by Michael Terry
Status: Merged
Merged at revision: 1433
Proposed branch: lp:~mterry/deja-dup/parse-file-path
Merge into: lp:deja-dup/26
Diff against target: 495 lines (+91/-85)
17 files modified
.bzrignore (+1/-1)
common/CommonUtils.vala (+8/-9)
common/DirHandling.vala (+33/-29)
common/FilteredSettings.vala (+19/-2)
common/Makefile.am (+1/-1)
common/Operation.vala (+1/-1)
common/OperationBackup.vala (+2/-5)
monitor/monitor.vala (+1/-1)
po/POTFILES.in (+1/-1)
po/POTFILES.skip (+1/-1)
widgets/ConfigEntry.vala (+5/-5)
widgets/ConfigLabelList.vala (+1/-4)
widgets/ConfigLabelLocation.vala (+4/-4)
widgets/ConfigList.vala (+3/-10)
widgets/ConfigLocationCustom.vala (+2/-1)
widgets/ConfigURLPart.vala (+4/-6)
widgets/ConfigWidget.vala (+4/-4)
To merge this branch: bzr merge lp:~mterry/deja-dup/parse-file-path
Reviewer Review Type Date Requested Status
Robert Bruce Park (community) Approve
Review via email: mp+145105@code.launchpad.net

Description of the change

During this cycle, I added support for replacing $USER in include/exclude settings with the current user name for the benefit of system administrators that wanted to change the defaults.

But really, the original request I had for that feature was with the intent of using it to set the default backup location, not in include or exclude paths. So this branch adds support for that.

It also adds some convenience methods to FilteredSettings (nee SimpleSettings).

Test by modifying /org/gnome/deja-dup/file/path to something with $USER in it and see if ./preferences/deja-dup-preferences shows the right thing in the Backup Location field when set to a local folder.

To post a comment you must log in.
Revision history for this message
Robert Bruce Park (robru) wrote :

Looks good! I tinkered with dconf-editor a bit and indeed, values of $USER are being replaced with my home directory.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file '.bzrignore'
2--- .bzrignore 2012-03-20 12:23:51 +0000
3+++ .bzrignore 2013-01-27 22:01:20 +0000
4@@ -7,6 +7,7 @@
5 common/DuplicityInfo.c
6 common/DuplicityInstance.c
7 common/Duplicity.c
8+common/FilteredSettings.c
9 common/Network.c
10 common/OperationBackup.c
11 common/OperationFiles.c
12@@ -16,7 +17,6 @@
13 common/RecursiveDelete.c
14 common/RecursiveMove.c
15 common/RecursiveOp.c
16-common/SimpleSettings.c
17 deja-dup/AssistantBackup.c
18 deja-dup/AssistantOperation.c
19 deja-dup/AssistantRestore.c
20
21=== modified file 'common/CommonUtils.vala'
22--- common/CommonUtils.vala 2013-01-20 19:54:44 +0000
23+++ common/CommonUtils.vala 2013-01-27 22:01:20 +0000
24@@ -276,7 +276,7 @@
25 return (last_check.compare(now) <= 0);
26 }
27
28-public string get_folder_key(SimpleSettings settings, string key)
29+public string get_folder_key(FilteredSettings settings, string key)
30 {
31 string folder = settings.get_string(key);
32 if (folder.contains("$HOSTNAME")) {
33@@ -289,7 +289,7 @@
34 }
35
36 bool settings_read_only = false;
37-HashTable<string, SimpleSettings> settings_table = null;
38+HashTable<string, FilteredSettings> settings_table = null;
39 public void set_settings_read_only(bool ro)
40 {
41 settings_read_only = ro;
42@@ -297,7 +297,7 @@
43 // When read only, we also need to make sure everyone shares the same
44 // settings object. Otherwise, they will not notice the changes other
45 // parts of the code make.
46- settings_table = new HashTable<string, SimpleSettings>.full(str_hash,
47+ settings_table = new HashTable<string, FilteredSettings>.full(str_hash,
48 str_equal,
49 g_free,
50 g_object_unref);
51@@ -307,22 +307,22 @@
52 }
53 }
54
55-public SimpleSettings get_settings(string? subdir = null)
56+public FilteredSettings get_settings(string? subdir = null)
57 {
58 string schema = "org.gnome.DejaDup";
59 if (subdir != null && subdir != "")
60 schema += "." + subdir;
61- SimpleSettings rv;
62+ FilteredSettings rv;
63 if (settings_read_only) {
64 rv = settings_table.lookup(schema);
65 if (rv == null) {
66- rv = new SimpleSettings(schema, true);
67+ rv = new FilteredSettings(schema, true);
68 rv.delay(); // never to be apply()'d again
69 settings_table.insert(schema, rv);
70 }
71 }
72 else {
73- rv = new SimpleSettings(schema, false);
74+ rv = new FilteredSettings(schema, false);
75 }
76 return rv;
77 }
78@@ -565,8 +565,7 @@
79 // This is admittedly fast and loose, but our primary concern is just
80 // avoiding silly choices like tmpfs or tiny special /tmp partitions.
81 var settings = get_settings();
82- var include_val = settings.get_value(INCLUDE_LIST_KEY);
83- var include_list = parse_dir_list(include_val.get_strv());
84+ var include_list = settings.get_file_list(INCLUDE_LIST_KEY);
85 File main_include = null;
86 var home = File.new_for_path(Environment.get_home_dir());
87 foreach (var include in include_list) {
88
89=== modified file 'common/DirHandling.vala'
90--- common/DirHandling.vala 2012-12-04 16:08:06 +0000
91+++ common/DirHandling.vala 2013-01-27 22:01:20 +0000
92@@ -26,41 +26,45 @@
93 return Path.build_filename(Environment.get_user_data_dir(), "Trash");
94 }
95
96-public File? parse_dir(string dir)
97+public string? parse_keywords(string dir)
98 {
99- string s = dir;
100- if (s == "$HOME")
101- s = Environment.get_home_dir();
102- else if (s == "$DESKTOP")
103- s = Environment.get_user_special_dir(UserDirectory.DESKTOP);
104- else if (s == "$DOCUMENTS")
105- s = Environment.get_user_special_dir(UserDirectory.DOCUMENTS);
106- else if (s == "$DOWNLOAD")
107- s = Environment.get_user_special_dir(UserDirectory.DOWNLOAD);
108- else if (s == "$MUSIC")
109- s = Environment.get_user_special_dir(UserDirectory.MUSIC);
110- else if (s == "$PICTURES")
111- s = Environment.get_user_special_dir(UserDirectory.PICTURES);
112- else if (s == "$PUBLIC_SHARE")
113- s = Environment.get_user_special_dir(UserDirectory.PUBLIC_SHARE);
114- else if (s == "$TEMPLATES")
115- s = Environment.get_user_special_dir(UserDirectory.TEMPLATES);
116- else if (s == "$TRASH")
117- s = get_trash_path();
118- else if (s == "$VIDEOS")
119- s = Environment.get_user_special_dir(UserDirectory.VIDEOS);
120+ string result = null;
121+ if (dir == "$HOME")
122+ result = Environment.get_home_dir();
123+ else if (dir == "$DESKTOP")
124+ result = Environment.get_user_special_dir(UserDirectory.DESKTOP);
125+ else if (dir == "$DOCUMENTS")
126+ result = Environment.get_user_special_dir(UserDirectory.DOCUMENTS);
127+ else if (dir == "$DOWNLOAD")
128+ result = Environment.get_user_special_dir(UserDirectory.DOWNLOAD);
129+ else if (dir == "$MUSIC")
130+ result = Environment.get_user_special_dir(UserDirectory.MUSIC);
131+ else if (dir == "$PICTURES")
132+ result = Environment.get_user_special_dir(UserDirectory.PICTURES);
133+ else if (dir == "$PUBLIC_SHARE")
134+ result = Environment.get_user_special_dir(UserDirectory.PUBLIC_SHARE);
135+ else if (dir == "$TEMPLATES")
136+ result = Environment.get_user_special_dir(UserDirectory.TEMPLATES);
137+ else if (dir == "$TRASH")
138+ result = get_trash_path();
139+ else if (dir == "$VIDEOS")
140+ result = Environment.get_user_special_dir(UserDirectory.VIDEOS);
141 else {
142 // Some variables can be placed inside a larger path, so replace those
143- s = s.replace("$USER", Environment.get_user_name());
144+ result = dir.replace("$USER", Environment.get_user_name());
145
146- if (Uri.parse_scheme(s) == null && !Path.is_absolute(s))
147- s = Path.build_filename(Environment.get_home_dir(), s);
148- else
149- return File.parse_name(s);
150+ if (Uri.parse_scheme(result) == null && !Path.is_absolute(result))
151+ result = Path.build_filename(Environment.get_home_dir(), result);
152 }
153
154- if (s != null)
155- return File.new_for_path(s);
156+ return result;
157+}
158+
159+public File? parse_dir(string dir)
160+{
161+ var result = parse_keywords(dir);
162+ if (result != null)
163+ return File.parse_name(result);
164 else
165 return null;
166 }
167
168=== renamed file 'common/SimpleSettings.vala' => 'common/FilteredSettings.vala'
169--- common/SimpleSettings.vala 2011-08-14 15:41:22 +0000
170+++ common/FilteredSettings.vala 2013-01-27 22:01:20 +0000
171@@ -31,11 +31,11 @@
172 dconf, so it's nice to be able to avoid those.
173 */
174
175-public class SimpleSettings : Settings
176+public class FilteredSettings : Settings
177 {
178 public bool read_only {get; set;}
179
180- public SimpleSettings(string schema, bool ro)
181+ public FilteredSettings(string schema, bool ro)
182 {
183 Object(schema: schema, read_only: ro);
184 }
185@@ -59,6 +59,23 @@
186 base.set_value(k, v);
187 }
188
189+ // May be uri, or may be a File's parsed path for historical reasons
190+ public new string get_uri(string k) {
191+ // If we are reading a URI, replace some special keywords.
192+ var val = get_string(k);
193+ var result = parse_keywords(val);
194+ if (result == null)
195+ return "";
196+ else
197+ return result;
198+ }
199+
200+ public new File[] get_file_list(string k) {
201+ // If we are reading a file path, replace some special keywords.
202+ var val = get_value(k);
203+ return parse_dir_list(val.get_strv());
204+ }
205+
206 // TODO: bytestring, strv
207 }
208
209
210=== modified file 'common/Makefile.am'
211--- common/Makefile.am 2012-11-01 09:16:02 +0000
212+++ common/Makefile.am 2013-01-27 22:01:20 +0000
213@@ -44,6 +44,7 @@
214 Checker.vala \
215 CommonUtils.vala \
216 DirHandling.vala \
217+ FilteredSettings.vala \
218 Network.vala \
219 Operation.vala \
220 OperationBackup.vala \
221@@ -55,7 +56,6 @@
222 RecursiveDelete.vala \
223 RecursiveMove.vala \
224 RecursiveOp.vala \
225- SimpleSettings.vala \
226 ToolPlugin.vala
227
228 libcommon_la_SOURCES = \
229
230=== modified file 'common/Operation.vala'
231--- common/Operation.vala 2013-01-20 19:54:44 +0000
232+++ common/Operation.vala 2013-01-27 22:01:20 +0000
233@@ -87,7 +87,7 @@
234 set_passphrase(state.passphrase);
235 }
236
237- SimpleSettings settings;
238+ FilteredSettings settings;
239 internal ToolJob job;
240 protected string passphrase;
241 bool finished = false;
242
243=== modified file 'common/OperationBackup.vala'
244--- common/OperationBackup.vala 2013-01-20 19:54:44 +0000
245+++ common/OperationBackup.vala 2013-01-27 22:01:20 +0000
246@@ -55,11 +55,8 @@
247 protected override List<string>? make_argv()
248 {
249 var settings = get_settings();
250-
251- var include_val = settings.get_value(INCLUDE_LIST_KEY);
252- var include_list = parse_dir_list(include_val.get_strv());
253- var exclude_val = settings.get_value(EXCLUDE_LIST_KEY);
254- var exclude_list = parse_dir_list(exclude_val.get_strv());
255+ var include_list = settings.get_file_list(INCLUDE_LIST_KEY);
256+ var exclude_list = settings.get_file_list(EXCLUDE_LIST_KEY);
257
258 // Exclude directories no one wants to backup
259 var always_excluded = get_always_excluded_dirs();
260
261=== modified file 'monitor/monitor.vala'
262--- monitor/monitor.vala 2012-12-21 04:03:03 +0000
263+++ monitor/monitor.vala 2013-01-27 22:01:20 +0000
264@@ -27,7 +27,7 @@
265 static bool op_active = false;
266 static bool reactive_check;
267 static bool first_check = false;
268-static DejaDup.SimpleSettings settings = null;
269+static DejaDup.FilteredSettings settings = null;
270
271 static bool testing_delay = true;
272
273
274=== modified file 'po/POTFILES.in'
275--- po/POTFILES.in 2012-10-24 01:50:46 +0000
276+++ po/POTFILES.in 2013-01-27 22:01:20 +0000
277@@ -16,6 +16,7 @@
278 common/BackendU1.vala
279 common/Backend.vala
280 common/CommonUtils.vala
281+common/FilteredSettings.vala
282 common/Network.vala
283 common/OperationBackup.vala
284 common/OperationFiles.vala
285@@ -26,7 +27,6 @@
286 common/RecursiveDelete.vala
287 common/RecursiveMove.vala
288 common/RecursiveOp.vala
289-common/SimpleSettings.vala
290 deja-dup/AssistantBackup.vala
291 deja-dup/AssistantOperation.vala
292 deja-dup/AssistantRestore.vala
293
294=== modified file 'po/POTFILES.skip'
295--- po/POTFILES.skip 2012-08-10 18:33:29 +0000
296+++ po/POTFILES.skip 2013-01-27 22:01:20 +0000
297@@ -6,6 +6,7 @@
298 common/BackendU1.c
299 common/Backend.c
300 common/CommonUtils.c
301+common/FilteredSettings.c
302 common/Network.c
303 common/OperationBackup.c
304 common/OperationFiles.c
305@@ -16,7 +17,6 @@
306 common/RecursiveDelete.c
307 common/RecursiveMove.c
308 common/RecursiveOp.c
309-common/SimpleSettings.c
310 deja-dup/AssistantBackup.c
311 deja-dup/AssistantOperation.c
312 deja-dup/AssistantRestore.c
313
314=== modified file 'widgets/ConfigEntry.vala'
315--- widgets/ConfigEntry.vala 2012-08-06 22:41:13 +0000
316+++ widgets/ConfigEntry.vala 2013-01-27 22:01:20 +0000
317@@ -23,9 +23,11 @@
318
319 public class ConfigEntry : ConfigWidget
320 {
321- public ConfigEntry(string key, string ns="")
322+ public bool is_uri {get; set;}
323+
324+ public ConfigEntry(string key, string ns="", bool is_uri=false)
325 {
326- Object(key: key, ns: ns);
327+ Object(key: key, ns: ns, is_uri: is_uri);
328 }
329
330 public string get_text()
331@@ -52,9 +54,7 @@
332
333 protected override async void set_from_config()
334 {
335- var val = settings.get_string(key);
336- if (val == null)
337- val = "";
338+ var val = is_uri ? settings.get_uri(key) : settings.get_string(key);
339 entry.set_text(val);
340 }
341
342
343=== modified file 'widgets/ConfigLabelList.vala'
344--- widgets/ConfigLabelList.vala 2011-10-19 15:03:07 +0000
345+++ widgets/ConfigLabelList.vala 2013-01-27 22:01:20 +0000
346@@ -35,10 +35,7 @@
347 protected override async void set_from_config()
348 {
349 string val = null;
350- var slist_val = settings.get_value(key);
351- string*[] slist = slist_val.get_strv();
352-
353- var list = DejaDup.parse_dir_list(slist);
354+ var list = settings.get_file_list(key);
355
356 foreach (File f in list) {
357 string s = yield DejaDup.get_nickname(f);
358
359=== modified file 'widgets/ConfigLabelLocation.vala'
360--- widgets/ConfigLabelLocation.vala 2012-08-06 22:41:13 +0000
361+++ widgets/ConfigLabelLocation.vala 2013-01-27 22:01:20 +0000
362@@ -24,10 +24,10 @@
363 public class ConfigLabelLocation : ConfigLabel
364 {
365 Gtk.Image img;
366- SimpleSettings file_root;
367- SimpleSettings s3_root;
368- SimpleSettings u1_root;
369- SimpleSettings rackspace_root;
370+ FilteredSettings file_root;
371+ FilteredSettings s3_root;
372+ FilteredSettings u1_root;
373+ FilteredSettings rackspace_root;
374
375 public ConfigLabelLocation()
376 {
377
378=== modified file 'widgets/ConfigList.vala'
379--- widgets/ConfigList.vala 2012-08-06 22:41:13 +0000
380+++ widgets/ConfigList.vala 2013-01-27 22:01:20 +0000
381@@ -225,10 +225,7 @@
382
383 protected override async void set_from_config()
384 {
385- var slist_val = settings.get_value(key);
386- string*[] slist = slist_val.get_strv();
387-
388- var list = DejaDup.parse_dir_list(slist);
389+ var list = settings.get_file_list(key);
390
391 Gtk.ListStore model;
392 tree.get("model", out model);
393@@ -295,6 +292,8 @@
394 if (files == null)
395 return false;
396
397+ // Explicitly do not call get_file_list here, because we want to avoid
398+ // modifying existing entries at all when we write the string list back.
399 var slist_val = settings.get_value(key);
400 string*[] slist = slist_val.get_strv();
401 bool rv = false;
402@@ -322,12 +321,6 @@
403 return rv;
404 }
405
406- public string[] get_files()
407- {
408- var slist_val = settings.get_value(key);
409- return slist_val.dup_strv();
410- }
411-
412 public void write_to_config(Gtk.TreeModel model, Gtk.TreePath? path)
413 {
414 Gtk.TreeIter iter;
415
416=== modified file 'widgets/ConfigLocationCustom.vala'
417--- widgets/ConfigLocationCustom.vala 2012-03-17 04:02:46 +0000
418+++ widgets/ConfigLocationCustom.vala 2013-01-27 22:01:20 +0000
419@@ -28,7 +28,8 @@
420 }
421
422 construct {
423- var entry = new ConfigEntry(DejaDup.FILE_PATH_KEY, DejaDup.FILE_ROOT);
424+ var entry = new ConfigEntry(DejaDup.FILE_PATH_KEY, DejaDup.FILE_ROOT,
425+ true);
426 entry.set_accessible_name("CustomFolder");
427 add_widget(_("_URI"), entry);
428 }
429
430=== modified file 'widgets/ConfigURLPart.vala'
431--- widgets/ConfigURLPart.vala 2011-06-28 15:48:17 +0000
432+++ widgets/ConfigURLPart.vala 2013-01-27 22:01:20 +0000
433@@ -44,7 +44,7 @@
434 write_uri_part(settings, key, part, userval);
435 }
436
437- public static string read_uri_part(SimpleSettings settings, string key, Part part)
438+ public static string read_uri_part(FilteredSettings settings, string key, Part part)
439 {
440 var uri = get_current_uri(settings, key);
441
442@@ -78,7 +78,7 @@
443 return text;
444 }
445
446- public static void write_uri_part(SimpleSettings settings, string key, Part part, string userval)
447+ public static void write_uri_part(FilteredSettings settings, string key, Part part, string userval)
448 {
449 var uri = get_current_uri(settings, key);
450
451@@ -114,11 +114,9 @@
452 settings.set_string(key, val);
453 }
454
455- static DejaDupDecodedUri get_current_uri(SimpleSettings settings, string key)
456+ static DejaDupDecodedUri get_current_uri(FilteredSettings settings, string key)
457 {
458- var val = settings.get_string(key);
459- if (val == null)
460- val = "";
461+ var val = settings.get_uri(key);
462
463 // First, try to parse as is. What's stored in settings is actually a
464 // GFile parse_name, but we'd like a first crack at it because passing
465
466=== modified file 'widgets/ConfigWidget.vala'
467--- widgets/ConfigWidget.vala 2012-08-06 22:41:13 +0000
468+++ widgets/ConfigWidget.vala 2013-01-27 22:01:20 +0000
469@@ -30,8 +30,8 @@
470 public string ns {get; construct; default = "";}
471
472 protected bool syncing;
473- protected SimpleSettings settings;
474- protected List<SimpleSettings> all_settings;
475+ protected FilteredSettings settings;
476+ protected List<FilteredSettings> all_settings;
477 construct {
478 visible_window = false;
479
480@@ -45,13 +45,13 @@
481
482 ~ConfigWidget() {
483 SignalHandler.disconnect_by_func(settings, (void*)key_changed_wrapper, this);
484- foreach (weak SimpleSettings s in all_settings) {
485+ foreach (weak FilteredSettings s in all_settings) {
486 SignalHandler.disconnect_by_func(s, (void*)key_changed_wrapper, this);
487 s.unref();
488 }
489 }
490
491- protected void watch_key(string? key, SimpleSettings? s = null)
492+ protected void watch_key(string? key, FilteredSettings? s = null)
493 {
494 if (s == null) {
495 s = settings;

Subscribers

People subscribed via source and target branches