Allow to set empty download-dir.
authorDaniel Carl <danielcarl@gmx.de>
Wed, 12 Mar 2014 20:03:41 +0000 (21:03 +0100)
committerDaniel Carl <danielcarl@gmx.de>
Wed, 12 Mar 2014 20:03:41 +0000 (21:03 +0100)
If the download directory is not set or empty the download will be put into
current directory.

src/main.c
src/setting.c
src/util.c

index 5f26aff..69dadf8 100644 (file)
@@ -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 */
index 1586678..a162fc1 100644 (file)
@@ -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;
index 63f0654..f4e9bb6 100644 (file)
@@ -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 */