← Back to team overview

deja-dup-team team mailing list archive

[Merge] lp:~nathanael-naeri/deja-dup/fix-1549776 into lp:deja-dup

 

Naël has proposed merging lp:~nathanael-naeri/deja-dup/fix-1549776 into lp:deja-dup with lp:~nathanael-naeri/deja-dup/fix-1660174-1660224-1660342 as a prerequisite.

Commit message:
Support $HOME/subdir and $XDG_SPECIAL_USER_DIRECTORY/subdir constructs in include-list and exclude-list DConf keys (fixes LP:1549776).

Requested reviews:
  Michael Terry (mterry)
Related bugs:
  Bug #1549776 in Déjà Dup: "Constructs like $HOME/path in the include and exclude lists are not honored"
  https://bugs.launchpad.net/deja-dup/+bug/1549776

For more details, see:
https://code.launchpad.net/~nathanael-naeri/deja-dup/fix-1549776/+merge/317042

I propose minor changes to libdeja/DirHandling.vala in order to support constructs like $HOME/subdir and $DOCUMENTS/subdir in the include-list and exclude-list DConf keys (fixes LP:1549776). Current support is limited to the top directories ($HOME, $DOCUMENTS...) without any subdirectory indication.

The documentation for the include-list and exclude-list keys is changed accordingly in data/org.gnome.DejaDup.gschema.xml.in. Changes are limited to those two files. Please review the bug report and the changes in those files.

Testing the changes in this branch is made easier by the fixes to the test shell I propose in branch lp:~nathanael-naeri/deja-dup/fix-1660174-1660224-1660342, so please merge that branch first.
-- 
Your team Déjà Dup Developers is subscribed to branch lp:deja-dup.
=== modified file 'data/org.gnome.DejaDup.gschema.xml.in'
--- data/org.gnome.DejaDup.gschema.xml.in	2016-12-15 18:33:08 +0000
+++ data/org.gnome.DejaDup.gschema.xml.in	2017-02-12 02:37:21 +0000
@@ -4,12 +4,12 @@
     <key name="include-list" type="as">
       <default>[ '$HOME' ]</default>
       <_summary>Folders to save</_summary>
-      <_description>This list of directories will be backed up.  Reserved values $HOME, $DESKTOP, $DOCUMENTS, $DOWNLOAD, $MUSIC, $PICTURES, $PUBLIC_SHARE, $TEMPLATES, $TRASH, and $VIDEOS are recognized as the user’s special directories.  Relative entries are relative to the user’s home directory.</_description>
+      <_description>This list of directories will be backed up.  Reserved values $HOME, $DESKTOP, $DOCUMENTS, $DOWNLOAD, $MUSIC, $PICTURES, $PUBLIC_SHARE, $TEMPLATES, $TRASH, and $VIDEOS are recognized as the user’s special directories and can be at the start of a longer path ($HOME/subdir).  Reserved value $USER is replaced by the user’s username and can be anywhere in the path.  Relative entries are relative to the user’s home directory.</_description>
     </key>
     <key name="exclude-list" type="as">
       <default>[ '$TRASH', '$DOWNLOAD' ]</default>
       <_summary>Folders to ignore</_summary>
-      <_description>This list of directories will not be backed up.  Reserved values $HOME, $DESKTOP, $DOCUMENTS, $DOWNLOAD, $MUSIC, $PICTURES, $PUBLIC_SHARE, $TEMPLATES, $TRASH, and $VIDEOS are recognized as the user’s special directories.  Relative entries are relative to the user’s home directory.</_description>
+      <_description>This list of directories will not be backed up.  Reserved values $HOME, $DESKTOP, $DOCUMENTS, $DOWNLOAD, $MUSIC, $PICTURES, $PUBLIC_SHARE, $TEMPLATES, $TRASH, and $VIDEOS are recognized as the user’s special directories and can be at the start of a longer path ($HOME/subdir).  Reserved value $USER is replaced by the user’s username and can be anywhere in the path.  Relative entries are relative to the user’s home directory.</_description>
     </key>
     <key name="root-prompt" type="b">
       <default>true</default>

=== modified file 'libdeja/DirHandling.vala'
--- libdeja/DirHandling.vala	2013-01-27 21:50:59 +0000
+++ libdeja/DirHandling.vala	2017-02-12 02:37:21 +0000
@@ -29,30 +29,34 @@
 public string? parse_keywords(string dir)
 {
   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);
+
+  // Replace special variables when they are at the start of a larger path
+  // The resulting string is an absolute path
+  if (dir.has_prefix("$HOME"))
+    result = dir.replace("$HOME", Environment.get_home_dir());
+  else if (dir.has_prefix("$DESKTOP"))
+    result = dir.replace("$DESKTOP", Environment.get_user_special_dir(UserDirectory.DESKTOP));
+  else if (dir.has_prefix("$DOCUMENTS"))
+    result = dir.replace("$DOCUMENTS", Environment.get_user_special_dir(UserDirectory.DOCUMENTS));
+  else if (dir.has_prefix("$DOWNLOAD"))
+    result = dir.replace("$DOWNLOAD", Environment.get_user_special_dir(UserDirectory.DOWNLOAD));
+  else if (dir.has_prefix("$MUSIC"))
+    result = dir.replace("$MUSIC", Environment.get_user_special_dir(UserDirectory.MUSIC));
+  else if (dir.has_prefix("$PICTURES"))
+    result = dir.replace("$PICTURES", Environment.get_user_special_dir(UserDirectory.PICTURES));
+  else if (dir.has_prefix("$PUBLIC_SHARE"))
+    result = dir.replace("$PUBLIC_SHARE", Environment.get_user_special_dir(UserDirectory.PUBLIC_SHARE));
+  else if (dir.has_prefix("$TEMPLATES"))
+    result = dir.replace("$TEMPLATES", Environment.get_user_special_dir(UserDirectory.TEMPLATES));
+  else if (dir.has_prefix("$TRASH"))
+    result = dir.replace("$TRASH", get_trash_path());
+  else if (dir.has_prefix("$VIDEOS"))
+    result = dir.replace("$VIDEOS", Environment.get_user_special_dir(UserDirectory.VIDEOS));
   else {
-    // Some variables can be placed inside a larger path, so replace those
+    // Some variables can be placed anywhere in the path
     result = dir.replace("$USER", Environment.get_user_name());
 
+    // Relative paths are relative to the user's home directory
     if (Uri.parse_scheme(result) == null && !Path.is_absolute(result))
       result = Path.build_filename(Environment.get_home_dir(), result);
   }


Follow ups