diff options
| author | Stephen Hines <srhines@google.com> | 2013-10-30 17:48:30 -0700 |
|---|---|---|
| committer | Jason Sams <jsams@google.com> | 2013-11-25 18:09:06 -0800 |
| commit | ee48c0bbf290a73e2cd4710b70d62fc203dac0dc (patch) | |
| tree | 886467fe497de3aaf5b977e2388839b46a8243ef /cpu_ref/rsCpuScript.cpp | |
| parent | 75adb8213f045bf3ffbc5deb1350b36d486e228a (diff) | |
Create a cache directory for our symlinked files if necessary.
Bug: 11519886
Change-Id: I93d3c194a15e4842455c31406095e90bced882ee
Diffstat (limited to 'cpu_ref/rsCpuScript.cpp')
| -rw-r--r-- | cpu_ref/rsCpuScript.cpp | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/cpu_ref/rsCpuScript.cpp b/cpu_ref/rsCpuScript.cpp index c956f438..2b69d857 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 @@ static std::string getRandomString(size_t len) { 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 @@ static void *loadSOHelper(const char *origName, const char *cacheDir, 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. |
