Skip to content
Merged
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
4 changes: 3 additions & 1 deletion include/luxrays/utils/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@
namespace luxrays {

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

extern std::filesystem::path GetCacheDir();


}

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

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

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

return "";
}

std::filesystem::path GetCacheDir() {

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

// XDG standard says XDG_CACHE_HOME is unset by default.
std::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.
std::filesystem::path home = GetEnvPath("HOME");

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

std::filesystem::path kernelConfigDir = xdgCacheHome / "luxcorerender.org";
#elif defined(__APPLE__)
// std::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 @@ -136,7 +136,7 @@ bool cudaKernelCache::ForcedCompilePTX(const vector<string> &kernelsParameters,
//------------------------------------------------------------------------------

std::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
//------------------------------------------------------------------------------

std::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