Fix world deletion (#7494)
authorVitaliy <silverunicorn2011@yandex.ru>
Sat, 30 Jun 2018 13:13:53 +0000 (16:13 +0300)
committerLoïc Blot <nerzhul@users.noreply.github.com>
Sat, 30 Jun 2018 13:13:53 +0000 (15:13 +0200)
* Fix world deletion

src/script/lua_api/l_mainmenu.cpp

index a5b211bc7b94992663e1de27532523f8d5d82d38..238e3e32f0b669e868fbc1a19598a220cbd79a24 100644 (file)
@@ -594,31 +594,18 @@ int ModApiMainMenu::l_create_world(lua_State *L)
 /******************************************************************************/
 int ModApiMainMenu::l_delete_world(lua_State *L)
 {
-       int worldidx    = luaL_checkinteger(L,1) -1;
-
+       int world_id = luaL_checkinteger(L, 1) - 1;
        std::vector<WorldSpec> worlds = getAvailableWorlds();
-
-       if ((worldidx >= 0) &&
-               (worldidx < (int) worlds.size())) {
-
-               WorldSpec spec = worlds[worldidx];
-
-               std::vector<std::string> paths;
-               paths.push_back(spec.path);
-               fs::GetRecursiveSubPaths(spec.path, paths, true);
-
-               // Delete files
-               if (!fs::DeletePaths(paths)) {
-                       lua_pushstring(L, "Failed to delete world");
-               }
-               else {
-                       lua_pushnil(L);
-               }
-       }
-       else {
+       if (world_id < 0 || world_id >= (int) worlds.size()) {
                lua_pushstring(L, "Invalid world index");
+               return 1;
        }
-       return 1;
+       const WorldSpec &spec = worlds[world_id];
+       if (!fs::RecursiveDelete(spec.path)) {
+               lua_pushstring(L, "Failed to delete world");
+               return 1;
+       }
+       return 0;
 }
 
 /******************************************************************************/