From 870b8bae5e962ab89caee2af79c38efc191ac5b4 Mon Sep 17 00:00:00 2001
From: Daniel Carl <danielcarl@gmx.de>
Date: Wed, 12 Mar 2014 21:03:41 +0100
Subject: [PATCH] Allow to set empty download-dir.

If the download directory is not set or empty the download will be put into
current directory.
---
 src/main.c    |  2 +-
 src/setting.c | 18 ++++++++++++------
 src/util.c    |  2 +-
 3 files changed, 14 insertions(+), 8 deletions(-)

diff --git a/src/main.c b/src/main.c
index 5f26aff..69dadf8 100644
--- a/src/main.c
+++ b/src/main.c
@@ -955,7 +955,7 @@ gboolean vb_download(WebKitWebView *view, WebKitDownload *download, const char *
         if (!path || *path == '\0') {
             path = PROJECT "-download";
         }
-        file = g_build_filename(vb.config.download_dir, path, NULL);
+        file = util_build_path(path, vb.config.download_dir);
     }
 
     /* build the file uri from file path */
diff --git a/src/setting.c b/src/setting.c
index 1586678..a162fc1 100644
--- a/src/setting.c
+++ b/src/setting.c
@@ -671,16 +671,22 @@ static SettingStatus download_path(const Setting *s, const SettingType type)
             g_free(vb.config.download_dir);
             vb.config.download_dir = NULL;
         }
+
         path = util_expand(s->arg.s);
-        /* if path is not absolute set it in the home directory */
-        if (*path != '/') {
-            vb.config.download_dir = g_build_filename(util_get_home_dir(), path, NULL);
-            g_free(path);
+        if (*path) {
+            /* if path is not absolute set it in the home directory */
+            if (*path != '/') {
+                vb.config.download_dir = g_build_filename(util_get_home_dir(), path, NULL);
+                g_free(path);
+            } else {
+                vb.config.download_dir = path;
+            }
+            /* create the path if it does not exist */
+            util_create_dir_if_not_exists(vb.config.download_dir);
         } else {
+            /* set the empty path */
             vb.config.download_dir = path;
         }
-        /* create the path if it does not exist */
-        util_create_dir_if_not_exists(vb.config.download_dir);
     }
 
     return SETTING_OK;
diff --git a/src/util.c b/src/util.c
index 63f0654..f4e9bb6 100644
--- a/src/util.c
+++ b/src/util.c
@@ -308,7 +308,7 @@ char *util_build_path(const char *path, const char *dir)
              * no need to free fexp, bacuse this should be done by the caller
              * on fullPath later */
             fullPath = fexp;
-        } else if (dir) {
+        } else if (dir && *dir) {
             /* try to expand also the dir given - this may be ~/path */
             if ((dexp = util_expand(dir))) {
                 /* use expanded dir and append expanded path */
-- 
2.20.1