static void init_callback()

in src/Linux/local_cache.cpp [198:229]


static void init_callback()
{
    load_cache_locations();
    const std::string application_name("/.az-dcap-client/");
    std::string dirname;
    std::string all_locations;

    // Try the cache locations in order
    for (auto &cache_location : cache_locations)
    {
        if (cache_location != 0 && strcmp(cache_location, "") != 0)
        {
            dirname = cache_location + application_name;
            make_dir(dirname, 0777);
            g_cache_dirname = dirname;
            return;
        }
    }
    
    // Collect all of the environment variables for the error message
    std::string environment_variable_list;
    for (size_t i = 0; i < CACHE_LOCATIONS - 1; ++i)
    {
        environment_variable_list += cache_locations[i];
        if (i != CACHE_LOCATIONS - 2)
        {
            environment_variable_list += ",";
        }
    }

    throw std::runtime_error("No cache location was found. Please define one of the following environment variables to enable caching: " + environment_variable_list);
}