Skip to content

Commit 9f19b7d

Browse files
numberZeronerzhul
authored andcommittedJun 30, 2018
Fix world deletion (#7494)
* Fix world deletion
1 parent f3b7be9 commit 9f19b7d

File tree

1 file changed

+9
-22
lines changed

1 file changed

+9
-22
lines changed
 

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

+9-22
Original file line numberDiff line numberDiff line change
@@ -594,31 +594,18 @@ int ModApiMainMenu::l_create_world(lua_State *L)
594594
/******************************************************************************/
595595
int ModApiMainMenu::l_delete_world(lua_State *L)
596596
{
597-
int worldidx = luaL_checkinteger(L,1) -1;
598-
597+
int world_id = luaL_checkinteger(L, 1) - 1;
599598
std::vector<WorldSpec> worlds = getAvailableWorlds();
600-
601-
if ((worldidx >= 0) &&
602-
(worldidx < (int) worlds.size())) {
603-
604-
WorldSpec spec = worlds[worldidx];
605-
606-
std::vector<std::string> paths;
607-
paths.push_back(spec.path);
608-
fs::GetRecursiveSubPaths(spec.path, paths, true);
609-
610-
// Delete files
611-
if (!fs::DeletePaths(paths)) {
612-
lua_pushstring(L, "Failed to delete world");
613-
}
614-
else {
615-
lua_pushnil(L);
616-
}
617-
}
618-
else {
599+
if (world_id < 0 || world_id >= (int) worlds.size()) {
619600
lua_pushstring(L, "Invalid world index");
601+
return 1;
620602
}
621-
return 1;
603+
const WorldSpec &spec = worlds[world_id];
604+
if (!fs::RecursiveDelete(spec.path)) {
605+
lua_pushstring(L, "Failed to delete world");
606+
return 1;
607+
}
608+
return 0;
622609
}
623610

624611
/******************************************************************************/

0 commit comments

Comments
 (0)