Skip to content

Commit daae40d

Browse files
committed
FIX: Prevent unnecessary call to remove if recurse is true
1 parent 987e734 commit daae40d

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

ui_api.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1104,7 +1104,7 @@ static int l_RemoveDir(lua_State* L)
11041104
int n = lua_gettop(L);
11051105
ui->LAssert(L, n >= 1, "Usage: l_RemoveDir(path, recurse)");
11061106
ui->LAssert(L, lua_isstring(L, 1), "l_RemoveDir() argument 1: expected string, got %s", luaL_typename(L, 1));
1107-
1107+
11081108
std::filesystem::path path(lua_tostring(L, 1));
11091109
bool recursive = false;
11101110

@@ -1114,7 +1114,10 @@ static int l_RemoveDir(lua_State* L)
11141114
}
11151115

11161116
std::error_code ec;
1117-
if (!is_directory(path, ec) || ec || (recursive && !remove_all(path, ec)) || ec || !remove(path, ec) || ec) {
1117+
if (!is_directory(path, ec) || ec
1118+
|| (recursive && !remove_all(path, ec)) || ec
1119+
|| (!recursive && !remove(path, ec)) || ec)
1120+
{
11181121
lua_pushnil(L);
11191122
lua_pushstring(L, strerror(ec.value()));
11201123
return 2;

0 commit comments

Comments
 (0)