deja-dup-team team mailing list archive
-
deja-dup-team team
-
Mailing list archive
-
Message #00541
[Merge] lp:~mterry/deja-dup/parse-file-path into lp:deja-dup
Michael Terry has proposed merging lp:~mterry/deja-dup/parse-file-path into lp:deja-dup.
Requested reviews:
Robert Bruce Park (robru)
For more details, see:
https://code.launchpad.net/~mterry/deja-dup/parse-file-path/+merge/145105
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.
--
https://code.launchpad.net/~mterry/deja-dup/parse-file-path/+merge/145105
Your team Déjà Dup Developers is subscribed to branch lp:deja-dup.
=== modified file '.bzrignore'
--- .bzrignore 2012-03-20 12:23:51 +0000
+++ .bzrignore 2013-01-27 22:01:20 +0000
@@ -7,6 +7,7 @@
common/DuplicityInfo.c
common/DuplicityInstance.c
common/Duplicity.c
+common/FilteredSettings.c
common/Network.c
common/OperationBackup.c
common/OperationFiles.c
@@ -16,7 +17,6 @@
common/RecursiveDelete.c
common/RecursiveMove.c
common/RecursiveOp.c
-common/SimpleSettings.c
deja-dup/AssistantBackup.c
deja-dup/AssistantOperation.c
deja-dup/AssistantRestore.c
=== modified file 'common/CommonUtils.vala'
--- common/CommonUtils.vala 2013-01-20 19:54:44 +0000
+++ common/CommonUtils.vala 2013-01-27 22:01:20 +0000
@@ -276,7 +276,7 @@
return (last_check.compare(now) <= 0);
}
-public string get_folder_key(SimpleSettings settings, string key)
+public string get_folder_key(FilteredSettings settings, string key)
{
string folder = settings.get_string(key);
if (folder.contains("$HOSTNAME")) {
@@ -289,7 +289,7 @@
}
bool settings_read_only = false;
-HashTable<string, SimpleSettings> settings_table = null;
+HashTable<string, FilteredSettings> settings_table = null;
public void set_settings_read_only(bool ro)
{
settings_read_only = ro;
@@ -297,7 +297,7 @@
// When read only, we also need to make sure everyone shares the same
// settings object. Otherwise, they will not notice the changes other
// parts of the code make.
- settings_table = new HashTable<string, SimpleSettings>.full(str_hash,
+ settings_table = new HashTable<string, FilteredSettings>.full(str_hash,
str_equal,
g_free,
g_object_unref);
@@ -307,22 +307,22 @@
}
}
-public SimpleSettings get_settings(string? subdir = null)
+public FilteredSettings get_settings(string? subdir = null)
{
string schema = "org.gnome.DejaDup";
if (subdir != null && subdir != "")
schema += "." + subdir;
- SimpleSettings rv;
+ FilteredSettings rv;
if (settings_read_only) {
rv = settings_table.lookup(schema);
if (rv == null) {
- rv = new SimpleSettings(schema, true);
+ rv = new FilteredSettings(schema, true);
rv.delay(); // never to be apply()'d again
settings_table.insert(schema, rv);
}
}
else {
- rv = new SimpleSettings(schema, false);
+ rv = new FilteredSettings(schema, false);
}
return rv;
}
@@ -565,8 +565,7 @@
// This is admittedly fast and loose, but our primary concern is just
// avoiding silly choices like tmpfs or tiny special /tmp partitions.
var settings = get_settings();
- var include_val = settings.get_value(INCLUDE_LIST_KEY);
- var include_list = parse_dir_list(include_val.get_strv());
+ var include_list = settings.get_file_list(INCLUDE_LIST_KEY);
File main_include = null;
var home = File.new_for_path(Environment.get_home_dir());
foreach (var include in include_list) {
=== modified file 'common/DirHandling.vala'
--- common/DirHandling.vala 2012-12-04 16:08:06 +0000
+++ common/DirHandling.vala 2013-01-27 22:01:20 +0000
@@ -26,41 +26,45 @@
return Path.build_filename(Environment.get_user_data_dir(), "Trash");
}
-public File? parse_dir(string dir)
+public string? parse_keywords(string dir)
{
- string s = dir;
- if (s == "$HOME")
- s = Environment.get_home_dir();
- else if (s == "$DESKTOP")
- s = Environment.get_user_special_dir(UserDirectory.DESKTOP);
- else if (s == "$DOCUMENTS")
- s = Environment.get_user_special_dir(UserDirectory.DOCUMENTS);
- else if (s == "$DOWNLOAD")
- s = Environment.get_user_special_dir(UserDirectory.DOWNLOAD);
- else if (s == "$MUSIC")
- s = Environment.get_user_special_dir(UserDirectory.MUSIC);
- else if (s == "$PICTURES")
- s = Environment.get_user_special_dir(UserDirectory.PICTURES);
- else if (s == "$PUBLIC_SHARE")
- s = Environment.get_user_special_dir(UserDirectory.PUBLIC_SHARE);
- else if (s == "$TEMPLATES")
- s = Environment.get_user_special_dir(UserDirectory.TEMPLATES);
- else if (s == "$TRASH")
- s = get_trash_path();
- else if (s == "$VIDEOS")
- s = Environment.get_user_special_dir(UserDirectory.VIDEOS);
+ string result = null;
+ if (dir == "$HOME")
+ result = Environment.get_home_dir();
+ else if (dir == "$DESKTOP")
+ result = Environment.get_user_special_dir(UserDirectory.DESKTOP);
+ else if (dir == "$DOCUMENTS")
+ result = Environment.get_user_special_dir(UserDirectory.DOCUMENTS);
+ else if (dir == "$DOWNLOAD")
+ result = Environment.get_user_special_dir(UserDirectory.DOWNLOAD);
+ else if (dir == "$MUSIC")
+ result = Environment.get_user_special_dir(UserDirectory.MUSIC);
+ else if (dir == "$PICTURES")
+ result = Environment.get_user_special_dir(UserDirectory.PICTURES);
+ else if (dir == "$PUBLIC_SHARE")
+ result = Environment.get_user_special_dir(UserDirectory.PUBLIC_SHARE);
+ else if (dir == "$TEMPLATES")
+ result = Environment.get_user_special_dir(UserDirectory.TEMPLATES);
+ else if (dir == "$TRASH")
+ result = get_trash_path();
+ else if (dir == "$VIDEOS")
+ result = Environment.get_user_special_dir(UserDirectory.VIDEOS);
else {
// Some variables can be placed inside a larger path, so replace those
- s = s.replace("$USER", Environment.get_user_name());
+ result = dir.replace("$USER", Environment.get_user_name());
- if (Uri.parse_scheme(s) == null && !Path.is_absolute(s))
- s = Path.build_filename(Environment.get_home_dir(), s);
- else
- return File.parse_name(s);
+ if (Uri.parse_scheme(result) == null && !Path.is_absolute(result))
+ result = Path.build_filename(Environment.get_home_dir(), result);
}
- if (s != null)
- return File.new_for_path(s);
+ return result;
+}
+
+public File? parse_dir(string dir)
+{
+ var result = parse_keywords(dir);
+ if (result != null)
+ return File.parse_name(result);
else
return null;
}
=== renamed file 'common/SimpleSettings.vala' => 'common/FilteredSettings.vala'
--- common/SimpleSettings.vala 2011-08-14 15:41:22 +0000
+++ common/FilteredSettings.vala 2013-01-27 22:01:20 +0000
@@ -31,11 +31,11 @@
dconf, so it's nice to be able to avoid those.
*/
-public class SimpleSettings : Settings
+public class FilteredSettings : Settings
{
public bool read_only {get; set;}
- public SimpleSettings(string schema, bool ro)
+ public FilteredSettings(string schema, bool ro)
{
Object(schema: schema, read_only: ro);
}
@@ -59,6 +59,23 @@
base.set_value(k, v);
}
+ // May be uri, or may be a File's parsed path for historical reasons
+ public new string get_uri(string k) {
+ // If we are reading a URI, replace some special keywords.
+ var val = get_string(k);
+ var result = parse_keywords(val);
+ if (result == null)
+ return "";
+ else
+ return result;
+ }
+
+ public new File[] get_file_list(string k) {
+ // If we are reading a file path, replace some special keywords.
+ var val = get_value(k);
+ return parse_dir_list(val.get_strv());
+ }
+
// TODO: bytestring, strv
}
=== modified file 'common/Makefile.am'
--- common/Makefile.am 2012-11-01 09:16:02 +0000
+++ common/Makefile.am 2013-01-27 22:01:20 +0000
@@ -44,6 +44,7 @@
Checker.vala \
CommonUtils.vala \
DirHandling.vala \
+ FilteredSettings.vala \
Network.vala \
Operation.vala \
OperationBackup.vala \
@@ -55,7 +56,6 @@
RecursiveDelete.vala \
RecursiveMove.vala \
RecursiveOp.vala \
- SimpleSettings.vala \
ToolPlugin.vala
libcommon_la_SOURCES = \
=== modified file 'common/Operation.vala'
--- common/Operation.vala 2013-01-20 19:54:44 +0000
+++ common/Operation.vala 2013-01-27 22:01:20 +0000
@@ -87,7 +87,7 @@
set_passphrase(state.passphrase);
}
- SimpleSettings settings;
+ FilteredSettings settings;
internal ToolJob job;
protected string passphrase;
bool finished = false;
=== modified file 'common/OperationBackup.vala'
--- common/OperationBackup.vala 2013-01-20 19:54:44 +0000
+++ common/OperationBackup.vala 2013-01-27 22:01:20 +0000
@@ -55,11 +55,8 @@
protected override List<string>? make_argv()
{
var settings = get_settings();
-
- var include_val = settings.get_value(INCLUDE_LIST_KEY);
- var include_list = parse_dir_list(include_val.get_strv());
- var exclude_val = settings.get_value(EXCLUDE_LIST_KEY);
- var exclude_list = parse_dir_list(exclude_val.get_strv());
+ var include_list = settings.get_file_list(INCLUDE_LIST_KEY);
+ var exclude_list = settings.get_file_list(EXCLUDE_LIST_KEY);
// Exclude directories no one wants to backup
var always_excluded = get_always_excluded_dirs();
=== modified file 'monitor/monitor.vala'
--- monitor/monitor.vala 2012-12-21 04:03:03 +0000
+++ monitor/monitor.vala 2013-01-27 22:01:20 +0000
@@ -27,7 +27,7 @@
static bool op_active = false;
static bool reactive_check;
static bool first_check = false;
-static DejaDup.SimpleSettings settings = null;
+static DejaDup.FilteredSettings settings = null;
static bool testing_delay = true;
=== modified file 'po/POTFILES.in'
--- po/POTFILES.in 2012-10-24 01:50:46 +0000
+++ po/POTFILES.in 2013-01-27 22:01:20 +0000
@@ -16,6 +16,7 @@
common/BackendU1.vala
common/Backend.vala
common/CommonUtils.vala
+common/FilteredSettings.vala
common/Network.vala
common/OperationBackup.vala
common/OperationFiles.vala
@@ -26,7 +27,6 @@
common/RecursiveDelete.vala
common/RecursiveMove.vala
common/RecursiveOp.vala
-common/SimpleSettings.vala
deja-dup/AssistantBackup.vala
deja-dup/AssistantOperation.vala
deja-dup/AssistantRestore.vala
=== modified file 'po/POTFILES.skip'
--- po/POTFILES.skip 2012-08-10 18:33:29 +0000
+++ po/POTFILES.skip 2013-01-27 22:01:20 +0000
@@ -6,6 +6,7 @@
common/BackendU1.c
common/Backend.c
common/CommonUtils.c
+common/FilteredSettings.c
common/Network.c
common/OperationBackup.c
common/OperationFiles.c
@@ -16,7 +17,6 @@
common/RecursiveDelete.c
common/RecursiveMove.c
common/RecursiveOp.c
-common/SimpleSettings.c
deja-dup/AssistantBackup.c
deja-dup/AssistantOperation.c
deja-dup/AssistantRestore.c
=== modified file 'widgets/ConfigEntry.vala'
--- widgets/ConfigEntry.vala 2012-08-06 22:41:13 +0000
+++ widgets/ConfigEntry.vala 2013-01-27 22:01:20 +0000
@@ -23,9 +23,11 @@
public class ConfigEntry : ConfigWidget
{
- public ConfigEntry(string key, string ns="")
+ public bool is_uri {get; set;}
+
+ public ConfigEntry(string key, string ns="", bool is_uri=false)
{
- Object(key: key, ns: ns);
+ Object(key: key, ns: ns, is_uri: is_uri);
}
public string get_text()
@@ -52,9 +54,7 @@
protected override async void set_from_config()
{
- var val = settings.get_string(key);
- if (val == null)
- val = "";
+ var val = is_uri ? settings.get_uri(key) : settings.get_string(key);
entry.set_text(val);
}
=== modified file 'widgets/ConfigLabelList.vala'
--- widgets/ConfigLabelList.vala 2011-10-19 15:03:07 +0000
+++ widgets/ConfigLabelList.vala 2013-01-27 22:01:20 +0000
@@ -35,10 +35,7 @@
protected override async void set_from_config()
{
string val = null;
- var slist_val = settings.get_value(key);
- string*[] slist = slist_val.get_strv();
-
- var list = DejaDup.parse_dir_list(slist);
+ var list = settings.get_file_list(key);
foreach (File f in list) {
string s = yield DejaDup.get_nickname(f);
=== modified file 'widgets/ConfigLabelLocation.vala'
--- widgets/ConfigLabelLocation.vala 2012-08-06 22:41:13 +0000
+++ widgets/ConfigLabelLocation.vala 2013-01-27 22:01:20 +0000
@@ -24,10 +24,10 @@
public class ConfigLabelLocation : ConfigLabel
{
Gtk.Image img;
- SimpleSettings file_root;
- SimpleSettings s3_root;
- SimpleSettings u1_root;
- SimpleSettings rackspace_root;
+ FilteredSettings file_root;
+ FilteredSettings s3_root;
+ FilteredSettings u1_root;
+ FilteredSettings rackspace_root;
public ConfigLabelLocation()
{
=== modified file 'widgets/ConfigList.vala'
--- widgets/ConfigList.vala 2012-08-06 22:41:13 +0000
+++ widgets/ConfigList.vala 2013-01-27 22:01:20 +0000
@@ -225,10 +225,7 @@
protected override async void set_from_config()
{
- var slist_val = settings.get_value(key);
- string*[] slist = slist_val.get_strv();
-
- var list = DejaDup.parse_dir_list(slist);
+ var list = settings.get_file_list(key);
Gtk.ListStore model;
tree.get("model", out model);
@@ -295,6 +292,8 @@
if (files == null)
return false;
+ // Explicitly do not call get_file_list here, because we want to avoid
+ // modifying existing entries at all when we write the string list back.
var slist_val = settings.get_value(key);
string*[] slist = slist_val.get_strv();
bool rv = false;
@@ -322,12 +321,6 @@
return rv;
}
- public string[] get_files()
- {
- var slist_val = settings.get_value(key);
- return slist_val.dup_strv();
- }
-
public void write_to_config(Gtk.TreeModel model, Gtk.TreePath? path)
{
Gtk.TreeIter iter;
=== modified file 'widgets/ConfigLocationCustom.vala'
--- widgets/ConfigLocationCustom.vala 2012-03-17 04:02:46 +0000
+++ widgets/ConfigLocationCustom.vala 2013-01-27 22:01:20 +0000
@@ -28,7 +28,8 @@
}
construct {
- var entry = new ConfigEntry(DejaDup.FILE_PATH_KEY, DejaDup.FILE_ROOT);
+ var entry = new ConfigEntry(DejaDup.FILE_PATH_KEY, DejaDup.FILE_ROOT,
+ true);
entry.set_accessible_name("CustomFolder");
add_widget(_("_URI"), entry);
}
=== modified file 'widgets/ConfigURLPart.vala'
--- widgets/ConfigURLPart.vala 2011-06-28 15:48:17 +0000
+++ widgets/ConfigURLPart.vala 2013-01-27 22:01:20 +0000
@@ -44,7 +44,7 @@
write_uri_part(settings, key, part, userval);
}
- public static string read_uri_part(SimpleSettings settings, string key, Part part)
+ public static string read_uri_part(FilteredSettings settings, string key, Part part)
{
var uri = get_current_uri(settings, key);
@@ -78,7 +78,7 @@
return text;
}
- public static void write_uri_part(SimpleSettings settings, string key, Part part, string userval)
+ public static void write_uri_part(FilteredSettings settings, string key, Part part, string userval)
{
var uri = get_current_uri(settings, key);
@@ -114,11 +114,9 @@
settings.set_string(key, val);
}
- static DejaDupDecodedUri get_current_uri(SimpleSettings settings, string key)
+ static DejaDupDecodedUri get_current_uri(FilteredSettings settings, string key)
{
- var val = settings.get_string(key);
- if (val == null)
- val = "";
+ var val = settings.get_uri(key);
// First, try to parse as is. What's stored in settings is actually a
// GFile parse_name, but we'd like a first crack at it because passing
=== modified file 'widgets/ConfigWidget.vala'
--- widgets/ConfigWidget.vala 2012-08-06 22:41:13 +0000
+++ widgets/ConfigWidget.vala 2013-01-27 22:01:20 +0000
@@ -30,8 +30,8 @@
public string ns {get; construct; default = "";}
protected bool syncing;
- protected SimpleSettings settings;
- protected List<SimpleSettings> all_settings;
+ protected FilteredSettings settings;
+ protected List<FilteredSettings> all_settings;
construct {
visible_window = false;
@@ -45,13 +45,13 @@
~ConfigWidget() {
SignalHandler.disconnect_by_func(settings, (void*)key_changed_wrapper, this);
- foreach (weak SimpleSettings s in all_settings) {
+ foreach (weak FilteredSettings s in all_settings) {
SignalHandler.disconnect_by_func(s, (void*)key_changed_wrapper, this);
s.unref();
}
}
- protected void watch_key(string? key, SimpleSettings? s = null)
+ protected void watch_key(string? key, FilteredSettings? s = null)
{
if (s == null) {
s = settings;
Follow ups