diff options
author | sfan5 <sfan5@live.de> | 2021-09-19 18:16:53 +0200 |
---|---|---|
committer | sfan5 <sfan5@live.de> | 2021-10-07 00:20:01 +0200 |
commit | 6de8d77e17017cd5cc7b065d42566b6b1cd076cc (patch) | |
tree | 1a6fc291b4df620a4b3c09182b0a69c9b42d2036 /src/script/lua_api | |
parent | 2b5075f0e2a8223cdb07f000b7e8f874416ed3a8 (diff) | |
download | minetest-6de8d77e17017cd5cc7b065d42566b6b1cd076cc.tar.gz minetest-6de8d77e17017cd5cc7b065d42566b6b1cd076cc.tar.bz2 minetest-6de8d77e17017cd5cc7b065d42566b6b1cd076cc.zip |
Move instead of copy during content install if possible
Diffstat (limited to 'src/script/lua_api')
-rw-r--r-- | src/script/lua_api/l_mainmenu.cpp | 30 |
1 files changed, 14 insertions, 16 deletions
diff --git a/src/script/lua_api/l_mainmenu.cpp b/src/script/lua_api/l_mainmenu.cpp index 2a6a9c32d..3d80bdafa 100644 --- a/src/script/lua_api/l_mainmenu.cpp +++ b/src/script/lua_api/l_mainmenu.cpp @@ -606,26 +606,24 @@ int ModApiMainMenu::l_copy_dir(lua_State *L) const char *destination = luaL_checkstring(L, 2); bool keep_source = true; + if (!lua_isnoneornil(L, 3)) + keep_source = readParam<bool>(L, 3); - if ((!lua_isnone(L,3)) && - (!lua_isnil(L,3))) { - keep_source = readParam<bool>(L,3); - } - - std::string absolute_destination = fs::RemoveRelativePathComponents(destination); - std::string absolute_source = fs::RemoveRelativePathComponents(source); - - if ((ModApiMainMenu::mayModifyPath(absolute_destination))) { - bool retval = fs::CopyDir(absolute_source,absolute_destination); - - if (retval && (!keep_source)) { + std::string abs_destination = fs::RemoveRelativePathComponents(destination); + std::string abs_source = fs::RemoveRelativePathComponents(source); - retval &= fs::RecursiveDelete(absolute_source); - } - lua_pushboolean(L,retval); + if (!ModApiMainMenu::mayModifyPath(abs_destination) || + (!keep_source && !ModApiMainMenu::mayModifyPath(abs_source))) { + lua_pushboolean(L, false); return 1; } - lua_pushboolean(L,false); + + bool retval; + if (keep_source) + retval = fs::CopyDir(abs_source, abs_destination); + else + retval = fs::MoveDir(abs_source, abs_destination); + lua_pushboolean(L, retval); return 1; } |