From fae41617bb77b8317f7b0ea5e8e2acf90cfd8c8e Mon Sep 17 00:00:00 2001
From: Bruce Merry <bmerry@ska.ac.za>
Date: Fri, 14 Nov 2014 12:03:31 +0200
Subject: [PATCH] Use appdirs module to get appropriate cache directory.

This fixes an insecure temporary file creation bug on UNIX-like systems.
---
 pyopencl/cache.py | 11 +++++------
 setup.py          |  1 +
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/pyopencl/cache.py b/pyopencl/cache.py
index 0db15d6e..6d054648 100644
--- a/pyopencl/cache.py
+++ b/pyopencl/cache.py
@@ -337,16 +337,15 @@ def _create_built_program_from_source_cached(ctx, src, options, devices, cache_d
             option_idx += 1
 
     if cache_dir is None:
-        from tempfile import gettempdir
-        import getpass
-        cache_dir = join(gettempdir(),
-                "pyopencl-compiler-cache-v2-uid%s-py%s" % (
-                    getpass.getuser(), ".".join(str(i) for i in sys.version_info)))
+        import appdirs
+        cache_dir = join(appdirs.user_cache_dir("pyopencl", "pyopencl"),
+                "pyopencl-compiler-cache-v2-py%s" % (
+                    ".".join(str(i) for i in sys.version_info),))
 
     # {{{ ensure cache directory exists
 
     try:
-        os.mkdir(cache_dir)
+        os.makedirs(cache_dir)
     except OSError, e:
         from errno import EEXIST
         if e.errno != EEXIST:
diff --git a/setup.py b/setup.py
index 4ef1f888..6dc78e51 100644
--- a/setup.py
+++ b/setup.py
@@ -208,6 +208,7 @@ def main():
                 "pytools>=2014.2",
                 "pytest>=2",
                 "decorator>=3.2.0",
+                "appdirs>=1.4.0",
                 # "Mako>=0.3.6",
                 ],
 
-- 
GitLab