aboutsummaryrefslogtreecommitdiff
path: root/src/script/lua_api
diff options
context:
space:
mode:
authorVitaliy <silverunicorn2011@yandex.ru>2018-06-30 16:13:53 +0300
committerLoïc Blot <nerzhul@users.noreply.github.com>2018-06-30 15:13:53 +0200
commit9f19b7d9367c5dc2758a9d4690b091b745fc821d (patch)
tree75c28235f5bcdf59a9860eb0c5ad23064d3148f6 /src/script/lua_api
parentf3b7be97feb5f1de8f31c1841cb7fdd3d89ac451 (diff)
downloadminetest-9f19b7d9367c5dc2758a9d4690b091b745fc821d.tar.gz
minetest-9f19b7d9367c5dc2758a9d4690b091b745fc821d.tar.bz2
minetest-9f19b7d9367c5dc2758a9d4690b091b745fc821d.zip
Fix world deletion (#7494)
* Fix world deletion
Diffstat (limited to 'src/script/lua_api')
-rw-r--r--src/script/lua_api/l_mainmenu.cpp31
1 files changed, 9 insertions, 22 deletions
diff --git a/src/script/lua_api/l_mainmenu.cpp b/src/script/lua_api/l_mainmenu.cpp
index a5b211bc7..238e3e32f 100644
--- a/src/script/lua_api/l_mainmenu.cpp
+++ b/src/script/lua_api/l_mainmenu.cpp
@@ -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;
}
/******************************************************************************/