[vlc-commits] android: fix config_GetUserDir for data/cache/home/config

Thomas Guillem git at videolan.org
Wed Jul 13 15:43:43 CEST 2016


vlc | branch: master | Thomas Guillem <thomas at gllm.fr> | Tue Jul 12 16:29:57 2016 +0200| [af873cf80decda07660a38336260f4c4c932a9ed] | committer: Thomas Guillem

android: fix config_GetUserDir for data/cache/home/config

These paths are based on the HOME environment variable.

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=af873cf80decda07660a38336260f4c4c932a9ed
---

 src/android/specific.c |   34 ++++++++++++++++++++++++++++++----
 1 file changed, 30 insertions(+), 4 deletions(-)

diff --git a/src/android/specific.c b/src/android/specific.c
index 8fe4cd5..959dc37 100644
--- a/src/android/specific.c
+++ b/src/android/specific.c
@@ -25,6 +25,7 @@
 #include <assert.h>
 
 #include <vlc_common.h>
+#include <vlc_fs.h>
 #include "../libvlc.h"
 #include "config/configuration.h"
 
@@ -65,18 +66,43 @@ system_Configure(libvlc_int_t *p_libvlc, int i_argc, const char *const pp_argv[]
     var_SetAddress(p_libvlc, "android-jvm", s_jvm);
 }
 
+static char *config_GetHomeDir(const char *psz_dir, const char *psz_default_dir)
+{
+    char *psz_home = getenv("HOME");
+    if (psz_home == NULL)
+        goto fallback;
+
+    if (psz_dir == NULL)
+        return strdup(psz_home);
+
+    char *psz_fullpath;
+    if (asprintf(&psz_fullpath, "%s/%s", psz_home, psz_dir) == -1)
+        goto fallback;
+    if (vlc_mkdir(psz_fullpath, 0700) == -1 && errno != EEXIST)
+    {
+        free(psz_fullpath);
+        goto fallback;
+    }
+    return psz_fullpath;
+
+fallback:
+    return psz_default_dir != NULL ? strdup(psz_default_dir) : NULL;
+}
+
 char *config_GetUserDir (vlc_userdir_t type)
 {
     switch (type)
     {
         case VLC_DATA_DIR:
-            return strdup("/sdcard/Android/data/org.videolan.vlc");
+            return config_GetHomeDir(".share",
+                "/sdcard/Android/data/org.videolan.vlc");
         case VLC_CACHE_DIR:
-            return strdup("/sdcard/Android/data/org.videolan.vlc/cache");
-
+            return config_GetHomeDir(".cache",
+                "/sdcard/Android/data/org.videolan.vlc/cache");
         case VLC_HOME_DIR:
+            return config_GetHomeDir(NULL, NULL);
         case VLC_CONFIG_DIR:
-            return NULL;
+            return config_GetHomeDir(".config", NULL);
 
         case VLC_DESKTOP_DIR:
         case VLC_DOWNLOAD_DIR:



More information about the vlc-commits mailing list