[babl] store cached fishes in ~/.cache/babl



commit d8259096e7e78e768147301a3d5ef8e8afed7a99
Author: Øyvind Kolås <pippin gimp org>
Date:   Tue Nov 15 17:02:10 2016 +0100

    store cached fishes in ~/.cache/babl
    
    Still no fish cache path solution for win32

 babl/babl-cache.c |   29 ++++++++++++++++++++++++++++-
 1 files changed, 28 insertions(+), 1 deletions(-)
---
diff --git a/babl/babl-cache.c b/babl/babl-cache.c
index 42a704d..35ae260 100644
--- a/babl/babl-cache.c
+++ b/babl/babl-cache.c
@@ -17,13 +17,40 @@
  */
 
 #include <time.h>
+#include <sys/stat.h>
 #include "config.h"
 #include "babl-internal.h"
 #include "git-version.h"
 
 static const char *fish_cache_path (void)
 {
-  return "/tmp/babl.db"; // XXX: a $HOME/.cache/babl/fishes path might be better
+  // FIXME: need a location for this temporary file on win32
+  struct stat stat_buf;
+  static char resolved[4096];
+  char *ret = NULL;
+  if (getenv ("HOME"))
+  {
+    sprintf (resolved, "%s/.cache/babl/fishes", getenv("HOME"));
+  }
+  else
+  {
+    return "/tmp/babl.db";
+  }
+
+  if (stat (resolved, &stat_buf)==0 && S_ISREG(stat_buf.st_mode))
+    return resolved;
+  ret = strdup (resolved);
+
+  while (strrchr (resolved, '/'))
+  {
+    *strrchr (resolved, '/') = '\0';
+    mkdir (resolved, S_IRWXU);
+  }
+
+  strcpy (resolved, ret);
+  free (ret);
+
+  return resolved;
 }
 
 static char *


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]