Skip to content

Commit ded522b

Browse files
p-ouelletteSmallJoker
authored andcommittedJan 26, 2019
Fix pkgmgr game install with RUN_IN_PLACE=0 (#8113)
1 parent 922e6ff commit ded522b

File tree

2 files changed

+15
-19
lines changed

2 files changed

+15
-19
lines changed
 

Diff for: ‎src/script/lua_api/l_mainmenu.cpp

+11-16
Original file line numberDiff line numberDiff line change
@@ -687,7 +687,7 @@ int ModApiMainMenu::l_get_texturepath_share(lua_State *L)
687687
int ModApiMainMenu::l_create_dir(lua_State *L) {
688688
const char *path = luaL_checkstring(L, 1);
689689

690-
if (ModApiMainMenu::isMinetestPath(path)) {
690+
if (ModApiMainMenu::mayModifyPath(path)) {
691691
lua_pushboolean(L, fs::CreateAllDirs(path));
692692
return 1;
693693
}
@@ -703,7 +703,7 @@ int ModApiMainMenu::l_delete_dir(lua_State *L)
703703

704704
std::string absolute_path = fs::RemoveRelativePathComponents(path);
705705

706-
if (ModApiMainMenu::isMinetestPath(absolute_path)) {
706+
if (ModApiMainMenu::mayModifyPath(absolute_path)) {
707707
lua_pushboolean(L, fs::RecursiveDelete(absolute_path));
708708
return 1;
709709
}
@@ -728,7 +728,7 @@ int ModApiMainMenu::l_copy_dir(lua_State *L)
728728
std::string absolute_destination = fs::RemoveRelativePathComponents(destination);
729729
std::string absolute_source = fs::RemoveRelativePathComponents(source);
730730

731-
if ((ModApiMainMenu::isMinetestPath(absolute_destination))) {
731+
if ((ModApiMainMenu::mayModifyPath(absolute_destination))) {
732732
bool retval = fs::CopyDir(absolute_source,absolute_destination);
733733

734734
if (retval && (!keep_source)) {
@@ -750,7 +750,7 @@ int ModApiMainMenu::l_extract_zip(lua_State *L)
750750

751751
std::string absolute_destination = fs::RemoveRelativePathComponents(destination);
752752

753-
if (ModApiMainMenu::isMinetestPath(absolute_destination)) {
753+
if (ModApiMainMenu::mayModifyPath(absolute_destination)) {
754754
fs::CreateAllDirs(absolute_destination);
755755

756756
io::IFileSystem *fs = RenderingEngine::get_filesystem();
@@ -838,28 +838,23 @@ int ModApiMainMenu::l_get_mainmenu_path(lua_State *L)
838838
}
839839

840840
/******************************************************************************/
841-
bool ModApiMainMenu::isMinetestPath(std::string path)
841+
bool ModApiMainMenu::mayModifyPath(const std::string &path)
842842
{
843-
if (fs::PathStartsWith(path,fs::TempPath()))
843+
if (fs::PathStartsWith(path, fs::TempPath()))
844844
return true;
845845

846-
/* games */
847-
if (fs::PathStartsWith(path,fs::RemoveRelativePathComponents(porting::path_share + DIR_DELIM + "games")))
846+
if (fs::PathStartsWith(path, fs::RemoveRelativePathComponents(porting::path_user + DIR_DELIM "games")))
848847
return true;
849848

850-
/* mods */
851-
if (fs::PathStartsWith(path,fs::RemoveRelativePathComponents(porting::path_user + DIR_DELIM + "mods")))
849+
if (fs::PathStartsWith(path, fs::RemoveRelativePathComponents(porting::path_user + DIR_DELIM "mods")))
852850
return true;
853851

854-
/* mods */
855-
if (fs::PathStartsWith(path,fs::RemoveRelativePathComponents(porting::path_user + DIR_DELIM + "textures")))
852+
if (fs::PathStartsWith(path, fs::RemoveRelativePathComponents(porting::path_user + DIR_DELIM "textures")))
856853
return true;
857854

858-
/* worlds */
859-
if (fs::PathStartsWith(path,fs::RemoveRelativePathComponents(porting::path_user + DIR_DELIM + "worlds")))
855+
if (fs::PathStartsWith(path, fs::RemoveRelativePathComponents(porting::path_user + DIR_DELIM "worlds")))
860856
return true;
861857

862-
863858
return false;
864859
}
865860

@@ -895,7 +890,7 @@ int ModApiMainMenu::l_download_file(lua_State *L)
895890
//check path
896891
std::string absolute_destination = fs::RemoveRelativePathComponents(target);
897892

898-
if (ModApiMainMenu::isMinetestPath(absolute_destination)) {
893+
if (ModApiMainMenu::mayModifyPath(absolute_destination)) {
899894
if (GUIEngine::downloadFile(url,absolute_destination)) {
900895
lua_pushboolean(L,true);
901896
return 1;

Diff for: ‎src/script/lua_api/l_mainmenu.h

+4-3
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,12 @@ class ModApiMainMenu: public ModApiBase
5353
static int getBoolData(lua_State *L, std::string name,bool& valid);
5454

5555
/**
56-
* check if a path is within some of minetests folders
56+
* Checks if a path may be modified. Paths in the temp directory or the user
57+
* games, mods, textures, or worlds directories may be modified.
5758
* @param path path to check
58-
* @return true/false
59+
* @return true if the path may be modified
5960
*/
60-
static bool isMinetestPath(std::string path);
61+
static bool mayModifyPath(const std::string &path);
6162

6263
//api calls
6364

0 commit comments

Comments
 (0)
Please sign in to comment.