summaryrefslogtreecommitdiff
path: root/src/porting.cpp
diff options
context:
space:
mode:
authorShadowNinja <shadowninja@minetest.net>2015-08-24 17:00:06 -0400
committerShadowNinja <shadowninja@minetest.net>2015-12-07 13:51:41 -0500
commitea2964f5a168cb52d1b9f74a08f00c7c068c6649 (patch)
tree77785296ca680eced53d3c3e976a5dc948d5df30 /src/porting.cpp
parent51e8c2b27786c050f0271eeeaed5eea17d62f0a0 (diff)
downloadminetest-ea2964f5a168cb52d1b9f74a08f00c7c068c6649.tar.gz
minetest-ea2964f5a168cb52d1b9f74a08f00c7c068c6649.tar.bz2
minetest-ea2964f5a168cb52d1b9f74a08f00c7c068c6649.zip
Add seperate cache path
This is set to the XDG cache path where possible. It's set to the app's cache path on Android.
Diffstat (limited to 'src/porting.cpp')
-rw-r--r--src/porting.cpp38
1 files changed, 37 insertions, 1 deletions
diff --git a/src/porting.cpp b/src/porting.cpp
index 3e39fc813..4a72e90fd 100644
--- a/src/porting.cpp
+++ b/src/porting.cpp
@@ -139,6 +139,7 @@ void signal_handler_init(void)
std::string path_share = "..";
std::string path_user = "..";
std::string path_locale = path_share + DIR_DELIM + "locale";
+std::string path_cache = path_user + DIR_DELIM + "cache";
std::string getDataPath(const char *subpath)
@@ -463,6 +464,25 @@ bool setSystemPaths()
#endif
+void migrateCachePath()
+{
+ const std::string local_cache_path = path_user + DIR_DELIM + "cache";
+
+ // Delete tmp folder if it exists (it only ever contained
+ // a temporary ogg file, which is no longer used).
+ if (fs::PathExists(local_cache_path + DIR_DELIM + "tmp"))
+ fs::RecursiveDelete(local_cache_path + DIR_DELIM + "tmp");
+
+ // Bail if migration impossible
+ if (path_cache == local_cache_path || !fs::PathExists(local_cache_path)
+ || fs::PathExists(path_cache)) {
+ return;
+ }
+ if (!fs::Rename(local_cache_path, path_cache)) {
+ errorstream << "Failed to migrate local cache path "
+ "to system path!" << std::endl;
+ }
+}
void initializePaths()
{
@@ -513,10 +533,27 @@ void initializePaths()
if (!setSystemPaths())
errorstream << "Failed to get one or more system-wide path" << std::endl;
+ // Initialize path_cache
+ // First try $XDG_CACHE_HOME/PROJECT_NAME
+ const char *cache_dir = getenv("XDG_CACHE_HOME");
+ if (cache_dir) {
+ path_cache = std::string(cache_dir) + DIR_DELIM + PROJECT_NAME;
+ } else {
+ // 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
+ }
+ // Migrate cache folder to new location if possible
+ migrateCachePath();
#endif
infostream << "Detected share path: " << path_share << std::endl;
infostream << "Detected user path: " << path_user << std::endl;
+ infostream << "Detected cache path: " << path_cache << std::endl;
bool found_localedir = false;
#ifdef STATIC_LOCALEDIR
@@ -542,7 +579,6 @@ void initializePaths()
if (!found_localedir) {
errorstream << "Couldn't find a locale directory!" << std::endl;
}
-
}