]> git.lizzy.rs Git - minetest.git/commitdiff
Fix pkgmgr game install with RUN_IN_PLACE=0 (#8113)
authorPaul Ouellette <oue.paul18@gmail.com>
Sat, 26 Jan 2019 13:12:20 +0000 (08:12 -0500)
committerSmallJoker <SmallJoker@users.noreply.github.com>
Sat, 26 Jan 2019 13:12:20 +0000 (14:12 +0100)
src/script/lua_api/l_mainmenu.cpp
src/script/lua_api/l_mainmenu.h

index 145ff0970c0f119d96ce5dd0a5b32c9406f1e662..9b9211593f98136be28b988eb40181600aebabeb 100644 (file)
@@ -687,7 +687,7 @@ int ModApiMainMenu::l_get_texturepath_share(lua_State *L)
 int ModApiMainMenu::l_create_dir(lua_State *L) {
        const char *path = luaL_checkstring(L, 1);
 
-       if (ModApiMainMenu::isMinetestPath(path)) {
+       if (ModApiMainMenu::mayModifyPath(path)) {
                lua_pushboolean(L, fs::CreateAllDirs(path));
                return 1;
        }
@@ -703,7 +703,7 @@ int ModApiMainMenu::l_delete_dir(lua_State *L)
 
        std::string absolute_path = fs::RemoveRelativePathComponents(path);
 
-       if (ModApiMainMenu::isMinetestPath(absolute_path)) {
+       if (ModApiMainMenu::mayModifyPath(absolute_path)) {
                lua_pushboolean(L, fs::RecursiveDelete(absolute_path));
                return 1;
        }
@@ -728,7 +728,7 @@ int ModApiMainMenu::l_copy_dir(lua_State *L)
        std::string absolute_destination = fs::RemoveRelativePathComponents(destination);
        std::string absolute_source = fs::RemoveRelativePathComponents(source);
 
-       if ((ModApiMainMenu::isMinetestPath(absolute_destination))) {
+       if ((ModApiMainMenu::mayModifyPath(absolute_destination))) {
                bool retval = fs::CopyDir(absolute_source,absolute_destination);
 
                if (retval && (!keep_source)) {
@@ -750,7 +750,7 @@ int ModApiMainMenu::l_extract_zip(lua_State *L)
 
        std::string absolute_destination = fs::RemoveRelativePathComponents(destination);
 
-       if (ModApiMainMenu::isMinetestPath(absolute_destination)) {
+       if (ModApiMainMenu::mayModifyPath(absolute_destination)) {
                fs::CreateAllDirs(absolute_destination);
 
                io::IFileSystem *fs = RenderingEngine::get_filesystem();
@@ -838,28 +838,23 @@ int ModApiMainMenu::l_get_mainmenu_path(lua_State *L)
 }
 
 /******************************************************************************/
-bool ModApiMainMenu::isMinetestPath(std::string path)
+bool ModApiMainMenu::mayModifyPath(const std::string &path)
 {
-       if (fs::PathStartsWith(path,fs::TempPath()))
+       if (fs::PathStartsWith(path, fs::TempPath()))
                return true;
 
-       /* games */
-       if (fs::PathStartsWith(path,fs::RemoveRelativePathComponents(porting::path_share + DIR_DELIM + "games")))
+       if (fs::PathStartsWith(path, fs::RemoveRelativePathComponents(porting::path_user + DIR_DELIM "games")))
                return true;
 
-       /* mods */
-       if (fs::PathStartsWith(path,fs::RemoveRelativePathComponents(porting::path_user + DIR_DELIM + "mods")))
+       if (fs::PathStartsWith(path, fs::RemoveRelativePathComponents(porting::path_user + DIR_DELIM "mods")))
                return true;
 
-       /* mods */
-       if (fs::PathStartsWith(path,fs::RemoveRelativePathComponents(porting::path_user + DIR_DELIM + "textures")))
+       if (fs::PathStartsWith(path, fs::RemoveRelativePathComponents(porting::path_user + DIR_DELIM "textures")))
                return true;
 
-       /* worlds */
-       if (fs::PathStartsWith(path,fs::RemoveRelativePathComponents(porting::path_user + DIR_DELIM + "worlds")))
+       if (fs::PathStartsWith(path, fs::RemoveRelativePathComponents(porting::path_user + DIR_DELIM "worlds")))
                return true;
 
-
        return false;
 }
 
@@ -895,7 +890,7 @@ int ModApiMainMenu::l_download_file(lua_State *L)
        //check path
        std::string absolute_destination = fs::RemoveRelativePathComponents(target);
 
-       if (ModApiMainMenu::isMinetestPath(absolute_destination)) {
+       if (ModApiMainMenu::mayModifyPath(absolute_destination)) {
                if (GUIEngine::downloadFile(url,absolute_destination)) {
                        lua_pushboolean(L,true);
                        return 1;
index ae68edccf142b0153b53cb0faa32d0155ee06762..9e77921974068ed57f9c38aaf53d28e0f602ac2e 100644 (file)
@@ -53,11 +53,12 @@ class ModApiMainMenu: public ModApiBase
        static int getBoolData(lua_State *L, std::string name,bool& valid);
 
        /**
-        * check if a path is within some of minetests folders
+        * Checks if a path may be modified. Paths in the temp directory or the user
+        * games, mods, textures, or worlds directories may be modified.
         * @param path path to check
-        * @return true/false
+        * @return true if the path may be modified
         */
-       static bool isMinetestPath(std::string path);
+       static bool mayModifyPath(const std::string &path);
 
        //api calls