From 8c11d185b753f7c53439929aa91f04edba772836 Mon Sep 17 00:00:00 2001 From: ruki Date: Wed, 31 Aug 2022 00:50:27 +0800 Subject: improve symlink --- core/src/xmake/os/islink.c | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) (limited to 'core/src') diff --git a/core/src/xmake/os/islink.c b/core/src/xmake/os/islink.c index c7fec236e..b5662c369 100644 --- a/core/src/xmake/os/islink.c +++ b/core/src/xmake/os/islink.c @@ -29,9 +29,6 @@ * includes */ #include "prefix.h" -#ifndef TB_CONFIG_OS_WINDOWS -# include -#endif /* ////////////////////////////////////////////////////////////////////////////////////// * implementation @@ -46,16 +43,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 From 6182a9eb658e5687fd60be57c65f4360926925e8 Mon Sep 17 00:00:00 2001 From: ruki Date: Wed, 31 Aug 2022 00:55:15 +0800 Subject: update tbox --- core/src/tbox/tbox | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'core/src') diff --git a/core/src/tbox/tbox b/core/src/tbox/tbox index 96ed09414..c759c36f8 160000 --- a/core/src/tbox/tbox +++ b/core/src/tbox/tbox @@ -1 +1 @@ -Subproject commit 96ed094143923dacafaec6eed10fc34e1106edc2 +Subproject commit c759c36f80ce61be8e1f5e284951cd1aeacdb8a1 -- cgit v1.3.1 From 971ed5cf931f31b3d86919667f8469a1be31dbfd Mon Sep 17 00:00:00 2001 From: ruki Date: Wed, 31 Aug 2022 00:56:57 +0800 Subject: fix config --- core/src/tbox/inc/linux/tbox.config.h | 1 + core/src/tbox/inc/macosx/tbox.config.h | 1 + 2 files changed, 2 insertions(+) (limited to 'core/src') diff --git a/core/src/tbox/inc/linux/tbox.config.h b/core/src/tbox/inc/linux/tbox.config.h index b2977ecbb..a1986b4be 100755 --- a/core/src/tbox/inc/linux/tbox.config.h +++ b/core/src/tbox/inc/linux/tbox.config.h @@ -148,6 +148,7 @@ #define TB_CONFIG_POSIX_HAVE_DLOPEN 1 #define TB_CONFIG_POSIX_HAVE_OPEN 1 #define TB_CONFIG_POSIX_HAVE_STAT64 1 +#define TB_CONFIG_POSIX_HAVE_LSTAT64 1 #define TB_CONFIG_POSIX_HAVE_GETHOSTNAME 1 #define TB_CONFIG_POSIX_HAVE_GETIFADDRS 1 #define TB_CONFIG_POSIX_HAVE_SEM_INIT 1 diff --git a/core/src/tbox/inc/macosx/tbox.config.h b/core/src/tbox/inc/macosx/tbox.config.h index 261b82b29..59abf4acf 100755 --- a/core/src/tbox/inc/macosx/tbox.config.h +++ b/core/src/tbox/inc/macosx/tbox.config.h @@ -145,6 +145,7 @@ #define TB_CONFIG_POSIX_HAVE_OPEN 1 #if !defined(__arm64__) && !defined(__aarch64__) # define TB_CONFIG_POSIX_HAVE_STAT64 1 +# define TB_CONFIG_POSIX_HAVE_LSTAT64 1 #else /* #undef TB_CONFIG_POSIX_HAVE_STAT64 */ #endif -- cgit v1.3.1 From df6efbec2309e41c67e6ffdc8386a600ca04c21d Mon Sep 17 00:00:00 2001 From: ruki Date: Wed, 31 Aug 2022 21:01:15 +0800 Subject: fix file info --- core/src/tbox/tbox | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'core/src') diff --git a/core/src/tbox/tbox b/core/src/tbox/tbox index c759c36f8..4ab2cdf8d 160000 --- a/core/src/tbox/tbox +++ b/core/src/tbox/tbox @@ -1 +1 @@ -Subproject commit c759c36f80ce61be8e1f5e284951cd1aeacdb8a1 +Subproject commit 4ab2cdf8dc94402d2277fd71ddc11eae913a30dc -- cgit v1.3.1 From 44d9b7cd8ef84a84bd8d898dddc419c385e02daf Mon Sep 17 00:00:00 2001 From: ruki Date: Wed, 31 Aug 2022 22:39:10 +0800 Subject: improve os.cpfile --- core/src/tbox/tbox | 2 +- core/src/xmake/os/cpfile.c | 8 +++++++- xmake/core/base/os.lua | 19 +++++++++---------- 3 files changed, 17 insertions(+), 12 deletions(-) (limited to 'core/src') diff --git a/core/src/tbox/tbox b/core/src/tbox/tbox index 4ab2cdf8d..6e4eab7e0 160000 --- a/core/src/tbox/tbox +++ b/core/src/tbox/tbox @@ -1 +1 @@ -Subproject commit 4ab2cdf8dc94402d2277fd71ddc11eae913a30dc +Subproject commit 6e4eab7e07a2b535af6889de3f62cfec0384e99b diff --git a/core/src/xmake/os/cpfile.c b/core/src/xmake/os/cpfile.c index 4490172da..153f51de0 100644 --- a/core/src/xmake/os/cpfile.c +++ b/core/src/xmake/os/cpfile.c @@ -43,7 +43,13 @@ tb_int_t xm_os_cpfile(lua_State* lua) tb_char_t const* dst = luaL_checkstring(lua, 2); tb_check_return_val(src && dst, 0); + // init copy flags + tb_size_t flags = TB_FILE_COPY_NONE; + tb_bool_t is_symlink = lua_toboolean(lua, 3); + if (is_symlink) + flags |= TB_FILE_COPY_LINK; + // do copy - lua_pushboolean(lua, tb_file_copy(src, dst)); + lua_pushboolean(lua, tb_file_copy(src, dst, flags)); return 1; } diff --git a/xmake/core/base/os.lua b/xmake/core/base/os.lua index 271e5546d..ad33699f4 100644 --- a/xmake/core/base/os.lua +++ b/xmake/core/base/os.lua @@ -79,16 +79,15 @@ function os._cp(src, dst, rootdir, opt) end end - -- link file if reserve symlink - if opt and opt.symlink and os.islink(src) then - local reallink = os.readlink(src) - if not os.link(reallink, dst) then - return false, string.format("cannot link %s(%s) to %s, %s", src, reallink, dst, os.strerror()) - end - else - -- copy file - if not os.cpfile(src, dst) then - return false, string.format("cannot copy file %s to %s, %s", src, dst, os.strerror()) + -- copy or link file + local symlink = opt and opt.symlink + if not os.cpfile(src, dst, symlink) then + local errors = os.strerror() + if symlink and os.islink(src) then + local reallink = os.readlink(src) + return false, string.format("cannot link %s(%s) to %s, %s", src, reallink, dst, errors) + else + return false, string.format("cannot copy file %s to %s, %s", src, dst, errors) end end -- is directory? -- cgit v1.3.1 From 23f93ac88e0484178a37c01b6e33298c95e3b64c Mon Sep 17 00:00:00 2001 From: ruki Date: Wed, 31 Aug 2022 22:44:00 +0800 Subject: update tbox --- core/src/tbox/tbox | 2 +- xmake/core/base/os.lua | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'core/src') diff --git a/core/src/tbox/tbox b/core/src/tbox/tbox index 6e4eab7e0..f336b0d24 160000 --- a/core/src/tbox/tbox +++ b/core/src/tbox/tbox @@ -1 +1 @@ -Subproject commit 6e4eab7e07a2b535af6889de3f62cfec0384e99b +Subproject commit f336b0d24f667825e8e3f439180ab5dcb0bab0d9 diff --git a/xmake/core/base/os.lua b/xmake/core/base/os.lua index ad33699f4..b67a497d1 100644 --- a/xmake/core/base/os.lua +++ b/xmake/core/base/os.lua @@ -67,8 +67,9 @@ function os._cp(src, dst, rootdir, opt) end end - -- is file? - if os.isfile(src) or os.islink(src) then + -- is file or link? + local symlink = opt and opt.symlink + if os.isfile(src) or (symlink and os.islink(src)) then -- the destination is directory? append the filename if os.isdir(dst) or path.islastsep(dst) then @@ -80,7 +81,6 @@ function os._cp(src, dst, rootdir, opt) end -- copy or link file - local symlink = opt and opt.symlink if not os.cpfile(src, dst, symlink) then local errors = os.strerror() if symlink and os.islink(src) then @@ -103,7 +103,7 @@ function os._cp(src, dst, rootdir, opt) end -- copy directory - if not os.cpdir(src, dst) then + if not os.cpdir(src, dst, symlink) then return false, string.format("cannot copy directory %s to %s, %s", src, dst, os.strerror()) end -- cgit v1.3.1 From 8294b15c930de7df43333dc1e93b019df93a73f8 Mon Sep 17 00:00:00 2001 From: ruki Date: Wed, 31 Aug 2022 22:44:25 +0800 Subject: improve os.cp --- core/src/xmake/os/cpdir.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'core/src') diff --git a/core/src/xmake/os/cpdir.c b/core/src/xmake/os/cpdir.c index 1967cba49..eaf59f445 100644 --- a/core/src/xmake/os/cpdir.c +++ b/core/src/xmake/os/cpdir.c @@ -43,9 +43,13 @@ tb_int_t xm_os_cpdir(lua_State* lua) tb_char_t const* dst = luaL_checkstring(lua, 2); tb_check_return_val(src && dst, 0); - // done os.cpdir(src, dst) - lua_pushboolean(lua, tb_directory_copy(src, dst)); + // init copy flags + tb_size_t flags = TB_FILE_COPY_NONE; + tb_bool_t is_symlink = lua_toboolean(lua, 3); + if (is_symlink) + flags |= TB_FILE_COPY_LINK; - // ok + // do copy + lua_pushboolean(lua, tb_directory_copy(src, dst, flags)); return 1; } -- cgit v1.3.1 From 6046e78b4d3ba893ef99f3e821736830dca1e5c2 Mon Sep 17 00:00:00 2001 From: ruki Date: Wed, 31 Aug 2022 22:48:20 +0800 Subject: fix os.cp --- core/src/tbox/tbox | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'core/src') diff --git a/core/src/tbox/tbox b/core/src/tbox/tbox index f336b0d24..dc99c25f3 160000 --- a/core/src/tbox/tbox +++ b/core/src/tbox/tbox @@ -1 +1 @@ -Subproject commit f336b0d24f667825e8e3f439180ab5dcb0bab0d9 +Subproject commit dc99c25f3c6fecafe1cf6791148f5656c007299f -- cgit v1.3.1