Commit a974da19 authored by Alessio Netti's avatar Alessio Netti

Fall back to /tmp/ dir if $HOME/.cache cannot be used for sensor cache

parent 1ba44cea
......@@ -1951,23 +1951,30 @@ SCError SensorConfigImpl::findSensorCachePath(std::string &path) {
_clusterName = "";
return SC_UNKNOWNERROR;
}
// Retrieving home dir
if((homeDir = getenv("HOME")) == "") {
return SC_PATHERROR;
}
path = homeDir + "/.cache/";
// Cache dir does not exist - we create it
if(access(path.c_str(), F_OK) != 0 && mkdir(path.c_str(), 0700) != 0) {
path = "";
return SC_PATHERROR;
}
try {
// Retrieving home dir
if ((homeDir = getenv("HOME")) == "") {
throw std::domain_error("Home directory is not defined!");
}
path = homeDir + "/.cache/";
// Cache dir does not exist - we create it
if (access(path.c_str(), F_OK) != 0 && mkdir(path.c_str(), 0700) != 0) {
throw std::domain_error("Cache directory cannot be accessed!");
}
// Cache dir exists but it is not accessible
if(access(path.c_str(), W_OK) != 0) {
path = "";
return SC_PATHERROR;
// Cache dir exists but it is not writeable
if (access(path.c_str(), W_OK) != 0) {
throw std::runtime_error("Cache directory is not writeable!");
}
} catch(const std::domain_error& e) {
path = "/tmp/";
// Tmp dir exists but it is not writeable
if (access(path.c_str(), W_OK) != 0) {
path = "";
return SC_PATHERROR;
}
}
path += std::string(SENSOR_CACHE_FILENAME) + _clusterName;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment