diff options
author | rubenwardy <rw@rubenwardy.com> | 2019-01-31 16:35:55 +0000 |
---|---|---|
committer | Paramat <paramat@users.noreply.github.com> | 2019-01-31 16:35:55 +0000 |
commit | 572ba83b3084e3d3abd294acb914746d29822a98 (patch) | |
tree | 2fb0235c3b73cce8bbd80292d7a18c763eb982d2 | |
parent | 944e9f5acbac8971643553eb6e351abe362c4c17 (diff) | |
download | minetest-572ba83b3084e3d3abd294acb914746d29822a98.tar.gz minetest-572ba83b3084e3d3abd294acb914746d29822a98.tar.bz2 minetest-572ba83b3084e3d3abd294acb914746d29822a98.zip |
Content store: Fix storage leak by storing screenshots in cache (#8137)
-rw-r--r-- | builtin/mainmenu/dlg_contentstore.lua | 2 | ||||
-rw-r--r-- | doc/menu_lua_api.txt | 1 | ||||
-rw-r--r-- | src/script/lua_api/l_mainmenu.cpp | 11 | ||||
-rw-r--r-- | src/script/lua_api/l_mainmenu.h | 2 |
4 files changed, 15 insertions, 1 deletions
diff --git a/builtin/mainmenu/dlg_contentstore.lua b/builtin/mainmenu/dlg_contentstore.lua index 0b3cababc..a9164091a 100644 --- a/builtin/mainmenu/dlg_contentstore.lua +++ b/builtin/mainmenu/dlg_contentstore.lua @@ -19,7 +19,7 @@ local store = {} local package_dialog = {} -- Screenshot -local screenshot_dir = os.tempfolder() +local screenshot_dir = core.get_cache_path() .. DIR_DELIM .. "cdb" assert(core.create_dir(screenshot_dir)) local screenshot_downloading = {} local screenshot_downloaded = {} diff --git a/doc/menu_lua_api.txt b/doc/menu_lua_api.txt index c7a215c4f..419bc2f8a 100644 --- a/doc/menu_lua_api.txt +++ b/doc/menu_lua_api.txt @@ -65,6 +65,7 @@ core.get_video_drivers() ^ first element of returned list is guaranteed to be the NULL driver core.get_mapgen_names([include_hidden=false]) -> table of map generator algorithms registered in the core (possible in async calls) +core.get_cache_path() -> path of cache Formspec: core.update_formspec(formspec) diff --git a/src/script/lua_api/l_mainmenu.cpp b/src/script/lua_api/l_mainmenu.cpp index 9b9211593..9a64bd0ab 100644 --- a/src/script/lua_api/l_mainmenu.cpp +++ b/src/script/lua_api/l_mainmenu.cpp @@ -683,6 +683,12 @@ int ModApiMainMenu::l_get_texturepath_share(lua_State *L) return 1; } +int ModApiMainMenu::l_get_cache_path(lua_State *L) +{ + lua_pushstring(L, fs::RemoveRelativePathComponents(porting::path_cache).c_str()); + return 1; +} + /******************************************************************************/ int ModApiMainMenu::l_create_dir(lua_State *L) { const char *path = luaL_checkstring(L, 1); @@ -855,6 +861,9 @@ bool ModApiMainMenu::mayModifyPath(const std::string &path) if (fs::PathStartsWith(path, fs::RemoveRelativePathComponents(porting::path_user + DIR_DELIM "worlds"))) return true; + if (fs::PathStartsWith(path, fs::RemoveRelativePathComponents(porting::path_cache))) + return true; + return false; } @@ -1043,6 +1052,7 @@ void ModApiMainMenu::Initialize(lua_State *L, int top) API_FCT(get_gamepath); API_FCT(get_texturepath); API_FCT(get_texturepath_share); + API_FCT(get_cache_path); API_FCT(create_dir); API_FCT(delete_dir); API_FCT(copy_dir); @@ -1071,6 +1081,7 @@ void ModApiMainMenu::InitializeAsync(lua_State *L, int top) API_FCT(get_gamepath); API_FCT(get_texturepath); API_FCT(get_texturepath_share); + API_FCT(get_cache_path); API_FCT(create_dir); API_FCT(delete_dir); API_FCT(copy_dir); diff --git a/src/script/lua_api/l_mainmenu.h b/src/script/lua_api/l_mainmenu.h index 9e7792197..4a664359a 100644 --- a/src/script/lua_api/l_mainmenu.h +++ b/src/script/lua_api/l_mainmenu.h @@ -120,6 +120,8 @@ private: static int l_get_texturepath_share(lua_State *L); + static int l_get_cache_path(lua_State *L); + static int l_create_dir(lua_State *L); static int l_delete_dir(lua_State *L); |