Skip to content

Commit

Permalink
Set up BU_DIR_CACHE env var to override the bu_dir cache location
Browse files Browse the repository at this point in the history
Looking at possibility of unit testing cache behavior, and if we do that
we definitely DON'T want to target the real BU_DIR_CACHE location.
Beyond polluting the user cache with non-working files, that would be a
major potential issue for multiple BRL-CAD builds simultaneously doing
unit testing with the same cache tests.  Allowing for an env variable
gives us a way to target a local build directory in those cases instead.
  • Loading branch information
starseeker committed Oct 17, 2023
1 parent 62152bc commit 223028e
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions src/libbu/dir.c
Original file line number Diff line number Diff line change
Expand Up @@ -214,22 +214,30 @@ dir_cache(char *buf, size_t len)
if (!buf || !len)
return buf;

/* method #1a: platform standard (linux) */
/* method #1: BRL-CAD environment variable */
if (BU_STR_EMPTY(path)) {
env = getenv("BU_DIR_CACHE");
if (env && env[0] != '\0' && !BU_STR_EMPTY(env) && bu_file_writable(env) && bu_file_executable(env)) {
bu_strlcpy(path, env, MAXPATHLEN);
}
}

/* method #2a: platform standard (linux) */
if (BU_STR_EMPTY(path)) {
env = getenv("XDG_CACHE_HOME");
if (!BU_STR_EMPTY(env)) {
bu_strlcpy(path, env, len);
}
}

/* method #1b: platform standard (macosx) */
/* method #2b: platform standard (macosx) */
#if defined(HAVE_CONFSTR) && defined(_CS_DARWIN_CACHE_DIR)
if (BU_STR_EMPTY(path)) {
confstr(_CS_DARWIN_CACHE_DIR, path, len);
}
#endif

/* method #1c: platform standard (windows) */
/* method #2c: platform standard (windows) */
#ifdef HAVE_WINDOWS_H
if (BU_STR_EMPTY(path)) {
PWSTR wpath;
Expand All @@ -240,15 +248,15 @@ dir_cache(char *buf, size_t len)
}
#endif

/* method 2: fallback to home directory subdir */
/* method 3: fallback to home directory subdir */
if (BU_STR_EMPTY(path)) {
dir_home(temp, MAXPATHLEN);
bu_strlcat(path, temp, MAXPATHLEN);
bu_strlcat(path, DSLASH, MAXPATHLEN);
bu_strlcat(path, ".cache", MAXPATHLEN);
}

/* method 3: fallback to temp directory subdir */
/* method 4: fallback to temp directory subdir */
if (BU_STR_EMPTY(path)) {
dir_temp(temp, MAXPATHLEN);
bu_strlcat(path, temp, MAXPATHLEN);
Expand Down

0 comments on commit 223028e

Please sign in to comment.