Repository: lra/mackup

Issue:
Mojave, new workstation
Hi, I'm on a new workstation with Dropbox installed.  I installed mackup with pip and ran 'mackup restore' and got this:

Traceback (most recent call last):
  File "/usr/local/bin/mackup", line 9, in <module>
    load_entry_point('mackup==0.8.20', 'console_scripts', 'mackup')()
  File "/Library/Python/2.7/site-packages/mackup/main.py", line 65, in main
    app_db = ApplicationsDatabase()
  File "/Library/Python/2.7/site-packages/mackup/appsdb.py", line 63, in __init__
    .format(xdg_config_home))
ValueError: $XDG_CONFIG_HOME: /Users/stephens/.config does not exist


Discussion:
Also getting the same thing:

```
$ mackup restore
Traceback (most recent call last):
  File "/usr/local/bin/mackup", line 11, in <module>
    load_entry_point('mackup==0.8.20', 'console_scripts', 'mackup')()
  File "/usr/local/Cellar/mackup/0.8.20/libexec/lib/python3.7/site-packages/mackup/main.py", line 65, in main
    app_db = ApplicationsDatabase()
  File "/usr/local/Cellar/mackup/0.8.20/libexec/lib/python3.7/site-packages/mackup/appsdb.py", line 63, in __init__
    .format(xdg_config_home))
ValueError: $XDG_CONFIG_HOME: /Users/cheeaun/.config does not exist
```
Same here just happened in the last update. Have also just updated to Mojave.
```
$ mackup list
Traceback (most recent call last):
  File "/usr/local/bin/mackup", line 11, in <module>
    load_entry_point('mackup==0.8.20', 'console_scripts', 'mackup')()
  File "/usr/local/Cellar/mackup/0.8.20/libexec/lib/python3.7/site-packages/mackup/main.py", line 65, in main
    app_db = ApplicationsDatabase()
  File "/usr/local/Cellar/mackup/0.8.20/libexec/lib/python3.7/site-packages/mackup/appsdb.py", line 63, in __init__
    .format(xdg_config_home))
ValueError: $XDG_CONFIG_HOME: /Users/tpeters/.config does not exist```
Also had this issue, a very dirty workaround is to set the missing variable before restoring

e.g
`export XDG_CONFIG_HOME=/Users/{yourusername_goes_here}/`
Possibly introduced here?: https://github.com/lra/mackup/pull/1199

To explain the bug, when 'XDG_CONFIG_HOME' doesn't exist (which it doesnt on OSX) this code sets 'xdg_config_home' to `~/.config`. It then checks that this path exists and blows up when it doesn't.

Given the above PR has no explanation I'd guess changing:

`failobj = "{}.config".format(home)`

to 

`failobj = home`

(or just using 'home') would fix this issue but probably breaks something else?
```
mackup backup
Traceback (most recent call last):
  File "/usr/local/bin/mackup", line 11, in <module>
    load_entry_point('mackup==0.8.20', 'console_scripts', 'mackup')()
  File "/usr/local/Cellar/mackup/0.8.20/libexec/lib/python3.7/site-packages/mackup/main.py", line 65, in main
    app_db = ApplicationsDatabase()
  File "/usr/local/Cellar/mackup/0.8.20/libexec/lib/python3.7/site-packages/mackup/appsdb.py", line 63, in __init__
    .format(xdg_config_home))
ValueError: $XDG_CONFIG_HOME: /Users/leo/.config does not exist
```
me too!
Fix with install history version < 0.8.20

```
sudo pip install 'mackup<0.8.20'
```
Hope it work!

Simplest workaround: 

```
mkdir ~/.config
```
Should be fixed in latest version
I still get the problem on a fresh installation via brew
```
Pauls-MacBook:~ paul$ brew info mackup
mackup: stable 0.8.21 (bottled), HEAD
Keep your Mac's application settings in sync
https://github.com/lra/mackup
/usr/local/Cellar/mackup/0.8.21 (1,012 files, 7.0MB) *
  Poured from bottle on 2019-01-15 at 14:41:19
From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/mackup.rb
==> Dependencies
Required: python ✔
==> Options
--HEAD
	Install HEAD version
```
```
Pauls-MacBook:~ paul$ mackup list
Traceback (most recent call last):
  File "/usr/local/bin/mackup", line 11, in <module>
    load_entry_point('mackup==0.8.21', 'console_scripts', 'mackup')()
  File "/usr/local/Cellar/mackup/0.8.21/libexec/lib/python3.7/site-packages/mackup/main.py", line 65, in main
    app_db = ApplicationsDatabase()
  File "/usr/local/Cellar/mackup/0.8.21/libexec/lib/python3.7/site-packages/mackup/appsdb.py", line 63, in __init__
    .format(xdg_config_home))
ValueError: $XDG_CONFIG_HOME: /Users/paul/.config does not exist
```
I see now, it seems you all define an `XDG_CONFIG_HOME` env var that points to a folder that you did not create.

3 solutions here:
- Mackup can ignore the fact that you specify a non existent folder and not sync anything that's supposed to exist in this folder, silently
- Same as the 1st one, by also display a friendly warning saying that you have specified a folder that do not exists
- Fail fast, displaying a friendlier error message.
No, this variable is not defined:
```
Pauls-MacBook:combiner paul$ env|grep XDG_CONFIG_HOME
Pauls-MacBook:combiner paul$ 
```

Resolving patch:
diff --git a/mackup/appsdb.py b/mackup/appsdb.py
--- a/mackup/appsdb.py
+++ b/mackup/appsdb.py
@@ -57,25 +57,21 @@ def __init__(self):
                 home = os.path.expanduser('~/')
                 failobj = "{}.config".format(home)
                 xdg_config_home = os.environ.get('XDG_CONFIG_HOME', failobj)
-                if xdg_config_home:
-                    if not os.path.exists(xdg_config_home):
-                        raise ValueError('$XDG_CONFIG_HOME: {} does not exist'
-                                         .format(xdg_config_home))
-                    if not xdg_config_home.startswith(home):
-                        raise ValueError('$XDG_CONFIG_HOME: {} must be '
-                                         'somewhere within your home '
-                                         'directory: {}'
-                                         .format(xdg_config_home, home))
-                    if config.has_section('xdg_configuration_files'):
-                        for path in config.options('xdg_configuration_files'):
-                            if path.startswith('/'):
-                                raise ValueError('Unsupported absolute path: '
-                                                 '{}'
-                                                 .format(path))
-                            path = os.path.join(xdg_config_home, path)
-                            path = path.replace(home, '')
-                            (self.apps[app_name]['configuration_files']
-                                .add(path))
+                if not xdg_config_home.startswith(home):
+                    raise ValueError('$XDG_CONFIG_HOME: {} must be '
+                                     'somewhere within your home '
+                                     'directory: {}'
+                                     .format(xdg_config_home, home))
+                if config.has_section('xdg_configuration_files'):
+                    for path in config.options('xdg_configuration_files'):
+                        if path.startswith('/'):
+                            raise ValueError('Unsupported absolute path: '
+                                             '{}'
+                                             .format(path))
+                        path = os.path.join(xdg_config_home, path)
+                        path = path.replace(home, '')
+                        (self.apps[app_name]['configuration_files']
+                            .add(path))
 
     @staticmethod
     def get_config_files():


Test patch: