Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

luxrays: rename GetConfigDir as GetCacheDir and use XDG_CACHE_HOME according to specifications #615

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/luxrays/utils/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
namespace luxrays {

extern std::string SanitizeFileName(const std::string &name);
extern boost::filesystem::path GetConfigDir();
extern boost::filesystem::path GetCacheDir();

}

Expand Down
32 changes: 29 additions & 3 deletions src/luxrays/utils/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,38 @@ string SanitizeFileName(const string &name) {
return sanitizedName;
}

boost::filesystem::path GetConfigDir() {
boost::filesystem::path GetEnvPath(const string &name) {
char *path = getenv(name.c_str());

if (path && path[0]) {
return boost::filesystem::path(path);
}

return "";
}

boost::filesystem::path GetCacheDir() {
#if defined(__linux__)
// boost::filesystem::temp_directory_path() is usually mapped to /tmp and
// the content of the directory is often deleted at each reboot
boost::filesystem::path kernelConfigDir = getenv("HOME");
kernelConfigDir = kernelConfigDir / ".config" / "luxcorerender.org";

// XDG standard says XDG_CACHE_HOME is unset by default.
boost::filesystem::path xdgCacheHome = GetEnvPath("XDG_CACHE_HOME");

if (!xdgCacheHome.size()) {
// HOME should never be unset, but we better not want to
// crash if that happens.
boost::filesystem::path home = GetEnvPath("HOME");

if (home.size()) {
xdgCacheHome = home / ".config";
}
else {
xdgCacheHome = boost::filesystem::temp_directory_path();
}
}

boost::filesystem::path kernelConfigDir = xdgCacheHome / "luxcorerender.org";
#elif defined(__APPLE__)
// boost::filesystem::temp_directory_path() is usually mapped to /tmp and
// the content of the directory is deleted at each reboot on MacOS
Expand Down
2 changes: 1 addition & 1 deletion src/luxrays/utils/cuda.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ bool cudaKernelCache::ForcedCompilePTX(const vector<string> &kernelsParameters,
//------------------------------------------------------------------------------

boost::filesystem::path cudaKernelPersistentCache::GetCacheDir(const string &applicationName) {
return GetConfigDir() / "cuda_kernel_cache" / SanitizeFileName(applicationName);
return luxrays::GetCacheDir() / "cuda_kernel_cache" / SanitizeFileName(applicationName);
}

cudaKernelPersistentCache::cudaKernelPersistentCache(const string &applicationName) {
Expand Down
2 changes: 1 addition & 1 deletion src/luxrays/utils/ocl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ cl_program oclKernelCache::ForcedCompile(cl_context context, cl_device_id device
//------------------------------------------------------------------------------

boost::filesystem::path oclKernelPersistentCache::GetCacheDir(const string &applicationName) {
return GetConfigDir() / "ocl_kernel_cache" / SanitizeFileName(applicationName);
return luxrays::GetCacheDir() / "ocl_kernel_cache" / SanitizeFileName(applicationName);
}

oclKernelPersistentCache::oclKernelPersistentCache(const string &applicationName) {
Expand Down