am d99b1df3: am 661a62c3: Create a cache directory for our symlinked files if necessary.

* commit 'd99b1df331de2b4327981cdb4661b88b2ffd7a99':
  Create a cache directory for our symlinked files if necessary.
diff --git a/cpu_ref/rsCpuScript.cpp b/cpu_ref/rsCpuScript.cpp
index c956f43..2b69d85 100644
--- a/cpu_ref/rsCpuScript.cpp
+++ b/cpu_ref/rsCpuScript.cpp
@@ -24,6 +24,7 @@
     #include <stdio.h>
     #include <stdlib.h>
     #include <string.h>
+    #include <sys/stat.h>
     #include <unistd.h>
 #else
     #include <bcc/BCCContext.h>
@@ -62,6 +63,18 @@
     return std::string(buf);
 }
 
+// Check if a path exists and attempt to create it if it doesn't.
+static bool ensureCacheDirExists(const char *path) {
+    if (access(path, R_OK | W_OK | X_OK) == 0) {
+        // Done if we can rwx the directory
+        return true;
+    }
+    if (mkdir(path, 0700) == 0) {
+        return true;
+    }
+    return false;
+}
+
 // Attempt to load the shared library from origName, but then fall back to
 // creating the symlinked shared library if necessary (to ensure instancing).
 // This function returns the dlopen()-ed handle if successful.
@@ -91,9 +104,16 @@
         return loaded;
     }
 
-    // Construct an appropriately randomized filename for the symlink.
     std::string newName(cacheDir);
-    newName.append("/com.android.renderscript.cache/librs.");
+    newName.append("/com.android.renderscript.cache/");
+
+    if (!ensureCacheDirExists(newName.c_str())) {
+        ALOGE("Could not verify or create cache dir: %s", cacheDir);
+        return NULL;
+    }
+
+    // Construct an appropriately randomized filename for the symlink.
+    newName.append("librs.");
     newName.append(resName);
     newName.append("#");
     newName.append(getRandomString(6));  // 62^6 potential filename variants.