diff options
author | Sergey Sharybin <sergey.vfx@gmail.com> | 2016-09-05 17:41:08 +0300 |
---|---|---|
committer | Sergey Sharybin <sergey.vfx@gmail.com> | 2016-09-12 10:39:05 +0300 |
commit | 91e0a16f2f7592b93bd41319e4099f6cfa183a05 (patch) | |
tree | 0adfef206b48a39a24a97ca1aa668a1fdc5d6361 /intern/cycles/util | |
parent | 49df5d0980c3350bdcd34fa33220693f67f49e29 (diff) |
Cycles: Use XDG's .cache folder for cached kernels
Basically just moves cached kernels from ~/.config/blender/BLENDER_VERSION to
~/.cache/cycles/kernels. This has following benefits:
- Follows XDG specification more closely,
not as if it's totally crucial or measurable by users, but still nice.
- Prevents unexpected sizes of config folder, makes disk space used in more
predictable for users way.
- Allows to share kernels across multiple Blender versions,
which makes it easier debugging at the times close to release.
- "Copy Previous Settings" operator will no longer be copying possibly
gigabytes of cached kernels, which used to lead to really nast disk usage
and annoying delays of copying settings.
- In the future we can have some smart logic to clear old unused cached
kernels.
Currently only done for Linux and OSX. Windows still follows old "cache"
folder logic, but it's not really important for now because we don't
support kernel compilation on this platform yet.
Reviewers: dingto, juicyfruit, brecht
Reviewed By: brecht
Differential Revision: https://developer.blender.org/D2197
Diffstat (limited to 'intern/cycles/util')
-rw-r--r-- | intern/cycles/util/util_path.cpp | 37 | ||||
-rw-r--r-- | intern/cycles/util/util_path.h | 1 |
2 files changed, 38 insertions, 0 deletions
diff --git a/intern/cycles/util/util_path.cpp b/intern/cycles/util/util_path.cpp index f23f2cb0168..d515b62d49f 100644 --- a/intern/cycles/util/util_path.cpp +++ b/intern/cycles/util/util_path.cpp @@ -36,6 +36,7 @@ OIIO_NAMESPACE_USING #else # define DIR_SEP '/' # include <dirent.h> +# include <pwd.h> #endif #ifdef HAVE_SHLWAPI_H @@ -63,6 +64,7 @@ typedef struct stat path_stat_t; static string cached_path = ""; static string cached_user_path = ""; +static string cached_xdg_cache_path = ""; namespace { @@ -331,6 +333,23 @@ static char *path_specials(const string& sub) return NULL; } +#if defined(__linux__) || defined(__APPLE__) +static string path_xdg_cache_get() +{ + const char *home = getenv("XDG_CACHE_HOME"); + if(home) { + return string(home); + } + else { + home = getenv("HOME"); + if(home == NULL) { + home = getpwuid(getuid())->pw_dir; + } + return path_join(string(home), ".cache"); + } +} +#endif + void path_init(const string& path, const string& user_path) { cached_path = path; @@ -364,6 +383,24 @@ string path_user_get(const string& sub) return path_join(cached_user_path, sub); } +string path_cache_get(const string& sub) +{ +#if defined(__linux__) || defined(__APPLE__) + if(cached_xdg_cache_path == "") { + cached_xdg_cache_path = path_xdg_cache_get(); + } + string result = path_join(cached_xdg_cache_path, "cycles"); + return path_join(result, sub); +#else + /* TODO(sergey): What that should be on Windows? */ + return path_user_get(path_join("cache", sub)); +#endif +} + +#if defined(__linux__) || defined(__APPLE__) +string path_xdg_home_get(const string& sub = ""); +#endif + string path_filename(const string& path) { size_t index = find_last_slash(path); diff --git a/intern/cycles/util/util_path.h b/intern/cycles/util/util_path.h index c80247f3837..4a89d87cbc6 100644 --- a/intern/cycles/util/util_path.h +++ b/intern/cycles/util/util_path.h @@ -35,6 +35,7 @@ CCL_NAMESPACE_BEGIN void path_init(const string& path = "", const string& user_path = ""); string path_get(const string& sub = ""); string path_user_get(const string& sub = ""); +string path_cache_get(const string& sub = ""); /* path string manipulation */ string path_filename(const string& path); |