From 1ac88d2b07043fff092b1d8d757ab391e59a057d Mon Sep 17 00:00:00 2001 From: ruki Date: Wed, 31 Aug 2022 00:47:29 +0800 Subject: improve os.islink --- core/src/tbox/tbox | 2 +- core/src/xmake/os/isdir.c | 4 +--- core/src/xmake/os/isfile.c | 4 +--- core/src/xmake/os/islink.c | 13 ++----------- 4 files changed, 5 insertions(+), 18 deletions(-) (limited to 'core/src') diff --git a/core/src/tbox/tbox b/core/src/tbox/tbox index c21437c8a..96ed09414 160000 --- a/core/src/tbox/tbox +++ b/core/src/tbox/tbox @@ -1 +1 @@ -Subproject commit c21437c8af85bf686d4bf44a9664d05c117a1ecf +Subproject commit 96ed094143923dacafaec6eed10fc34e1106edc2 diff --git a/core/src/xmake/os/isdir.c b/core/src/xmake/os/isdir.c index 850823a31..c49860581 100644 --- a/core/src/xmake/os/isdir.c +++ b/core/src/xmake/os/isdir.c @@ -42,10 +42,8 @@ tb_int_t xm_os_isdir(lua_State* lua) tb_char_t const* path = luaL_checkstring(lua, 1); tb_check_return_val(path, 0); - // done os.isdir(path) + // is directory? tb_file_info_t info = {0}; lua_pushboolean(lua, tb_file_info(path, &info) && (info.type == TB_FILE_TYPE_DIRECTORY)); - - // ok return 1; } diff --git a/core/src/xmake/os/isfile.c b/core/src/xmake/os/isfile.c index 85e616828..bfc162d74 100644 --- a/core/src/xmake/os/isfile.c +++ b/core/src/xmake/os/isfile.c @@ -42,10 +42,8 @@ tb_int_t xm_os_isfile(lua_State* lua) tb_char_t const* path = luaL_checkstring(lua, 1); tb_check_return_val(path, 0); - // done os.isfile(path) + // is file? tb_file_info_t info = {0}; lua_pushboolean(lua, tb_file_info(path, &info) && (info.type == TB_FILE_TYPE_FILE)); - - // ok return 1; } diff --git a/core/src/xmake/os/islink.c b/core/src/xmake/os/islink.c index c7fec236e..d70681cb5 100644 --- a/core/src/xmake/os/islink.c +++ b/core/src/xmake/os/islink.c @@ -46,16 +46,7 @@ tb_int_t xm_os_islink(lua_State* lua) tb_check_return_val(path, 0); // is link? -#if defined(TB_CONFIG_OS_WINDOWS) - lua_pushboolean(lua, tb_false); -#elif defined(TB_CONFIG_POSIX_HAVE_STAT64) - struct stat64 st = {0}; - lua_pushboolean(lua, !lstat64(path, &st) && S_ISLNK(st.st_mode)); -#else - struct stat st = {0}; - lua_pushboolean(lua, !lstat(path, &st) && S_ISLNK(st.st_mode)); -#endif - - // ok + tb_file_info_t info = {0}; + lua_pushboolean(lua, tb_file_info(path, &info) && (info.flags & TB_FILE_FLAG_LINK)); return 1; } -- cgit v1.3.1