Skip to content

Commit d9f2c49

Browse files
committed
Refactor cache file location retrieval to use namespaced function and enhance documentation
1 parent 8bdaa4a commit d9f2c49

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

src/scitokens.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1145,10 +1145,7 @@ int scitoken_config_get_str(const char *key, char **output, char **err_msg) {
11451145
return 0;
11461146
}
11471147

1148-
// Forward declaration of get_cache_file from scitokens_cache.cpp
1149-
extern std::string get_cache_file();
1150-
11511148
const char* scitokens_get_cache_file_location() {
1152-
static std::string cache_location = get_cache_file();
1149+
static std::string cache_location = scitokens::get_cache_file();
11531150
return cache_location.c_str();
11541151
}

src/scitokens_cache.cpp

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,23 @@ int remove_issuer_entry(sqlite3 *db, const std::string &issuer,
9292

9393
} // namespace
9494

95-
// Expose get_cache_file function for use by scitokens-keycache tool
96-
std::string get_cache_file() {
95+
/**
96+
* @brief Determines the location of the SciTokens key cache file.
97+
*
98+
* This function checks environment variables and configuration settings to find
99+
* the appropriate directory for the key cache file. It prioritizes the following:
100+
* 1. SCITOKENS_KEYCACHE_FILE environment variable (direct file path).
101+
* 2. Configured cache directory via Configuration::get_cache_home().
102+
* 3. XDG_CACHE_HOME environment variable.
103+
* 4. Default to $HOME/.cache if none of the above are set.
104+
*
105+
* The function ensures the cache directory exists, creates it if necessary,
106+
* initializes the SQLite database if needed, and returns the full path to the
107+
* cache file. Returns an empty string on failure.
108+
*
109+
* @return std::string Full path to the key cache file, or empty string on error.
110+
*/
111+
std::string scitokens::get_cache_file() {
97112
// Check for direct cache file location first (offline support)
98113
const char *direct_cache_file = getenv("SCITOKENS_KEYCACHE_FILE");
99114
if (direct_cache_file && strlen(direct_cache_file) > 0) {

0 commit comments

Comments
 (0)