@@ -349,6 +349,49 @@ int ModApiUtil::l_mkdir(lua_State *L)
349349 return 1 ;
350350}
351351
352+ // rmdir(path, recursive)
353+ int ModApiUtil::l_rmdir (lua_State *L)
354+ {
355+ NO_MAP_LOCK_REQUIRED;
356+ const char *path = luaL_checkstring (L, 1 );
357+ CHECK_SECURE_PATH (L, path, true );
358+
359+ bool recursive = readParam<bool >(L, 2 , false );
360+
361+ if (recursive)
362+ lua_pushboolean (L, fs::RecursiveDelete (path));
363+ else
364+ lua_pushboolean (L, fs::DeleteSingleFileOrEmptyDirectory (path));
365+
366+ return 1 ;
367+ }
368+
369+ // cpdir(source, destination)
370+ int ModApiUtil::l_cpdir (lua_State *L)
371+ {
372+ NO_MAP_LOCK_REQUIRED;
373+ const char *source = luaL_checkstring (L, 1 );
374+ const char *destination = luaL_checkstring (L, 2 );
375+ CHECK_SECURE_PATH (L, source, false );
376+ CHECK_SECURE_PATH (L, destination, true );
377+
378+ lua_pushboolean (L, fs::CopyDir (source, destination));
379+ return 1 ;
380+ }
381+
382+ // mpdir(source, destination)
383+ int ModApiUtil::l_mvdir (lua_State *L)
384+ {
385+ NO_MAP_LOCK_REQUIRED;
386+ const char *source = luaL_checkstring (L, 1 );
387+ const char *destination = luaL_checkstring (L, 2 );
388+ CHECK_SECURE_PATH (L, source, true );
389+ CHECK_SECURE_PATH (L, destination, true );
390+
391+ lua_pushboolean (L, fs::MoveDir (source, destination));
392+ return 1 ;
393+ }
394+
352395// get_dir_list(path, is_dir)
353396int ModApiUtil::l_get_dir_list (lua_State *L)
354397{
@@ -588,6 +631,9 @@ void ModApiUtil::Initialize(lua_State *L, int top)
588631 API_FCT (decompress);
589632
590633 API_FCT (mkdir);
634+ API_FCT (rmdir);
635+ API_FCT (cpdir);
636+ API_FCT (mvdir);
591637 API_FCT (get_dir_list);
592638 API_FCT (safe_file_write);
593639
@@ -651,6 +697,9 @@ void ModApiUtil::InitializeAsync(lua_State *L, int top)
651697 API_FCT (decompress);
652698
653699 API_FCT (mkdir);
700+ API_FCT (rmdir);
701+ API_FCT (cpdir);
702+ API_FCT (mvdir);
654703 API_FCT (get_dir_list);
655704
656705 API_FCT (encode_base64);
0 commit comments