1
0
mirror of https://github.com/moparisthebest/minetest synced 2024-11-15 13:55:11 -05:00

Fix cache path with RUN_IN_PLACE

If an `XDG_CACHE_HOME` can't be found or `RUN_IN_PLACE` is enabled,
`path_cache` is left at its default of `$PATH_USER/cache`
(at a time when `PATH_USER` is `..`), rather than being reset to
`$PATH_USER/cache` after `PATH_USER` has been properly set.
This commit is contained in:
ShadowNinja 2015-12-18 15:42:12 -05:00 committed by sapier
parent cb30facda0
commit 9719aded54

View File

@ -527,6 +527,7 @@ void initializePaths()
path_share = execpath; path_share = execpath;
path_user = execpath; path_user = execpath;
} }
path_cache = path_user + DIR_DELIM + "cache";
#else #else
infostream << "Using system-wide paths (NOT RUN_IN_PLACE)" << std::endl; infostream << "Using system-wide paths (NOT RUN_IN_PLACE)" << std::endl;
@ -536,16 +537,16 @@ void initializePaths()
// Initialize path_cache // Initialize path_cache
// First try $XDG_CACHE_HOME/PROJECT_NAME // First try $XDG_CACHE_HOME/PROJECT_NAME
const char *cache_dir = getenv("XDG_CACHE_HOME"); const char *cache_dir = getenv("XDG_CACHE_HOME");
const char *home_dir = getenv("HOME");
if (cache_dir) { if (cache_dir) {
path_cache = std::string(cache_dir) + DIR_DELIM + PROJECT_NAME; path_cache = std::string(cache_dir) + DIR_DELIM + PROJECT_NAME;
} else { } else if (home_dir) {
// Then try $HOME/.cache/PROJECT_NAME // Then try $HOME/.cache/PROJECT_NAME
const char *home_dir = getenv("HOME"); path_cache = std::string(home_dir) + DIR_DELIM + ".cache"
if (home_dir) { + DIR_DELIM + PROJECT_NAME;
path_cache = std::string(home_dir) + DIR_DELIM + ".cache" } else {
+ DIR_DELIM + PROJECT_NAME; // If neither works, use $PATH_USER/cache
} path_cache = path_user + DIR_DELIM + "cache";
// If neither works, leave it at $PATH_USER/cache
} }
// Migrate cache folder to new location if possible // Migrate cache folder to new location if possible
migrateCachePath(); migrateCachePath();