Skip to content

Commit 572ba83

Browse files
rubenwardyparamat
authored andcommitted
Content store: Fix storage leak by storing screenshots in cache (#8137)
1 parent 944e9f5 commit 572ba83

File tree

4 files changed

+15
-1
lines changed

4 files changed

+15
-1
lines changed

builtin/mainmenu/dlg_contentstore.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ local store = {}
1919
local package_dialog = {}
2020

2121
-- Screenshot
22-
local screenshot_dir = os.tempfolder()
22+
local screenshot_dir = core.get_cache_path() .. DIR_DELIM .. "cdb"
2323
assert(core.create_dir(screenshot_dir))
2424
local screenshot_downloading = {}
2525
local screenshot_downloaded = {}

doc/menu_lua_api.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ core.get_video_drivers()
6565
^ first element of returned list is guaranteed to be the NULL driver
6666
core.get_mapgen_names([include_hidden=false]) -> table of map generator algorithms
6767
registered in the core (possible in async calls)
68+
core.get_cache_path() -> path of cache
6869

6970
Formspec:
7071
core.update_formspec(formspec)

src/script/lua_api/l_mainmenu.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -683,6 +683,12 @@ int ModApiMainMenu::l_get_texturepath_share(lua_State *L)
683683
return 1;
684684
}
685685

686+
int ModApiMainMenu::l_get_cache_path(lua_State *L)
687+
{
688+
lua_pushstring(L, fs::RemoveRelativePathComponents(porting::path_cache).c_str());
689+
return 1;
690+
}
691+
686692
/******************************************************************************/
687693
int ModApiMainMenu::l_create_dir(lua_State *L) {
688694
const char *path = luaL_checkstring(L, 1);
@@ -855,6 +861,9 @@ bool ModApiMainMenu::mayModifyPath(const std::string &path)
855861
if (fs::PathStartsWith(path, fs::RemoveRelativePathComponents(porting::path_user + DIR_DELIM "worlds")))
856862
return true;
857863

864+
if (fs::PathStartsWith(path, fs::RemoveRelativePathComponents(porting::path_cache)))
865+
return true;
866+
858867
return false;
859868
}
860869

@@ -1043,6 +1052,7 @@ void ModApiMainMenu::Initialize(lua_State *L, int top)
10431052
API_FCT(get_gamepath);
10441053
API_FCT(get_texturepath);
10451054
API_FCT(get_texturepath_share);
1055+
API_FCT(get_cache_path);
10461056
API_FCT(create_dir);
10471057
API_FCT(delete_dir);
10481058
API_FCT(copy_dir);
@@ -1071,6 +1081,7 @@ void ModApiMainMenu::InitializeAsync(lua_State *L, int top)
10711081
API_FCT(get_gamepath);
10721082
API_FCT(get_texturepath);
10731083
API_FCT(get_texturepath_share);
1084+
API_FCT(get_cache_path);
10741085
API_FCT(create_dir);
10751086
API_FCT(delete_dir);
10761087
API_FCT(copy_dir);

src/script/lua_api/l_mainmenu.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,8 @@ class ModApiMainMenu: public ModApiBase
120120

121121
static int l_get_texturepath_share(lua_State *L);
122122

123+
static int l_get_cache_path(lua_State *L);
124+
123125
static int l_create_dir(lua_State *L);
124126

125127
static int l_delete_dir(lua_State *L);

0 commit comments

Comments
 (0)