Fix cache path with RUN_IN_PLACE
authorShadowNinja <shadowninja@minetest.net>
Fri, 18 Dec 2015 20:42:12 +0000 (15:42 -0500)
committersapier <sapier AT gmx dot net>
Tue, 29 Dec 2015 23:14:30 +0000 (00:14 +0100)
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.

src/porting.cpp

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